]> git.sesse.net Git - stockfish/blobdiff - src/thread_win32.h
LMR Simplification
[stockfish] / src / thread_win32.h
index a3abd65cbfb7863913fa0ab1b11c569d00d1d6b1..47516c62719d6de6bf2d89f0666f21ccd0bc6dd6 100644 (file)
@@ -2,6 +2,7 @@
   Stockfish, a UCI chess playing engine derived from Glaurung 2.1
   Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
   Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
   Stockfish, a UCI chess playing engine derived from Glaurung 2.1
   Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
   Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
+  Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
 
   Stockfish is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
 
   Stockfish is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
 /// relies on libwinpthread. Currently libwinpthread implements mutexes directly
 /// on top of Windows semaphores. Semaphores, being kernel objects, require kernel
 /// mode transition in order to lock or unlock, which is very slow compared to
 /// relies on libwinpthread. Currently libwinpthread implements mutexes directly
 /// on top of Windows semaphores. Semaphores, being kernel objects, require kernel
 /// mode transition in order to lock or unlock, which is very slow compared to
-/// interlocked operations (about 30% slower on bench test). To workaround this
+/// interlocked operations (about 30% slower on bench test). To work around this
 /// issue, we define our wrappers to the low level Win32 calls. We use critical
 /// sections to support Windows XP and older versions. Unfortunately, cond_wait()
 /// is racy between unlock() and WaitForSingleObject() but they have the same
 /// issue, we define our wrappers to the low level Win32 calls. We use critical
 /// sections to support Windows XP and older versions. Unfortunately, cond_wait()
 /// is racy between unlock() and WaitForSingleObject() but they have the same
-/// speed performance of SRW locks.
+/// speed performance as the SRW locks.
 
 #include <condition_variable>
 #include <mutex>
 
 #include <condition_variable>
 #include <mutex>
@@ -57,29 +58,7 @@ private:
   CRITICAL_SECTION cs;
 };
 
   CRITICAL_SECTION cs;
 };
 
-struct ConditionVariable {
-  ConditionVariable() { hn = CreateEvent(0, FALSE, FALSE, 0); }
- ~ConditionVariable() { CloseHandle(hn); }
-  void notify_one() { SetEvent(hn); }
-
-  void wait(std::unique_lock<Mutex>& lk) {
-    lk.unlock();
-    WaitForSingleObject(hn, INFINITE);
-    lk.lock();
-  }
-
-  void wait_for(std::unique_lock<Mutex>& lk, const std::chrono::milliseconds& ms) {
-    lk.unlock();
-    WaitForSingleObject(hn, ms.count());
-    lk.lock();
-  }
-
-  template<class Predicate>
-  void wait(std::unique_lock<Mutex>& lk, Predicate p) { while (!p()) this->wait(lk); }
-
-private:
-  HANDLE hn;
-};
+typedef std::condition_variable_any ConditionVariable;
 
 #else // Default case: use STL classes
 
 
 #else // Default case: use STL classes