- // We have returned from the idle loop, which means that all threads are
- // finished. Note that setting 'searching' and decreasing splitPointsSize is
- // done under lock protection to avoid a race with Thread::is_available_to().
- Threads.mutex.lock();
- sp.mutex.lock();
-
- searching = true;
- splitPointsSize--;
- activeSplitPoint = sp.parentSplitPoint;
- pos.set_nodes_searched(pos.nodes_searched() + sp.nodes);
- *bestMove = sp.bestMove;
- *bestValue = sp.bestValue;
-
- sp.mutex.unlock();
- Threads.mutex.unlock();
-}
-
-// Explicit template instantiations
-template void Thread::split<false>(Position&, Stack*, Value, Value, Value*, Move*, Depth, Move, int, MovePicker*, int);
-template void Thread::split< true>(Position&, Stack*, Value, Value, Value*, Move*, Depth, Move, int, MovePicker*, int);
-
-
-// wait_for_think_finished() waits for main thread to go to sleep then returns
-
-void ThreadPool::wait_for_think_finished() {
-
- MainThread* t = main_thread();
- t->mutex.lock();
- while (t->thinking) sleepCondition.wait(t->mutex);
- t->mutex.unlock();
-}
-
-
-// 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) {
- wait_for_think_finished();
-
- SearchTime = Time::now(); // As early as possible
-
- Signals.stopOnPonderhit = Signals.firstRootMove = false;
- Signals.stop = Signals.failedLowAtRoot = false;
-
- RootPos = pos;
- Limits = limits;
- SetupStates = states; // Ownership transfer here
- RootMoves.clear();
-
- for (MoveList<LEGAL> ml(pos); !ml.end(); ++ml)
- if ( searchMoves.empty()
- || std::count(searchMoves.begin(), searchMoves.end(), ml.move()))
- RootMoves.push_back(RootMove(ml.move()));