Remove delay exiting node in request processor (#1904)

* Remove delay exiting node

* Make stopped atomic
This commit is contained in:
Wesley Shillingford 2019-04-13 17:14:50 +01:00 committed by GitHub
commit adbb93a5c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -2775,7 +2775,7 @@ void nano::active_transactions::confirm_frontiers (nano::transaction const & tra
{
size_t max_elections (max_broadcast_queue / 4);
size_t elections_count (0);
for (auto i (node.store.latest_begin (transaction_a, next_frontier_account)), n (node.store.latest_end ()); i != n && elections_count < max_elections; ++i)
for (auto i (node.store.latest_begin (transaction_a, next_frontier_account)), n (node.store.latest_end ()); i != n && !stopped && elections_count < max_elections; ++i)
{
nano::account_info info (i->second);
if (info.block_count != info.confirmation_height)
@ -3070,6 +3070,13 @@ void nano::active_transactions::request_loop ()
while (!stopped)
{
request_confirm (lock);
// This prevents unnecessary waiting if stopped is set in-between the above check and now
if (stopped)
{
break;
}
const auto extra_delay (std::min (roots.size (), max_broadcast_queue) * node.network.broadcast_interval_ms * 2);
condition.wait_for (lock, std::chrono::milliseconds (node.network_params.network.request_interval_ms + extra_delay));
}

View file

@ -158,7 +158,7 @@ private:
std::chrono::steady_clock::time_point next_frontier_check{ std::chrono::steady_clock::now () };
std::condition_variable condition;
bool started;
bool stopped;
std::atomic<bool> stopped;
boost::thread thread;
};