]> git.sesse.net Git - stockfish/commitdiff
Move wake_sleeping_thread() to Thread class
authorMarco Costalba <mcostalba@gmail.com>
Wed, 20 Apr 2011 09:18:36 +0000 (11:18 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 20 Apr 2011 11:05:07 +0000 (12:05 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/search.cpp
src/thread.h

index 21db685285972f12c571078dec42751d76201228..30299ac435e68c1305f8708914cc79cbd86c9dd7 100644 (file)
@@ -76,7 +76,6 @@ namespace {
     bool available_thread_exists(int master) const;
     bool thread_is_available(int slave, int master) const;
     bool cutoff_at_splitpoint(int threadID) const;
-    void wake_sleeping_thread(int threadID);
     void idle_loop(int threadID, SplitPoint* sp);
 
     template <bool Fake>
@@ -509,7 +508,7 @@ bool think(Position& pos, bool infinite, bool ponder, int time[], int increment[
   // Wake up needed threads and reset maxPly counter
   for (int i = 0; i < ThreadsMgr.active_threads(); i++)
   {
-      ThreadsMgr.wake_sleeping_thread(i);
+      ThreadsMgr[i].wake_up();
       ThreadsMgr[i].maxPly = 0;
   }
 
@@ -2107,7 +2106,7 @@ split_point_start: // At split points actual search starts from here
             // Wake up master thread so to allow it to return from the idle loop in
             // case we are the last slave of the split point.
             if (useSleepingThreads && threadID != tsp->master && threads[tsp->master].state == THREAD_AVAILABLE)
-                wake_sleeping_thread(tsp->master);
+                threads[tsp->master].wake_up();
         }
 
         // If this thread is the master of a split point and all slaves have
@@ -2201,7 +2200,7 @@ split_point_start: // At split points actual search starts from here
     // Wake up all the threads and waits for termination
     for (int i = 1; i < MAX_THREADS; i++)
     {
-        wake_sleeping_thread(i);
+        threads[i].wake_up();
         while (threads[i].state != THREAD_TERMINATED) {}
     }
 
@@ -2376,7 +2375,7 @@ split_point_start: // At split points actual search starts from here
             threads[i].state = THREAD_WORKISWAITING; // This makes the slave to exit from idle_loop()
 
             if (useSleepingThreads && i != master)
-                wake_sleeping_thread(i);
+                threads[i].wake_up();
         }
 
     // Everything is set up. The master thread enters the idle loop, from
@@ -2400,17 +2399,6 @@ split_point_start: // At split points actual search starts from here
   }
 
 
-  // wake_sleeping_thread() wakes up the thread with the given threadID
-  // when it is time to start a new search.
-
-  void ThreadsManager::wake_sleeping_thread(int threadID) {
-
-     lock_grab(&threads[threadID].sleepLock);
-     cond_signal(&threads[threadID].sleepCond);
-     lock_release(&threads[threadID].sleepLock);
-  }
-
-
   /// RootMove and RootMoveList method's definitions
 
   RootMove::RootMove() {
index f54fcbbe71b62691d62de3f9480980db6aa71558..b476d529f4d3a1455e662958a8190a6094178870 100644 (file)
@@ -75,6 +75,12 @@ struct Thread {
   SplitPoint* volatile splitPoint;
   volatile int activeSplitPoints;
   SplitPoint splitPoints[MAX_ACTIVE_SPLIT_POINTS];
+
+  void wake_up() {
+    lock_grab(&sleepLock);
+    cond_signal(&sleepCond);
+    lock_release(&sleepLock);
+  }
 };
 
 #endif // !defined(THREAD_H_INCLUDED)