diff options
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 |