]> git.sesse.net Git - stockfish/commitdiff
Change slave_available() API
authorMarco Costalba <mcostalba@gmail.com>
Wed, 6 Feb 2013 08:36:13 +0000 (09:36 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 6 Feb 2013 19:48:26 +0000 (20:48 +0100)
To return a pointer to the available
thread instead of a bool. This allows
to simplify the core loop in split().

No functional change.

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

index ec457609fedb9b2997c7f88c8a420c20941e88c9..60b7c8062a2ba118f4c33b8e369eb468dc5364a5 100644 (file)
@@ -1025,7 +1025,7 @@ split_point_start: // At split points actual search starts from here
       // Step 19. Check for splitting the search
       if (   !SpNode
           &&  depth >= Threads.minimumSplitDepth
-          &&  Threads.slave_available(thisThread)
+          &&  Threads.available_slave(thisThread)
           &&  thisThread->splitPointsSize < MAX_SPLITPOINTS_PER_THREAD)
       {
           assert(bestValue < beta);
index b04b8adbb1719e586e818e366b2077fdc01053ab..3b59a05df3e0711c7a2943c4d66ca254ca3e29f3 100644 (file)
@@ -229,13 +229,13 @@ void ThreadPool::read_uci_options() {
 // slave_available() tries to find an idle thread which is available as a slave
 // for the thread 'master'.
 
-bool ThreadPool::slave_available(Thread* master) const {
+Thread* ThreadPool::available_slave(Thread* master) const {
 
   for (const_iterator it = begin(); it != end(); ++it)
       if ((*it)->is_available_to(master))
-          return true;
+          return *it;
 
-  return false;
+  return NULL;
 }
 
 
@@ -290,18 +290,15 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes
   activeSplitPoint = &sp;
 
   size_t slavesCnt = 1; // This thread is always included
+  Thread* slave;
 
-  for (ThreadPool::iterator it = Threads.begin(); it != Threads.end() && !Fake; ++it)
+  while (    (slave = Threads.available_slave(this)) != NULL
+         && ++slavesCnt <= Threads.maxThreadsPerSplitPoint && !Fake)
   {
-      Thread* slave = *it;
-
-      if (slave->is_available_to(this) && ++slavesCnt <= Threads.maxThreadsPerSplitPoint)
-      {
-          sp.slavesMask |= 1ULL << slave->idx;
-          slave->activeSplitPoint = &sp;
-          slave->searching = true; // Slave leaves idle_loop()
-          slave->notify_one(); // Could be sleeping
-      }
+      sp.slavesMask |= 1ULL << slave->idx;
+      slave->activeSplitPoint = &sp;
+      slave->searching = true; // Slave leaves idle_loop()
+      slave->notify_one(); // Could be sleeping
   }
 
   sp.mutex.unlock();
index b18170dfcccfa9b29b1bf4f011747142e48e3166..c760c20d509b5a9fcd69a475aed91ade0d500f64 100644 (file)
@@ -149,7 +149,7 @@ struct ThreadPool : public std::vector<Thread*> {
 
   MainThread* main_thread() { return static_cast<MainThread*>((*this)[0]); }
   void read_uci_options();
-  bool slave_available(Thread* master) const;
+  Thread* available_slave(Thread* master) const;
   void wait_for_think_finished();
   void start_thinking(const Position&, const Search::LimitsType&,
                       const std::vector<Move>&, Search::StateStackPtr&);