Skip to content

Commit

Permalink
Remove this_thread::sleep_for and instead use condition_variable::wait.
Browse files Browse the repository at this point in the history
Fixes checking whether the component is stopped.
  • Loading branch information
clemahieu committed Sep 3, 2024
1 parent be53f61 commit 8c8a69b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions nano/node/confirming_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ void nano::confirming_set::run_batch (std::unique_lock<std::mutex> & 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)] () {
Expand Down

0 comments on commit 8c8a69b

Please sign in to comment.