Fixing more locking issues on bootstrap_ascending::stopped identified by TSAN (#4212)

* Fixing more locking issues on bootstrap_ascending::stopped

* Ensure there is an owned lock on throttle_if_needed

---------

Co-authored-by: Thiago Silva <thiago@nano.org>
This commit is contained in:
clemahieu 2023-04-05 21:44:13 +01:00 committed by GitHub
commit f65e58a2d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View file

@ -581,9 +581,10 @@ void nano::bootstrap_ascending::inspect (nano::transaction const & tx, nano::pro
void nano::bootstrap_ascending::wait_blockprocessor ()
{
nano::unique_lock<nano::mutex> lock{ mutex };
while (!stopped && block_processor.half_full ())
{
std::this_thread::sleep_for (500ms); // Blockprocessor is relatively slow, sleeping here instead of using conditions
condition.wait_for (lock, 500ms, [this] () { return stopped; }); // Blockprocessor is relatively slow, sleeping here instead of using conditions
}
}
@ -718,9 +719,9 @@ bool nano::bootstrap_ascending::run_one ()
return success;
}
void nano::bootstrap_ascending::throttle_if_needed ()
void nano::bootstrap_ascending::throttle_if_needed (nano::unique_lock<nano::mutex> & lock)
{
nano::unique_lock<nano::mutex> lock{ mutex };
debug_assert (lock.owns_lock ());
if (!iterator.warmup () && throttle.throttled ())
{
stats.inc (nano::stat::type::bootstrap_ascending, nano::stat::detail::throttled);
@ -730,11 +731,14 @@ void nano::bootstrap_ascending::throttle_if_needed ()
void nano::bootstrap_ascending::run ()
{
nano::unique_lock<nano::mutex> lock{ mutex };
while (!stopped)
{
lock.unlock ();
stats.inc (nano::stat::type::bootstrap_ascending, nano::stat::detail::loop);
run_one ();
throttle_if_needed ();
lock.lock ();
throttle_if_needed (lock);
}
}

View file

@ -105,7 +105,7 @@ private:
/* Inspects a block that has been processed by the block processor */
void inspect (nano::transaction const &, nano::process_return const & result, nano::block const & block);
void throttle_if_needed ();
void throttle_if_needed (nano::unique_lock<nano::mutex> & lock);
void run ();
bool run_one ();
void run_timeouts ();