- // We have returned from the idle loop, which means that all threads are
- // finished. Note that setting is_searching and decreasing splitPointsCnt is
- // done under lock protection to avoid a race with Thread::is_available_to().
- lock_grab(sp->lock); // To protect sp->nodes
- lock_grab(splitLock);
-
- masterThread.is_searching = true;
- masterThread.splitPointsCnt--;
- masterThread.curSplitPoint = sp->parent;
- pos.set_nodes_searched(pos.nodes_searched() + sp->nodes);
- *bestMove = sp->bestMove;
-
- lock_release(splitLock);
- lock_release(sp->lock);
-
- return sp->bestValue;
-}
-
-// Explicit template instantiations
-template Value ThreadsManager::split<false>(Position&, Stack*, Value, Value, Value, Move*, Depth, Move, int, MovePicker*, int);
-template Value ThreadsManager::split<true>(Position&, Stack*, Value, Value, Value, Move*, Depth, Move, int, MovePicker*, int);
-
-
-// ThreadsManager::set_timer() is used to set the timer to trigger after msec
-// milliseconds. If msec is 0 then timer is stopped.
-
-void ThreadsManager::set_timer(int msec) {
-
- lock_grab(timer->sleepLock);
- timer->maxPly = msec;
- cond_signal(timer->sleepCond); // Wake up and restart the timer
- lock_release(timer->sleepLock);
-}
-
-
-// ThreadsManager::wait_for_search_finished() waits for main thread to go to
-// sleep, this means search is finished. Then returns.
-
-void ThreadsManager::wait_for_search_finished() {
-
- Thread* main = threads[0];
- lock_grab(main->sleepLock);
- while (!main->do_sleep) cond_wait(sleepCond, main->sleepLock);
- lock_release(main->sleepLock);
-}
-
-
-// ThreadsManager::start_searching() wakes up the main thread sleeping in
-// main_loop() so to start a new search, then returns immediately.
-
-void ThreadsManager::start_searching(const Position& pos, const LimitsType& limits,
- const std::set<Move>& searchMoves) {
- wait_for_search_finished();
-
- Signals.stopOnPonderhit = Signals.firstRootMove = false;
- Signals.stop = Signals.failedLowAtRoot = false;
-
- RootPosition.copy(pos, 0);
- Limits = limits;
- RootMoves.clear();
-
- for (MoveList<MV_LEGAL> ml(pos); !ml.end(); ++ml)
- if (searchMoves.empty() || searchMoves.count(ml.move()))
- RootMoves.push_back(RootMove(ml.move()));