diff options
| author | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2016-09-21 11:29:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-21 11:29:48 -0700 |
| commit | d5d2ca8058a0f1c00ab7ca9fe2c058ba47546c0a (patch) | |
| tree | 8a22ca73ff838f3f0090b29a548ae81087fc90ed /src/common/thread.h | |
| parent | 2a910a6d883f2227edc74aacf5b93a58a3dea07c (diff) | |
| parent | 0e3f0120a8ec2996e73bb6b7b6c9d7531f7a7eb1 (diff) | |
Merge pull request #2086 from linkmauve/clang-format
Add clang-format as part of our {commit,travis}-time checks
Diffstat (limited to 'src/common/thread.h')
| -rw-r--r-- | src/common/thread.h | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/common/thread.h b/src/common/thread.h index bbfa8befa..9c08be7e3 100644 --- a/src/common/thread.h +++ b/src/common/thread.h @@ -4,11 +4,10 @@ #pragma once -#include <cstddef> -#include <thread> #include <condition_variable> +#include <cstddef> #include <mutex> - +#include <thread> #include "common/common_types.h" // Support for C++11's thread_local keyword was surprisingly spotty in compilers until very @@ -17,17 +16,17 @@ // backwards compat support. // WARNING: This only works correctly with POD types. #if defined(__clang__) -# if !__has_feature(cxx_thread_local) -# define thread_local __thread -# endif +#if !__has_feature(cxx_thread_local) +#define thread_local __thread +#endif #elif defined(__GNUC__) -# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8) -# define thread_local __thread -# endif +#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8) +#define thread_local __thread +#endif #elif defined(_MSC_VER) -# if _MSC_VER < 1900 -# define thread_local __declspec(thread) -# endif +#if _MSC_VER < 1900 +#define thread_local __declspec(thread) +#endif #endif namespace Common { @@ -51,13 +50,14 @@ public: void Wait() { std::unique_lock<std::mutex> lk(mutex); - condvar.wait(lk, [&]{ return is_set; }); + condvar.wait(lk, [&] { return is_set; }); is_set = false; } void Reset() { std::unique_lock<std::mutex> lk(mutex); - // no other action required, since wait loops on the predicate and any lingering signal will get cleared on the first iteration + // no other action required, since wait loops on the predicate and any lingering signal will + // get cleared on the first iteration is_set = false; } @@ -81,7 +81,8 @@ public: waiting = 0; condvar.notify_all(); } else { - condvar.wait(lk, [this, current_generation]{ return current_generation != generation; }); + condvar.wait(lk, + [this, current_generation] { return current_generation != generation; }); } } @@ -94,7 +95,7 @@ private: }; void SleepCurrentThread(int ms); -void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms +void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms // Use this function during a spin-wait to make the current thread // relax while another thread is working. This may be more efficient @@ -103,6 +104,6 @@ inline void YieldCPU() { std::this_thread::yield(); } -void SetCurrentThreadName(const char *name); +void SetCurrentThreadName(const char* name); } // namespace Common |
