diff options
author | bunnei <bunneidev@gmail.com> | 2018-11-23 17:52:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-23 17:52:05 +0100 |
commit | 24dfb43ac692124a4dd1181d670b68dfd926b0d0 (patch) | |
tree | 90e5f9cc63f3f930c2c6434348e6c80cc6e46021 | |
parent | Added predicate comparison LessEqualWithNan (#1736) (diff) | |
parent | common/thread: Drop Hungarian notation on SetCurrentThreadName's parameter (diff) | |
download | yuzu-24dfb43ac692124a4dd1181d670b68dfd926b0d0.tar yuzu-24dfb43ac692124a4dd1181d670b68dfd926b0d0.tar.gz yuzu-24dfb43ac692124a4dd1181d670b68dfd926b0d0.tar.bz2 yuzu-24dfb43ac692124a4dd1181d670b68dfd926b0d0.tar.lz yuzu-24dfb43ac692124a4dd1181d670b68dfd926b0d0.tar.xz yuzu-24dfb43ac692124a4dd1181d670b68dfd926b0d0.tar.zst yuzu-24dfb43ac692124a4dd1181d670b68dfd926b0d0.zip |
-rw-r--r-- | src/common/thread.cpp | 35 | ||||
-rw-r--r-- | src/common/thread.h | 20 |
2 files changed, 14 insertions, 41 deletions
diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 9e207118f..5144c0d9f 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp @@ -25,23 +25,6 @@ namespace Common { -int CurrentThreadId() { -#ifdef _MSC_VER - return GetCurrentThreadId(); -#elif defined __APPLE__ - return mach_thread_self(); -#else - return 0; -#endif -} - -#ifdef _WIN32 -// Supporting functions -void SleepCurrentThread(int ms) { - Sleep(ms); -} -#endif - #ifdef _MSC_VER void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask) { @@ -62,7 +45,7 @@ void SwitchCurrentThread() { // This is implemented much nicer in upcoming msvc++, see: // http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.100).aspx -void SetCurrentThreadName(const char* szThreadName) { +void SetCurrentThreadName(const char* name) { static const DWORD MS_VC_EXCEPTION = 0x406D1388; #pragma pack(push, 8) @@ -75,7 +58,7 @@ void SetCurrentThreadName(const char* szThreadName) { #pragma pack(pop) info.dwType = 0x1000; - info.szName = szThreadName; + info.szName = name; info.dwThreadID = -1; // dwThreadID; info.dwFlags = 0; @@ -107,10 +90,6 @@ void SetCurrentThreadAffinity(u32 mask) { } #ifndef _WIN32 -void SleepCurrentThread(int ms) { - usleep(1000 * ms); -} - void SwitchCurrentThread() { usleep(1000 * 1); } @@ -118,15 +97,15 @@ void SwitchCurrentThread() { // MinGW with the POSIX threading model does not support pthread_setname_np #if !defined(_WIN32) || defined(_MSC_VER) -void SetCurrentThreadName(const char* szThreadName) { +void SetCurrentThreadName(const char* name) { #ifdef __APPLE__ - pthread_setname_np(szThreadName); + pthread_setname_np(name); #elif defined(__Bitrig__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) - pthread_set_name_np(pthread_self(), szThreadName); + pthread_set_name_np(pthread_self(), name); #elif defined(__NetBSD__) - pthread_setname_np(pthread_self(), "%s", (void*)szThreadName); + pthread_setname_np(pthread_self(), "%s", (void*)name); #else - pthread_setname_np(pthread_self(), szThreadName); + pthread_setname_np(pthread_self(), name); #endif } #endif diff --git a/src/common/thread.h b/src/common/thread.h index 6cbdb96a3..2cf74452d 100644 --- a/src/common/thread.h +++ b/src/common/thread.h @@ -13,15 +13,8 @@ namespace Common { -int CurrentThreadId(); - -void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask); -void SetCurrentThreadAffinity(u32 mask); - class Event { public: - Event() : is_set(false) {} - void Set() { std::lock_guard<std::mutex> lk(mutex); if (!is_set) { @@ -53,14 +46,14 @@ public: } private: - bool is_set; + bool is_set = false; std::condition_variable condvar; std::mutex mutex; }; class Barrier { public: - explicit Barrier(std::size_t count_) : count(count_), waiting(0), generation(0) {} + explicit Barrier(std::size_t count_) : count(count_) {} /// Blocks until all "count" threads have called Sync() void Sync() { @@ -80,12 +73,13 @@ public: private: std::condition_variable condvar; std::mutex mutex; - const std::size_t count; - std::size_t waiting; - std::size_t generation; // Incremented once each time the barrier is used + std::size_t count; + std::size_t waiting = 0; + std::size_t generation = 0; // Incremented once each time the barrier is used }; -void SleepCurrentThread(int ms); +void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask); +void SetCurrentThreadAffinity(u32 mask); void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms void SetCurrentThreadName(const char* name); |