X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fthread.cpp;h=c76b4b707e9f97dfe641670de06021b982481287;hp=34424d3791c7b30fdabab421b93c506c93f285a0;hb=9c9205860c5ab0e4f3180298e3f7082be259772c;hpb=27c5cb59127101d834636d4faa0062d4e7bd05ce diff --git a/src/thread.cpp b/src/thread.cpp index 34424d37..c76b4b70 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -66,7 +66,7 @@ void ThreadBase::notify_one() { // ThreadBase::wait() set the thread to sleep until 'condition' turns true -void ThreadBase::wait(std::atomic& condition) { +void ThreadBase::wait(std::atomic_bool& condition) { std::unique_lock lk(mutex); sleepCondition.wait(lk, [&]{ return bool(condition); }); @@ -74,7 +74,7 @@ void ThreadBase::wait(std::atomic& condition) { // ThreadBase::wait_while() set the thread to sleep until 'condition' turns false -void ThreadBase::wait_while(std::atomic& condition) { +void ThreadBase::wait_while(std::atomic_bool& condition) { std::unique_lock lk(mutex); sleepCondition.wait(lk, [&]{ return !condition; }); @@ -86,34 +86,14 @@ void ThreadBase::wait_while(std::atomic& condition) { Thread::Thread() { - searching = false; - maxPly = 0; + searching = resetCallsCnt = false; + maxPly = callsCnt = 0; history.clear(); counterMoves.clear(); idx = Threads.size(); // Starts from 0 } -// TimerThread::idle_loop() is where the timer thread waits Resolution milliseconds -// and then calls check_time(). When not searching, thread sleeps until it's woken up. - -void TimerThread::idle_loop() { - - while (!exit) - { - std::unique_lock lk(mutex); - - if (!exit) - sleepCondition.wait_for(lk, std::chrono::milliseconds(run ? Resolution : INT_MAX)); - - lk.unlock(); - - if (!exit && run) - check_time(); - } -} - - // Thread::idle_loop() is where the thread is parked when it has no work to do void Thread::idle_loop() { @@ -174,7 +154,6 @@ void MainThread::join() { void ThreadPool::init() { - timer = new_thread(); push_back(new_thread()); read_uci_options(); } @@ -185,9 +164,6 @@ void ThreadPool::init() { void ThreadPool::exit() { - delete_thread(timer); // As first because check_time() accesses threads data - timer = nullptr; - for (Thread* th : *this) delete_thread(th);