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 Feb 2, 2021
1 parent f72d80b commit e3341df
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 @@ -154,8 +154,6 @@ static fs::path GetPidFile(const ArgsManager& args)

static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;

static std::thread g_load_block;

void Interrupt(NodeContext& node)
{
InterruptHTTPServer();
Expand Down Expand Up @@ -219,7 +217,7 @@ void Shutdown(NodeContext& node)
// After everything has been shut down, but before things get flushed, stop the
// CScheduler/checkqueue, scheduler 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();
StopScriptCheckWorkerThreads();

// After the threads that potentially access these pointers have been stopped,
Expand Down Expand Up @@ -1862,7 +1860,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 @@ -839,6 +840,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 e3341df

Please sign in to comment.