Avoid unnecessarily held lock in backlog_population (#4126)
This commit is contained in:
parent
3e0d54f7f7
commit
96aa938827
1 changed files with 8 additions and 4 deletions
|
|
@ -29,9 +29,10 @@ void nano::backlog_population::start ()
|
||||||
|
|
||||||
void nano::backlog_population::stop ()
|
void nano::backlog_population::stop ()
|
||||||
{
|
{
|
||||||
nano::unique_lock<nano::mutex> lock{ mutex };
|
{
|
||||||
stopped = true;
|
nano::lock_guard<nano::mutex> lock{ mutex };
|
||||||
lock.unlock ();
|
stopped = true;
|
||||||
|
}
|
||||||
notify ();
|
notify ();
|
||||||
nano::join_or_pass (thread);
|
nano::join_or_pass (thread);
|
||||||
}
|
}
|
||||||
|
|
@ -85,6 +86,7 @@ void nano::backlog_population::populate_backlog (nano::unique_lock<nano::mutex>
|
||||||
while (!stopped && !done)
|
while (!stopped && !done)
|
||||||
{
|
{
|
||||||
lock.unlock ();
|
lock.unlock ();
|
||||||
|
|
||||||
{
|
{
|
||||||
auto transaction = store.tx_begin_read ();
|
auto transaction = store.tx_begin_read ();
|
||||||
|
|
||||||
|
|
@ -101,9 +103,11 @@ void nano::backlog_population::populate_backlog (nano::unique_lock<nano::mutex>
|
||||||
}
|
}
|
||||||
done = store.account.begin (transaction, next) == end;
|
done = store.account.begin (transaction, next) == end;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock.lock ();
|
lock.lock ();
|
||||||
|
|
||||||
// Give the rest of the node time to progress without holding database lock
|
// Give the rest of the node time to progress without holding database lock
|
||||||
std::this_thread::sleep_for (std::chrono::milliseconds (1000 / config_m.frequency));
|
condition.wait_for (lock, std::chrono::milliseconds{ 1000 / config_m.frequency });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue