]> git.sesse.net Git - stockfish/commitdiff
Simplify idle_loop() signature
authorMarco Costalba <mcostalba@gmail.com>
Sun, 19 Aug 2012 10:20:33 +0000 (11:20 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 19 Aug 2012 22:01:28 +0000 (23:01 +0100)
We can detect the split point master also from within idle_loop,
so we can call the function without parameters and remove an
overloaded member hack in Thread class.

Note that we don't need to take a lock around curSplitPoint
when entering idle_loop() because if we are the master then
curSplitPoint cannot change under our feet (because is_searching
is set and so we cannot be reallocated), if we are a slave
we enter idle_loop() only upon Thread creation and in that case
is always splitPointsCnt == 0. This is true even in the very rare
case that curSplitPoint != NULL, if we have been already allocated
even before entering idle_loop().

No functional change.

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

index a3ad7be13147b4cce2fb8e6d9cea2f2cd1c24045..043ada63d6fdd22306d5add2709b325fa768902d 100644 (file)
@@ -1643,11 +1643,15 @@ void RootMove::insert_pv_in_tt(Position& pos) {
 }
 
 
 }
 
 
-/// Thread::idle_loop() is where the thread is parked when it has no work to do.
-/// The parameter 'master_sp', if non-NULL, is a pointer to an active SplitPoint
-/// object for which the thread is the master.
+/// Thread::idle_loop() is where the thread is parked when it has no work to do
 
 
-void Thread::idle_loop(SplitPoint* sp_master) {
+void Thread::idle_loop() {
+
+  // Pointer 'sp_master', if non-NULL, points to the active SplitPoint
+  // object for which the thread is the master.
+  const SplitPoint* sp_master = splitPointsCnt ? curSplitPoint : NULL;
+
+  assert(!sp_master || (sp_master->master == this && is_searching));
 
   // 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 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.
index 0a8bacf7d09acebf34d40145697338b8fb970a10..4447efeecab4d911a1f0a7395c1d35d2df06c504 100644 (file)
@@ -365,12 +365,11 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta,
 
   // Everything is set up. The master thread enters the idle loop, from which
   // it will instantly launch a search, because its is_searching flag is set.
 
   // Everything is set up. The master thread enters the idle loop, from which
   // it will instantly launch a search, because its is_searching flag is set.
-  // We pass the split point as a parameter to the idle loop, which means that
-  // the thread will return from the idle loop when all slaves have finished
+  // The thread will return from the idle loop when all slaves have finished
   // their work at this split point.
   if (slavesCnt || Fake)
   {
   // their work at this split point.
   if (slavesCnt || Fake)
   {
-      master->idle_loop(sp);
+      master->idle_loop();
 
       // In helpful master concept a master can help only a sub-tree of its split
       // point, and because here is all finished is not possible master is booked.
 
       // In helpful master concept a master can help only a sub-tree of its split
       // point, and because here is all finished is not possible master is booked.
index d1328daad91b9818859660e6adc18f0f83652b07..96ad121efeec2632ef85cf033b22497f3cadc832 100644 (file)
@@ -76,8 +76,7 @@ public:
   void wake_up();
   bool cutoff_occurred() const;
   bool is_available_to(Thread* master) const;
   void wake_up();
   bool cutoff_occurred() const;
   bool is_available_to(Thread* master) const;
-  void idle_loop(SplitPoint* sp_master);
-  void idle_loop() { idle_loop(NULL); } // Hack to allow storing in start_fn
+  void idle_loop();
   void main_loop();
   void timer_loop();
   void wait_for_stop_or_ponderhit();
   void main_loop();
   void timer_loop();
   void wait_for_stop_or_ponderhit();