From 8c8a69bf4a109a14ee04f800c4006d1d03505c52 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..fe00f5cab5 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_for (lock, 100ms, [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)] () {