LimitsType Limits;
std::vector<RootMove> RootMoves;
Position RootPosition;
- Time SearchTime;
+ Time::point SearchTime;
+ StateStackPtr SetupStates;
}
using std::string;
-using std::cout;
-using std::endl;
using Eval::evaluate;
using namespace Search;
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;
<< " 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();
if (Options["Use Search Log"])
{
- int e = SearchTime.elapsed();
+ int e = Time::now() - SearchTime;
Log log(Options["Search Log Filename"]);
log << "Nodes: " << pos.nodes_searched()
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]);
}
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;
}
// 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;
+ if ((bestValue > alpha && bestValue < beta) || Time::now() - SearchTime > 2000)
+ 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.
if (!Signals.stop && Options["Use Search Log"])
{
Log log(Options["Search Log Filename"]);
- log << pretty_pv(pos, depth, bestValue, SearchTime.elapsed(), &RootMoves[0].pv[0])
- << endl;
+ log << pretty_pv(pos, depth, bestValue, Time::now() - SearchTime, &RootMoves[0].pv[0])
+ << std::endl;
}
// Filter out startup noise when monitoring best move stability
// Stop search if most of available time is already consumed. We
// probably don't have enough time to search the first move at the
// next iteration anyway.
- if (SearchTime.elapsed() > (TimeMgr.available_time() * 62) / 100)
+ if (Time::now() - SearchTime > (TimeMgr.available_time() * 62) / 100)
stop = true;
// Stop search early if one move seems to be much better than others
if ( depth >= 12
&& !stop
&& ( (bestMoveNeverChanged && pos.captured_piece_type())
- || SearchTime.elapsed() > (TimeMgr.available_time() * 40) / 100))
+ || Time::now() - SearchTime > (TimeMgr.available_time() * 40) / 100))
{
Value rBeta = bestValue - EasyMoveMargin;
(ss+1)->excludedMove = RootMoves[0].pv[0];
if (SpNode)
{
moveCount = ++sp->moveCount;
- lock_release(sp->lock);
+ sp->mutex.unlock();
}
else
moveCount++;
{
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;
+ if (thisThread == Threads.main_thread() && Time::now() - SearchTime > 2000)
+ sync_cout << "info depth " << depth / ONE_PLY
+ << " currmove " << move_to_uci(move, Chess960)
+ << " currmovenumber " << moveCount + PVIdx << sync_endl;
}
isPvMove = (PvNode && moveCount <= 1);
&& (!threatMove || !connected_threat(pos, move, threatMove)))
{
if (SpNode)
- lock_grab(sp->lock);
+ sp->mutex.lock();
continue;
}
if (futilityValue < beta)
{
if (SpNode)
- lock_grab(sp->lock);
+ sp->mutex.lock();
continue;
}
&& pos.see_sign(move) < 0)
{
if (SpNode)
- lock_grab(sp->lock);
+ sp->mutex.lock();
continue;
}
// Step 18. Check for new best move
if (SpNode)
{
- lock_grab(sp->lock);
+ sp->mutex.lock();
bestValue = sp->bestValue;
alpha = sp->alpha;
}
static RKISS rk;
// PRNG sequence should be not deterministic
- for (int i = Time::current_time().msec() % 50; i > 0; i--)
+ for (int i = Time::now() % 50; i > 0; i--)
rk.rand<unsigned>();
// RootMoves are already sorted by score in descending order
string uci_pv(const Position& pos, int depth, Value alpha, Value beta) {
std::stringstream s;
- int t = SearchTime.elapsed();
+ int t = Time::now() - SearchTime;
int selDepth = 0;
for (size_t i = 0; i < Threads.size(); i++)
}
// 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;
}
// 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
{
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);
memcpy(ss, sp->ss - 1, 4 * sizeof(Stack));
(ss+1)->sp = sp;
- lock_grab(sp->lock);
+ sp->mutex.lock();
if (sp->nodeType == Root)
search<SplitPointRoot>(pos, ss+1, sp->alpha, sp->beta, sp->depth);
// 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();
}
}
}
void check_time() {
- static Time lastInfoTime = Time::current_time();
+ static Time::point lastInfoTime = Time::now();
- if (lastInfoTime.elapsed() >= 1000)
+ if (Time::now() - lastInfoTime >= 1000)
{
- lastInfoTime.restart();
+ lastInfoTime = Time::now();
dbg_print();
}
if (Limits.ponder)
return;
- int e = SearchTime.elapsed();
+ int e = Time::now() - SearchTime;
bool stillAtFirstMove = Signals.firstRootMove
&& !Signals.failedLowAtRoot
&& e > TimeMgr.available_time();