Skip to content

Commit

Permalink
refactor: move load block thread into ChainstateManager
Browse files Browse the repository at this point in the history
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 <falke.marco@gmail.com>
  • Loading branch information
fanquake and MarcoFalke committed Jan 29, 2021
1 parent c8b8351 commit f538c25
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ static fs::path GetPidFile(const ArgsManager& args)

static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;

static std::thread g_load_block;

static boost::thread_group threadGroup;

void Interrupt(NodeContext& node)
Expand Down Expand Up @@ -220,7 +218,7 @@ void Shutdown(NodeContext& node)
// After everything has been shut down, but before things get flushed, stop the
// CScheduler/checkqueue, threadGroup and load block thread.
if (node.scheduler) node.scheduler->stop();
if (g_load_block.joinable()) g_load_block.join();
if (node.chainman && node.chainman->m_load_block.joinable()) node.chainman->m_load_block.join();
threadGroup.interrupt_all();
threadGroup.join_all();
StopScriptCheckWorkerThreads();
Expand Down Expand Up @@ -1865,7 +1863,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
vImportFiles.push_back(strFile);
}

g_load_block = std::thread(&TraceThread<std::function<void()>>, "loadblk", [=, &chainman, &args] {
chainman.m_load_block = std::thread(&TraceThread<std::function<void()>>, "loadblk", [=, &chainman, &args] {
ThreadImport(chainman, vImportFiles, args);
});

Expand Down
2 changes: 2 additions & 0 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <set>
#include <stdint.h>
#include <string>
#include <thread>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -828,6 +829,7 @@ class ChainstateManager
friend CChain& ChainActive();

public:
std::thread m_load_block;
//! A single BlockManager instance is shared across each constructed
//! chainstate to avoid duplicating block metadata.
BlockManager m_blockman GUARDED_BY(::cs_main);
Expand Down

0 comments on commit f538c25

Please sign in to comment.