X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=53a99f66036f66932ccc6e01b1ade81f81b51ca3;hp=6586144dfabceac40f269567244d192c98702d04;hb=831f91b859c43a5fa895ef0c955516ec8b7a8212;hpb=b84af67f4c88f3e3f7b61bf2035475f79fb3e62e diff --git a/src/search.cpp b/src/search.cpp index 6586144d..53a99f66 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -43,11 +43,10 @@ namespace Search { std::vector RootMoves; Position RootPosition; Time SearchTime; + StateStackPtr SetupStates; } using std::string; -using std::cout; -using std::endl; using Eval::evaluate; using namespace Search; @@ -236,8 +235,8 @@ void Search::think() { if (RootMoves.empty()) { - cout << "info depth 0 score " - << score_to_uci(pos.in_check() ? -VALUE_MATE : VALUE_DRAW) << endl; + sync_cout << "info depth 0 score " + << score_to_uci(pos.in_check() ? -VALUE_MATE : VALUE_DRAW) << sync_endl; RootMoves.push_back(MOVE_NONE); goto finalize; @@ -271,7 +270,7 @@ void Search::think() { << " time: " << Limits.time[pos.side_to_move()] << " increment: " << Limits.inc[pos.side_to_move()] << " moves to go: " << Limits.movestogo - << endl; + << std::endl; } Threads.wake_up(); @@ -300,7 +299,7 @@ void Search::think() { StateInfo st; pos.do_move(RootMoves[0].pv[0], st); - log << "\nPonder move: " << move_to_san(pos, RootMoves[0].pv[1]) << endl; + log << "\nPonder move: " << move_to_san(pos, RootMoves[0].pv[1]) << std::endl; pos.undo_move(RootMoves[0].pv[0]); } @@ -313,8 +312,8 @@ finalize: pos.this_thread()->wait_for_stop_or_ponderhit(); // Best move could be MOVE_NONE when searching on a stalemate position - cout << "bestmove " << move_to_uci(RootMoves[0].pv[0], Chess960) - << " ponder " << move_to_uci(RootMoves[0].pv[1], Chess960) << endl; + sync_cout << "bestmove " << move_to_uci(RootMoves[0].pv[0], Chess960) + << " ponder " << move_to_uci(RootMoves[0].pv[1], Chess960) << sync_endl; } @@ -400,7 +399,7 @@ namespace { // Send full PV info to GUI if we are going to leave the loop or // if we have a fail high/low and we are deep in the search. if ((bestValue > alpha && bestValue < beta) || SearchTime.elapsed() > 2000) - cout << uci_pv(pos, depth, alpha, beta) << endl; + sync_cout << uci_pv(pos, depth, alpha, beta) << sync_endl; // In case of failing high/low increase aspiration window and // research, otherwise exit the fail high/low loop. @@ -433,7 +432,7 @@ namespace { { Log log(Options["Search Log Filename"]); log << pretty_pv(pos, depth, bestValue, SearchTime.elapsed(), &RootMoves[0].pv[0]) - << endl; + << std::endl; } // Filter out startup noise when monitoring best move stability @@ -819,7 +818,7 @@ split_point_start: // At split points actual search starts from here if (SpNode) { moveCount = ++sp->moveCount; - lock_release(sp->lock); + sp->mutex.unlock(); } else moveCount++; @@ -829,9 +828,9 @@ split_point_start: // At split points actual search starts from here Signals.firstRootMove = (moveCount == 1); if (thisThread == Threads.main_thread() && SearchTime.elapsed() > 2000) - cout << "info depth " << depth / ONE_PLY - << " currmove " << move_to_uci(move, Chess960) - << " currmovenumber " << moveCount + PVIdx << endl; + sync_cout << "info depth " << depth / ONE_PLY + << " currmove " << move_to_uci(move, Chess960) + << " currmovenumber " << moveCount + PVIdx << sync_endl; } isPvMove = (PvNode && moveCount <= 1); @@ -885,7 +884,7 @@ split_point_start: // At split points actual search starts from here && (!threatMove || !connected_threat(pos, move, threatMove))) { if (SpNode) - lock_grab(sp->lock); + sp->mutex.lock(); continue; } @@ -900,7 +899,7 @@ split_point_start: // At split points actual search starts from here if (futilityValue < beta) { if (SpNode) - lock_grab(sp->lock); + sp->mutex.lock(); continue; } @@ -910,7 +909,7 @@ split_point_start: // At split points actual search starts from here && pos.see_sign(move) < 0) { if (SpNode) - lock_grab(sp->lock); + sp->mutex.lock(); continue; } @@ -974,7 +973,7 @@ split_point_start: // At split points actual search starts from here // Step 18. Check for new best move if (SpNode) { - lock_grab(sp->lock); + sp->mutex.lock(); bestValue = sp->bestValue; alpha = sp->alpha; } @@ -1670,12 +1669,12 @@ void Thread::idle_loop() { } // Grab the lock to avoid races with Thread::wake_up() - lock_grab(sleepLock); + mutex.lock(); // If we are master and all slaves have finished don't go to sleep if (sp_master && !sp_master->slavesMask) { - lock_release(sleepLock); + mutex.unlock(); break; } @@ -1684,9 +1683,9 @@ void Thread::idle_loop() { // in the meanwhile, allocated us and sent the wake_up() call before we // had the chance to grab the lock. if (do_sleep || !is_searching) - cond_wait(sleepCond, sleepLock); + sleepCondition.wait(mutex); - lock_release(sleepLock); + mutex.unlock(); } // If this thread has been assigned work, launch a search @@ -1694,12 +1693,12 @@ void Thread::idle_loop() { { assert(!do_sleep && !do_exit); - lock_grab(Threads.splitLock); + Threads.mutex.lock(); assert(is_searching); SplitPoint* sp = curSplitPoint; - lock_release(Threads.splitLock); + Threads.mutex.unlock(); Stack ss[MAX_PLY_PLUS_2]; Position pos(*sp->pos, this); @@ -1707,7 +1706,7 @@ void Thread::idle_loop() { memcpy(ss, sp->ss - 1, 4 * sizeof(Stack)); (ss+1)->sp = sp; - lock_grab(sp->lock); + sp->mutex.lock(); if (sp->nodeType == Root) search(pos, ss+1, sp->alpha, sp->beta, sp->depth); @@ -1738,7 +1737,7 @@ void Thread::idle_loop() { // related data in a safe way becuase it could have been released under // our feet by the sp master. Also accessing other Thread objects is // unsafe because if we are exiting there is a chance are already freed. - lock_release(sp->lock); + sp->mutex.unlock(); } } } @@ -1754,7 +1753,7 @@ void check_time() { if (lastInfoTime.elapsed() >= 1000) { - lastInfoTime.restart(); + lastInfoTime = Time::current_time(); dbg_print(); }