From faf843c07f99f91603e08ea858f972516f1d669a Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 2 Apr 2021 20:38:28 +0200 Subject: [PATCH] refactor: Move load block thread into ChainstateManager --- src/init.cpp | 6 ++---- src/validation.h | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 17b216573f2..7e963e81902 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -155,8 +155,6 @@ static fs::path GetPidFile(const ArgsManager& args) static std::unique_ptr globalVerifyHandle; -static std::thread g_load_block; - void Interrupt(NodeContext& node) { InterruptHTTPServer(); @@ -220,7 +218,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, @@ -1880,7 +1878,7 @@ bool AppInitMain(const std::any& context, NodeContext& node, interfaces::BlockAn vImportFiles.push_back(strFile); } - g_load_block = std::thread(&TraceThread>, "loadblk", [=, &chainman, &args] { + chainman.m_load_block = std::thread(&TraceThread>, "loadblk", [=, &chainman, &args] { ThreadImport(chainman, vImportFiles, args); }); diff --git a/src/validation.h b/src/validation.h index 21e63947fae..3f7e967ec76 100644 --- a/src/validation.h +++ b/src/validation.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -869,6 +870,7 @@ private: 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);