From f5246e17d64ffb2f6d738817a8c334fbca6158a0 Mon Sep 17 00:00:00 2001 From: frikilax Date: Mon, 17 May 2021 17:21:40 +0000 Subject: [PATCH] ATHREAD::FIXED:: Do not immediately run buffer/tanomaly threads at startup --- toolkit/AThread.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/toolkit/AThread.cpp b/toolkit/AThread.cpp index 9c469445..17af39cb 100644 --- a/toolkit/AThread.cpp +++ b/toolkit/AThread.cpp @@ -10,7 +10,7 @@ #include "AThread.hpp" #include "Logger.hpp" -AThread::AThread(int interval) : +AThread::AThread(int interval) : _interval(interval), _thread(), _is_stop(false) {} @@ -21,14 +21,16 @@ void AThread::ThreadMain() { std::mutex mtx; std::unique_lock lck(mtx); - while (!(this->_is_stop)) { - if (!this->Main()) { - DARWIN_LOG_DEBUG("AThread::ThreadMain:: Error in main function, stopping the thread"); - _is_stop = true; - break; - } + while (not this->_is_stop) { // Wait for notification or until timeout this->_cv.wait_for(lck, std::chrono::seconds(_interval)); + if (not _is_stop) { + if (not this->Main()) { + DARWIN_LOG_DEBUG("AThread::ThreadMain:: Error in main function, stopping the thread"); + _is_stop = true; + break; + } + } } }