From 43204d9ac210a3a68b7b9785f3089d38412c1375 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 6 Nov 2011 13:37:18 +0100 Subject: [PATCH] Reformat all_slaves_finished() Rename and move under ThreadsManager class. No functional change. Signed-off-by: Marco Costalba --- src/search.cpp | 18 +++--------------- src/thread.cpp | 13 +++++++++++++ src/thread.h | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 8257b5bb..40e548dc 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -2071,20 +2071,8 @@ split_point_start: // At split points actual search starts from here do pos.undo_move(pv[--ply]); while (ply); } -} // namespace - - -// Little helper used by idle_loop() to check that all the slave threads of a -// split point have finished searching. - -static bool all_slaves_finished(SplitPoint* sp) { - for (int i = 0; i < Threads.size(); i++) - if (sp->is_slave[i]) - return false; - - return true; -} +} // namespace // Thread::idle_loop() is where the thread is parked when it has no work to do. @@ -2114,7 +2102,7 @@ void Thread::idle_loop(SplitPoint* sp) { lock_grab(&sleepLock); // If we are master and all slaves have finished don't go to sleep - if (sp && all_slaves_finished(sp)) + if (sp && Threads.split_point_finished(sp)) { lock_release(&sleepLock); break; @@ -2166,7 +2154,7 @@ void Thread::idle_loop(SplitPoint* sp) { // If this thread is the master of a split point and all slaves have // finished their work at this split point, return from the idle loop. - if (sp && all_slaves_finished(sp)) + if (sp && Threads.split_point_finished(sp)) { // Because sp->is_slave[] is reset under lock protection, // be sure sp->lock has been released before to return. diff --git a/src/thread.cpp b/src/thread.cpp index df76dcca..ca9fe14d 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -239,6 +239,19 @@ bool ThreadsManager::available_slave_exists(int master) const { } +// split_point_finished() checks if all the slave threads of a given split +// point have finished searching. + +bool ThreadsManager::split_point_finished(SplitPoint* sp) const { + + for (int i = 0; i < activeThreads; i++) + if (sp->is_slave[i]) + return false; + + return true; +} + + // split() does the actual work of distributing the work at a node between // several available threads. If it does not succeed in splitting the // node (because no idle threads are available, or because we have no unused diff --git a/src/thread.h b/src/thread.h index 46ce03aa..e6d40094 100644 --- a/src/thread.h +++ b/src/thread.h @@ -114,6 +114,7 @@ public: void set_size(int cnt); void read_uci_options(); bool available_slave_exists(int master) const; + bool split_point_finished(SplitPoint* sp) const; void getline(std::string& cmd); void start_listener(); -- 2.39.2