Skip to content

Commit e3341df

Browse files
fanquakeMarcoFalke
andcommitted
refactor: move load block thread into ChainstateManager
This is a diff of Marcos from #19197, which probably should have just been used at the time. After this change, and #21016, we'll have no more global thread(Group)s hanging out in init. Co-authored-by: MarcoFalke <[email protected]>
1 parent f72d80b commit e3341df

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/init.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ static fs::path GetPidFile(const ArgsManager& args)
154154

155155
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
156156

157-
static std::thread g_load_block;
158-
159157
void Interrupt(NodeContext& node)
160158
{
161159
InterruptHTTPServer();
@@ -219,7 +217,7 @@ void Shutdown(NodeContext& node)
219217
// After everything has been shut down, but before things get flushed, stop the
220218
// CScheduler/checkqueue, scheduler and load block thread.
221219
if (node.scheduler) node.scheduler->stop();
222-
if (g_load_block.joinable()) g_load_block.join();
220+
if (node.chainman && node.chainman->m_load_block.joinable()) node.chainman->m_load_block.join();
223221
StopScriptCheckWorkerThreads();
224222

225223
// After the threads that potentially access these pointers have been stopped,
@@ -1862,7 +1860,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
18621860
vImportFiles.push_back(strFile);
18631861
}
18641862

1865-
g_load_block = std::thread(&TraceThread<std::function<void()>>, "loadblk", [=, &chainman, &args] {
1863+
chainman.m_load_block = std::thread(&TraceThread<std::function<void()>>, "loadblk", [=, &chainman, &args] {
18661864
ThreadImport(chainman, vImportFiles, args);
18671865
});
18681866

src/validation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <set>
3232
#include <stdint.h>
3333
#include <string>
34+
#include <thread>
3435
#include <utility>
3536
#include <vector>
3637

@@ -839,6 +840,7 @@ class ChainstateManager
839840
friend CChain& ChainActive();
840841

841842
public:
843+
std::thread m_load_block;
842844
//! A single BlockManager instance is shared across each constructed
843845
//! chainstate to avoid duplicating block metadata.
844846
BlockManager m_blockman GUARDED_BY(::cs_main);

0 commit comments

Comments
 (0)