From 79e50a2fbfdf2e866255e002b7d7cdc55d96bb9e Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 20 Apr 2011 11:18:36 +0200 Subject: [PATCH] Move wake_sleeping_thread() to Thread class No functional change. Signed-off-by: Marco Costalba --- src/search.cpp | 20 ++++---------------- src/thread.h | 6 ++++++ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 21db6852..30299ac4 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -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 @@ -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() { diff --git a/src/thread.h b/src/thread.h index f54fcbbe..b476d529 100644 --- a/src/thread.h +++ b/src/thread.h @@ -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) -- 2.39.2