]> git.sesse.net Git - stockfish/blobdiff - src/thread.h
Retire spinlocks
[stockfish] / src / thread.h
index b4aad5cb7f42321c8954ee641452c5908f9d3cb5..231443dbba0d9f9c521b085ec2837c20587b2973 100644 (file)
@@ -41,22 +41,6 @@ const size_t MAX_SPLITPOINTS_PER_THREAD = 8;
 const size_t MAX_SLAVES_PER_SPLITPOINT = 4;
 
 
-/// Spinlock class wraps low level atomic operations to provide a spin lock
-
-class Spinlock {
-
-  std::atomic_int lock;
-
-public:
-  Spinlock() { lock = 1; } // Init here to workaround a bug with MSVC 2013
-  void acquire() {
-    while (lock.fetch_sub(1, std::memory_order_acquire) != 1)
-        while (lock.load(std::memory_order_relaxed) <= 0) {}
-  }
-  void release() { lock.store(1, std::memory_order_release); }
-};
-
-
 /// SplitPoint struct stores information shared by the threads searching in
 /// parallel below the same split point. It is populated at splitting time.
 
@@ -76,7 +60,7 @@ struct SplitPoint {
   SplitPoint* parentSplitPoint;
 
   // Shared variable data
-  Spinlock spinlock;
+  Mutex mutex;
   std::bitset<MAX_THREADS> slavesMask;
   volatile bool allSlavesSearching;
   volatile uint64_t nodes;
@@ -167,7 +151,7 @@ struct ThreadPool : public std::vector<Thread*> {
   void start_thinking(const Position&, const Search::LimitsType&, Search::StateStackPtr&);
 
   Depth minimumSplitDepth;
-  Spinlock spinlock;
+  Mutex mutex;
   ConditionVariable sleepCondition;
   TimerThread* timer;
 };