From 285c56d369fbf8f2aa186a640d98c352bba59bef Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 3 Sep 2024 01:43:28 +0100 Subject: [PATCH] Remove this_thread::sleep_for and instead use condition_variable::wait. Fixes checking whether the component is stopped. --- nano/node/confirming_set.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index 9a8f436e77..f668655b87 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -133,10 +133,14 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) notification.already_cemented.swap (already); // Wait for the worker thread if too many notifications are queued - while (notification_workers.num_queued_tasks () >= config.max_queued_notifications) + std::unique_lock lock{ mutex }; + bool stopped_l; + condition.wait (lock, [this, &stopped_l] { + return (stopped_l = stopped) || notification_workers.num_queued_tasks () < config.max_queued_notifications; + }); + if (stopped_l) { - stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cooldown); - std::this_thread::sleep_for (100ms); + return; } notification_workers.push_task ([this, notification = std::move (notification)] () {