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 4, 2024
1 parent be53f61 commit ebea02d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nano/node/confirming_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ void nano::confirming_set::run_batch (std::unique_lock<std::mutex> & lock)
notification.cemented.swap (cemented);
notification.already_cemented.swap (already);

// Wait for the worker thread if too many notifications are queued
std::unique_lock lock{ mutex };
while (notification_workers.num_queued_tasks () >= config.max_queued_notifications)
{
stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cooldown);
std::this_thread::sleep_for (100ms);
condition.wait_for (lock, 100ms, [this] { return stopped; });
if (stopped)
{
return;
}
}

notification_workers.push_task ([this, notification = std::move (notification)] () {
Expand Down

0 comments on commit ebea02d

Please sign in to comment.