[Bf-blender-cvs] [746aec51a79] master: Cycles: Use TBB's spin mutex

Sergey Sharybin noreply at git.blender.org
Fri Jul 3 11:15:04 CEST 2020


Commit: 746aec51a7978876035fa58c150ac76bc4b305b7
Author: Sergey Sharybin
Date:   Thu Jul 2 17:05:34 2020 +0200
Branches: master
https://developer.blender.org/rB746aec51a7978876035fa58c150ac76bc4b305b7

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

===================================================================

M	intern/cycles/util/util_thread.h

===================================================================

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:



More information about the Bf-blender-cvs mailing list