thread: 添加 Thread::pause() 函数并将 stop 更名为 pause (WIP)

尚未确认是否正常工作。
This commit is contained in:
Calcitem 2020-10-04 17:33:47 +08:00
parent b2de7354ce
commit bbafc09ef8
4 changed files with 20 additions and 11 deletions

View File

@ -104,6 +104,13 @@ void Thread::start_searching()
cv.notify_one(); // Wake up the thread in idle_loop()
}
void Thread::pause()
{
// TODO: Can work?
std::lock_guard<std::mutex> lk(mutex);
searching = false;
cv.notify_one(); // Wake up the thread in idle_loop()
}
/// Thread::wait_for_search_finished() blocks on the condition variable
/// until the thread has finished searching.

View File

@ -61,6 +61,8 @@ public:
void wait_for_search_finished();
int best_move_count(Move move) const;
void pause();
size_t pvIdx, pvLast;
uint64_t ttHitAverage;
int selDepth, nmpMinPly;

View File

@ -116,7 +116,7 @@ GameController::~GameController()
killTimer(timeID);
// 停掉线程
stopAndWaitThreads();
pauseAndWaitThreads();
deleteAiThreads();
#ifdef ENDGAME_LEARNING
@ -194,7 +194,7 @@ void GameController::gameReset()
// 停掉线程
if (!gameOptions.getAutoRestart()) {
stopThreads();
pauseThreads();
resetAiPlayers();
}
@ -877,7 +877,7 @@ bool GameController::actionPiece(QPointF pos)
}
// 如果已经决出胜负
else {
stopThreads();
pauseThreads();
}
}
@ -1017,7 +1017,7 @@ bool GameController::command(const string &cmd, bool update /* = true */)
}
// 如果已经决出胜负
else {
stopThreads();
pauseThreads();
gameEndTime = now();
gameDurationTime = gameEndTime - gameStartTime;

View File

@ -279,19 +279,19 @@ public slots:
void stopAndWaitAiThreads()
{
if (isAiPlayer[BLACK]) {
aiThread[BLACK]->start_searching();
aiThread[BLACK]->pause();
aiThread[BLACK]->wait_for_search_finished();
}
if (isAiPlayer[WHITE]) {
aiThread[WHITE]->start_searching();
aiThread[WHITE]->pause();
aiThread[WHITE]->wait_for_search_finished();
}
}
void stopThreads()
void pauseThreads()
{
aiThread[BLACK]->start_searching();
aiThread[WHITE]->start_searching();
aiThread[BLACK]->pause();
aiThread[WHITE]->pause();
}
void waitThreads()
@ -300,9 +300,9 @@ public slots:
aiThread[WHITE]->wait_for_search_finished();
}
void stopAndWaitThreads()
void pauseAndWaitThreads()
{
stopThreads();
pauseThreads();
waitThreads();
}