0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

Make CCheckQueue destructor stop worker threads

This commit is contained in:
Hennadii Stepanov 2023-07-07 10:37:36 +01:00
parent be4ff3060b
commit d03eaacbcf
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
9 changed files with 2 additions and 29 deletions

View file

@ -61,7 +61,6 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
// it is done explicitly here for clarity // it is done explicitly here for clarity
control.Wait(); control.Wait();
}); });
queue.StopWorkerThreads();
ECC_Stop(); ECC_Stop();
} }
BENCHMARK(CCheckQueueSpeedPrevectorJob, benchmark::PriorityLevel::HIGH); BENCHMARK(CCheckQueueSpeedPrevectorJob, benchmark::PriorityLevel::HIGH);

View file

@ -290,7 +290,6 @@ epilogue:
// dereferencing and UB. // dereferencing and UB.
scheduler.stop(); scheduler.stop();
if (chainman.m_thread_load.joinable()) chainman.m_thread_load.join(); if (chainman.m_thread_load.joinable()) chainman.m_thread_load.join();
chainman.StopScriptCheckWorkerThreads();
GetMainSignals().FlushBackgroundCallbacks(); GetMainSignals().FlushBackgroundCallbacks();
{ {

View file

@ -179,24 +179,16 @@ public:
} }
} }
//! Stop all of the worker threads. ~CCheckQueue()
void StopWorkerThreads() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
{ {
WITH_LOCK(m_mutex, m_request_stop = true); WITH_LOCK(m_mutex, m_request_stop = true);
m_worker_cv.notify_all(); m_worker_cv.notify_all();
for (std::thread& t : m_worker_threads) { for (std::thread& t : m_worker_threads) {
t.join(); t.join();
} }
m_worker_threads.clear();
WITH_LOCK(m_mutex, m_request_stop = false);
} }
bool HasThreads() const { return !m_worker_threads.empty(); } bool HasThreads() const { return !m_worker_threads.empty(); }
~CCheckQueue()
{
assert(m_worker_threads.empty());
}
}; };
/** /**

View file

@ -268,10 +268,9 @@ void Shutdown(NodeContext& node)
StopTorControl(); StopTorControl();
// After everything has been shut down, but before things get flushed, stop the // After everything has been shut down, but before things get flushed, stop the
// CScheduler/checkqueue, scheduler and load block thread. // scheduler and load block thread.
if (node.scheduler) node.scheduler->stop(); if (node.scheduler) node.scheduler->stop();
if (node.chainman && node.chainman->m_thread_load.joinable()) node.chainman->m_thread_load.join(); if (node.chainman && node.chainman->m_thread_load.joinable()) node.chainman->m_thread_load.join();
if (node.chainman) node.chainman->StopScriptCheckWorkerThreads();
// After the threads that potentially access these pointers have been stopped, // After the threads that potentially access these pointers have been stopped,
// destruct and reset all to nullptr. // destruct and reset all to nullptr.

View file

@ -176,7 +176,6 @@ static void Correct_Queue_range(std::vector<size_t> range)
BOOST_REQUIRE(control.Wait()); BOOST_REQUIRE(control.Wait());
BOOST_REQUIRE_EQUAL(FakeCheckCheckCompletion::n_calls, i); BOOST_REQUIRE_EQUAL(FakeCheckCheckCompletion::n_calls, i);
} }
small_queue->StopWorkerThreads();
} }
/** Test that 0 checks is correct /** Test that 0 checks is correct
@ -240,7 +239,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
BOOST_REQUIRE(success); BOOST_REQUIRE(success);
} }
} }
fail_queue->StopWorkerThreads();
} }
// Test that a block validation which fails does not interfere with // Test that a block validation which fails does not interfere with
// future blocks, ie, the bad state is cleared. // future blocks, ie, the bad state is cleared.
@ -262,7 +260,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
BOOST_REQUIRE(r != end_fails); BOOST_REQUIRE(r != end_fails);
} }
} }
fail_queue->StopWorkerThreads();
} }
// Test that unique checks are actually all called individually, rather than // Test that unique checks are actually all called individually, rather than
@ -294,7 +291,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
} }
BOOST_REQUIRE(r); BOOST_REQUIRE(r);
} }
queue->StopWorkerThreads();
} }
@ -325,7 +321,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
} }
BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U); BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U);
} }
queue->StopWorkerThreads();
} }
// Test that a new verification cannot occur until all checks // Test that a new verification cannot occur until all checks
@ -361,7 +356,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
// Wait for control to finish // Wait for control to finish
t0.join(); t0.join();
BOOST_REQUIRE(!fails); BOOST_REQUIRE(!fails);
queue->StopWorkerThreads();
} }

View file

@ -553,7 +553,6 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction)
bool controlCheck = control.Wait(); bool controlCheck = control.Wait();
assert(controlCheck); assert(controlCheck);
scriptcheckqueue.StopWorkerThreads();
} }
SignatureData CombineSignatures(const CMutableTransaction& input1, const CMutableTransaction& input2, const CTransactionRef tx) SignatureData CombineSignatures(const CMutableTransaction& input1, const CMutableTransaction& input2, const CTransactionRef tx)

View file

@ -193,7 +193,6 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
ChainTestingSetup::~ChainTestingSetup() ChainTestingSetup::~ChainTestingSetup()
{ {
if (m_node.scheduler) m_node.scheduler->stop(); if (m_node.scheduler) m_node.scheduler->stop();
m_node.chainman->StopScriptCheckWorkerThreads();
GetMainSignals().FlushBackgroundCallbacks(); GetMainSignals().FlushBackgroundCallbacks();
GetMainSignals().UnregisterBackgroundSignalScheduler(); GetMainSignals().UnregisterBackgroundSignalScheduler();
m_node.connman.reset(); m_node.connman.reset();

View file

@ -2047,11 +2047,6 @@ DisconnectResult Chainstate::DisconnectBlock(const CBlock& block, const CBlockIn
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN; return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
} }
void ChainstateManager::StopScriptCheckWorkerThreads()
{
m_script_check_queue.StopWorkerThreads();
}
/** /**
* Threshold condition checker that triggers when unknown versionbits are seen on the network. * Threshold condition checker that triggers when unknown versionbits are seen on the network.
*/ */
@ -5754,8 +5749,6 @@ ChainstateManager::ChainstateManager(const util::SignalInterrupt& interrupt, Opt
ChainstateManager::~ChainstateManager() ChainstateManager::~ChainstateManager()
{ {
StopScriptCheckWorkerThreads();
LOCK(::cs_main); LOCK(::cs_main);
m_versionbitscache.Clear(); m_versionbitscache.Clear();

View file

@ -1246,7 +1246,6 @@ public:
std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
CCheckQueue<CScriptCheck>& GetCheckQueue() { return m_script_check_queue; } CCheckQueue<CScriptCheck>& GetCheckQueue() { return m_script_check_queue; }
void StopScriptCheckWorkerThreads();
~ChainstateManager(); ~ChainstateManager();
}; };