diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-07-02 18:05:34 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-07-03 12:14:26 +0300 |
commit | 746aec51a7978876035fa58c150ac76bc4b305b7 (patch) | |
tree | b45f7da58df742db9d7b59f66f5c1e8efb995da0 /intern/cycles | |
parent | 0e1ee29f777dbcd7f74a4d99690f8d29022b8091 (diff) |
Cycles: Use TBB's spin mutex
First benefit is reduced boilerplate code.
Second benefit is fixed warnings about using deprecated spin lock
on macOS when using SDK 10.12 and above.
Differential Revision: https://developer.blender.org/D8182
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/util/util_thread.h | 77 |
1 files changed, 4 insertions, 73 deletions
diff --git a/intern/cycles/util/util_thread.h b/intern/cycles/util/util_thread.h index f6dbc9186b8..29f9becbefe 100644 --- a/intern/cycles/util/util_thread.h +++ b/intern/cycles/util/util_thread.h @@ -29,9 +29,9 @@ # include <pthread.h> #endif -#ifdef __APPLE__ -# include <libkern/OSAtomic.h> -#endif +/* NOTE: Use tbb/spin_mutex.h instead of util_tbb.h because some of the TBB + * functionality requires RTTI, which is disabled for OSL kernel. */ +#include <tbb/spin_mutex.h> #include "util/util_function.h" @@ -65,76 +65,7 @@ class thread { int node_; }; -/* Own wrapper around pthread's spin lock to make it's use easier. */ - -class thread_spin_lock { - public: -#ifdef __APPLE__ - inline thread_spin_lock() - { - spin_ = OS_SPINLOCK_INIT; - } - - inline void lock() - { - OSSpinLockLock(&spin_); - } - - inline void unlock() - { - OSSpinLockUnlock(&spin_); - } -#elif defined(_WIN32) - inline thread_spin_lock() - { - const DWORD SPIN_COUNT = 50000; - InitializeCriticalSectionAndSpinCount(&cs_, SPIN_COUNT); - } - - inline ~thread_spin_lock() - { - DeleteCriticalSection(&cs_); - } - - inline void lock() - { - EnterCriticalSection(&cs_); - } - - inline void unlock() - { - LeaveCriticalSection(&cs_); - } -#else - inline thread_spin_lock() - { - pthread_spin_init(&spin_, 0); - } - - inline ~thread_spin_lock() - { - pthread_spin_destroy(&spin_); - } - - inline void lock() - { - pthread_spin_lock(&spin_); - } - - inline void unlock() - { - pthread_spin_unlock(&spin_); - } -#endif - protected: -#ifdef __APPLE__ - OSSpinLock spin_; -#elif defined(_WIN32) - CRITICAL_SECTION cs_; -#else - pthread_spinlock_t spin_; -#endif -}; +using thread_spin_lock = tbb::spin_mutex; class thread_scoped_spin_lock { public: |