Skip to content

Commit d03eaac

Browse files
committed
Make CCheckQueue destructor stop worker threads
1 parent be4ff30 commit d03eaac

File tree

9 files changed

+2
-29
lines changed

9 files changed

+2
-29
lines changed

src/bench/checkqueue.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
6161
// it is done explicitly here for clarity
6262
control.Wait();
6363
});
64-
queue.StopWorkerThreads();
6564
ECC_Stop();
6665
}
6766
BENCHMARK(CCheckQueueSpeedPrevectorJob, benchmark::PriorityLevel::HIGH);

src/bitcoin-chainstate.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ int main(int argc, char* argv[])
290290
// dereferencing and UB.
291291
scheduler.stop();
292292
if (chainman.m_thread_load.joinable()) chainman.m_thread_load.join();
293-
chainman.StopScriptCheckWorkerThreads();
294293

295294
GetMainSignals().FlushBackgroundCallbacks();
296295
{

src/checkqueue.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,16 @@ class CCheckQueue
179179
}
180180
}
181181

182-
//! Stop all of the worker threads.
183-
void StopWorkerThreads() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
182+
~CCheckQueue()
184183
{
185184
WITH_LOCK(m_mutex, m_request_stop = true);
186185
m_worker_cv.notify_all();
187186
for (std::thread& t : m_worker_threads) {
188187
t.join();
189188
}
190-
m_worker_threads.clear();
191-
WITH_LOCK(m_mutex, m_request_stop = false);
192189
}
193190

194191
bool HasThreads() const { return !m_worker_threads.empty(); }
195-
196-
~CCheckQueue()
197-
{
198-
assert(m_worker_threads.empty());
199-
}
200192
};
201193

202194
/**

src/init.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,9 @@ void Shutdown(NodeContext& node)
268268
StopTorControl();
269269

270270
// After everything has been shut down, but before things get flushed, stop the
271-
// CScheduler/checkqueue, scheduler and load block thread.
271+
// scheduler and load block thread.
272272
if (node.scheduler) node.scheduler->stop();
273273
if (node.chainman && node.chainman->m_thread_load.joinable()) node.chainman->m_thread_load.join();
274-
if (node.chainman) node.chainman->StopScriptCheckWorkerThreads();
275274

276275
// After the threads that potentially access these pointers have been stopped,
277276
// destruct and reset all to nullptr.

src/test/checkqueue_tests.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ static void Correct_Queue_range(std::vector<size_t> range)
176176
BOOST_REQUIRE(control.Wait());
177177
BOOST_REQUIRE_EQUAL(FakeCheckCheckCompletion::n_calls, i);
178178
}
179-
small_queue->StopWorkerThreads();
180179
}
181180

182181
/** Test that 0 checks is correct
@@ -240,7 +239,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
240239
BOOST_REQUIRE(success);
241240
}
242241
}
243-
fail_queue->StopWorkerThreads();
244242
}
245243
// Test that a block validation which fails does not interfere with
246244
// future blocks, ie, the bad state is cleared.
@@ -262,7 +260,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
262260
BOOST_REQUIRE(r != end_fails);
263261
}
264262
}
265-
fail_queue->StopWorkerThreads();
266263
}
267264

268265
// Test that unique checks are actually all called individually, rather than
@@ -294,7 +291,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
294291
}
295292
BOOST_REQUIRE(r);
296293
}
297-
queue->StopWorkerThreads();
298294
}
299295

300296

@@ -325,7 +321,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
325321
}
326322
BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U);
327323
}
328-
queue->StopWorkerThreads();
329324
}
330325

331326
// Test that a new verification cannot occur until all checks
@@ -361,7 +356,6 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
361356
// Wait for control to finish
362357
t0.join();
363358
BOOST_REQUIRE(!fails);
364-
queue->StopWorkerThreads();
365359
}
366360

367361

src/test/transaction_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction)
553553

554554
bool controlCheck = control.Wait();
555555
assert(controlCheck);
556-
scriptcheckqueue.StopWorkerThreads();
557556
}
558557

559558
SignatureData CombineSignatures(const CMutableTransaction& input1, const CMutableTransaction& input2, const CTransactionRef tx)

src/test/util/setup_common.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
193193
ChainTestingSetup::~ChainTestingSetup()
194194
{
195195
if (m_node.scheduler) m_node.scheduler->stop();
196-
m_node.chainman->StopScriptCheckWorkerThreads();
197196
GetMainSignals().FlushBackgroundCallbacks();
198197
GetMainSignals().UnregisterBackgroundSignalScheduler();
199198
m_node.connman.reset();

src/validation.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,11 +2047,6 @@ DisconnectResult Chainstate::DisconnectBlock(const CBlock& block, const CBlockIn
20472047
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
20482048
}
20492049

2050-
void ChainstateManager::StopScriptCheckWorkerThreads()
2051-
{
2052-
m_script_check_queue.StopWorkerThreads();
2053-
}
2054-
20552050
/**
20562051
* Threshold condition checker that triggers when unknown versionbits are seen on the network.
20572052
*/
@@ -5754,8 +5749,6 @@ ChainstateManager::ChainstateManager(const util::SignalInterrupt& interrupt, Opt
57545749

57555750
ChainstateManager::~ChainstateManager()
57565751
{
5757-
StopScriptCheckWorkerThreads();
5758-
57595752
LOCK(::cs_main);
57605753

57615754
m_versionbitscache.Clear();

src/validation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,6 @@ class ChainstateManager
12461246
std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
12471247

12481248
CCheckQueue<CScriptCheck>& GetCheckQueue() { return m_script_check_queue; }
1249-
void StopScriptCheckWorkerThreads();
12501249

12511250
~ChainstateManager();
12521251
};

0 commit comments

Comments
 (0)