]> git.sesse.net Git - stockfish/commitdiff
Clarify slavesMask usage
authorMarco Costalba <mcostalba@gmail.com>
Sat, 26 Jan 2013 13:23:37 +0000 (14:23 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 26 Jan 2013 13:38:51 +0000 (14:38 +0100)
When a thread is allocated a bit is set in slavesMask.
This bit corresponds to the thread's index field that,
because it happens to be the position in the threads
array, eventually it is equal to the loop index 'i'.

But instead of relying on this 'coincidence', explicitly
use the 'idx' field so to clarify slavesMask usage.

Backported from c++11 branch.

No functional change.

src/thread.cpp
src/thread.h

index 9aa0b55ef0deaafac39f430bbab900a754ba855f..14c778f8699fb2456fe4e7ec064e7c0db283b5ac 100644 (file)
@@ -296,7 +296,7 @@ Value ThreadPool::split(Position& pos, Stack* ss, Value alpha, Value beta,
   for (size_t i = 0; i < threads.size() && !Fake; ++i)
       if (threads[i]->is_available_to(master) && ++slavesCnt <= maxThreadsPerSplitPoint)
       {
-          sp.slavesMask |= 1ULL << i;
+          sp.slavesMask |= 1ULL << threads[i]->idx;
           threads[i]->activeSplitPoint = &sp;
           threads[i]->searching = true; // Slave leaves idle_loop()
           threads[i]->notify_one(); // Could be sleeping
@@ -352,8 +352,8 @@ void ThreadPool::wait_for_think_finished() {
 }
 
 
-// start_thinking() wakes up the main thread sleeping in  main_loop() so to start
-// a new search, then returns immediately.
+// start_thinking() wakes up the main thread sleeping in MainThread::idle_loop()
+// so to start a new search, then returns immediately.
 
 void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
                                 const std::vector<Move>& searchMoves, StateStackPtr& states) {
index 7df9f241e4a64d55d7e3499ca7ad5bb7d1114948..ad17e8b270c788aa79863997db77ea65c4b432aa 100644 (file)
@@ -153,7 +153,7 @@ public:
   bool slave_available(Thread* master) const;
   void wait_for_think_finished();
   void start_thinking(const Position&, const Search::LimitsType&,
-                       const std::vector<Move>&, Search::StateStackPtr&);
+                      const std::vector<Move>&, Search::StateStackPtr&);
 
   template <bool Fake>
   Value split(Position& pos, Search::Stack* ss, Value alpha, Value beta, Value bestValue, Move* bestMove,