Fix scope issue with mutex when setting thread names in the signature checker (#1674)

This commit is contained in:
Wesley Shillingford 2019-01-31 21:54:09 +00:00 committed by GitHub
commit 65b25846c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View file

@ -1374,7 +1374,7 @@ void nano::signature_checker::verify (nano::signature_check_set & check_a)
{
{
// Don't process anything else if we have stopped
std::lock_guard<std::mutex> guard (stopped_mutex);
std::lock_guard<std::mutex> guard (mutex);
if (stopped)
{
return;
@ -1426,7 +1426,7 @@ void nano::signature_checker::verify (nano::signature_check_set & check_a)
void nano::signature_checker::stop ()
{
std::lock_guard<std::mutex> guard (stopped_mutex);
std::lock_guard<std::mutex> guard (mutex);
if (!stopped)
{
stopped = true;
@ -1436,7 +1436,7 @@ void nano::signature_checker::stop ()
void nano::signature_checker::flush ()
{
std::lock_guard<std::mutex> guard (stopped_mutex);
std::lock_guard<std::mutex> guard (mutex);
while (!stopped && tasks_remaining != 0)
;
}
@ -1482,7 +1482,6 @@ void nano::signature_checker::set_thread_names (unsigned num_threads)
auto ready = false;
auto pending = num_threads;
std::condition_variable cv;
std::mutex mutex_l;
std::vector<std::promise<void>> promises (num_threads);
std::vector<std::future<void>> futures;
futures.reserve (num_threads);
@ -1493,8 +1492,8 @@ void nano::signature_checker::set_thread_names (unsigned num_threads)
for (auto i = 0u; i < num_threads; ++i)
{
// clang-format off
boost::asio::post (thread_pool, [&cv, &ready, &pending, &mutex_l, &promise = promises[i]]() {
std::unique_lock<std::mutex> lk (mutex_l);
boost::asio::post (thread_pool, [&cv, &ready, &pending, &mutex = mutex, &promise = promises[i]]() {
std::unique_lock<std::mutex> lk (mutex);
nano::thread_role::set (nano::thread_role::name::signature_checking);
if (--pending == 0)
{

View file

@ -464,7 +464,7 @@ private:
static constexpr size_t batch_size = 256;
const bool single_threaded;
unsigned num_threads;
std::mutex stopped_mutex;
std::mutex mutex;
bool stopped{ false };
};