From 7d6e85382bba57705e6d8a487b34dafda9d63d2b Mon Sep 17 00:00:00 2001 From: CastagnaIT Date: Fri, 25 Aug 2023 08:34:46 +0200 Subject: [PATCH] test --- src/common/AdaptiveTree.cpp | 17 ++++++++++++++++- src/common/AdaptiveTree.h | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/common/AdaptiveTree.cpp b/src/common/AdaptiveTree.cpp index 04e6bdf21..0b664aa99 100644 --- a/src/common/AdaptiveTree.cpp +++ b/src/common/AdaptiveTree.cpp @@ -563,8 +563,11 @@ namespace adaptive { std::unique_lock updLck(m_updMutex); - while (~m_tree->m_updateInterval && !m_threadStop) + while (~m_tree->m_updateInterval) { + if (m_threadStop) + break; + if (m_cvUpdInterval.wait_for(updLck, std::chrono::milliseconds(m_tree->m_updateInterval)) == std::cv_status::timeout) { @@ -579,6 +582,18 @@ namespace adaptive } } + void AdaptiveTree::TreeUpdateThread::Stop() + { + // If an update is already in progress the wait until its finished + while (true) + { + std::lock_guard updLck{m_updMutex}; + if (m_waitQueue == 0) + break; + } + m_threadStop = true; + } + void AdaptiveTree::TreeUpdateThread::Pause() { // If an update is already in progress the wait until its finished diff --git a/src/common/AdaptiveTree.h b/src/common/AdaptiveTree.h index 45ef4044d..de84f239c 100644 --- a/src/common/AdaptiveTree.h +++ b/src/common/AdaptiveTree.h @@ -525,6 +525,8 @@ class ATTR_DLL_LOCAL AdaptiveTree AdaptiveTree(const AdaptiveTree& left); virtual ~AdaptiveTree() { + m_updThread.Stop(); + for (auto period : periods_) delete period; } @@ -639,6 +641,9 @@ class ATTR_DLL_LOCAL AdaptiveTree // \brief As "std::mutex" unlock, but resume the manifest updates (support std::lock_guard). void unlock() { Resume(); } + // \brief Stop performing new updates. + void Stop() + private: void Worker(); void Pause();