Skip to content

Commit 0c4ff18

Browse files
committed
Merge bitcoin/bitcoin#30896: kernel: Move background load thread to node context
bc7900f kernel: Move background load thread to node context (TheCharlatan) Pull request description: The thread handle is never used by the ChainstateManager, so move it out and into the node context. Users of the kernel library now no longer have to manually join the thread when destructing the ChainstateManager. ACKs for top commit: maflcko: ACK bc7900f 🔄 achow101: ACK bc7900f ryanofsky: Code review ACK bc7900f. Nice cleanup jonatack: Light ACK bc7900f stickies-v: ACK bc7900f Tree-SHA512: add9c4823731324e3db50f95e023e99d55db7cc75c69083ae7c9c2157e5540968caa6cf10674aa4901f91366b02ebb1ff18bb977fec0a46431e2196448958b9d
2 parents 87d5450 + bc7900f commit 0c4ff18

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

src/bitcoin-chainstate.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ int main(int argc, char* argv[])
283283
epilogue:
284284
// Without this precise shutdown sequence, there will be a lot of nullptr
285285
// dereferencing and UB.
286-
if (chainman.m_thread_load.joinable()) chainman.m_thread_load.join();
287-
288286
validation_signals.FlushBackgroundCallbacks();
289287
{
290288
LOCK(cs_main);

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void Shutdown(NodeContext& node)
298298

299299
StopTorControl();
300300

301-
if (node.chainman && node.chainman->m_thread_load.joinable()) node.chainman->m_thread_load.join();
301+
if (node.background_init_thread.joinable()) node.background_init_thread.join();
302302
// After everything has been shut down, but before things get flushed, stop the
303303
// the scheduler. After this point, SyncWithValidationInterfaceQueue() should not be called anymore
304304
// as this would prevent the shutdown from completing.
@@ -1789,7 +1789,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17891789
vImportFiles.push_back(fs::PathFromString(strFile));
17901790
}
17911791

1792-
chainman.m_thread_load = std::thread(&util::TraceThread, "initload", [=, &chainman, &args, &node] {
1792+
node.background_init_thread = std::thread(&util::TraceThread, "initload", [=, &chainman, &args, &node] {
17931793
ScheduleBatchPriority();
17941794
// Import blocks
17951795
ImportBlocks(chainman, vImportFiles);

src/node/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <cstdlib>
1010
#include <functional>
1111
#include <memory>
12+
#include <thread>
1213
#include <vector>
1314

1415
class ArgsManager;
@@ -86,6 +87,7 @@ struct NodeContext {
8687
std::atomic<int> exit_status{EXIT_SUCCESS};
8788
//! Manages all the node warnings
8889
std::unique_ptr<node::Warnings> warnings;
90+
std::thread background_init_thread;
8991

9092
//! Declare default constructor and destructor that are not inline, so code
9193
//! instantiating the NodeContext struct doesn't need to #include class

src/validation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include <span>
4343
#include <stdint.h>
4444
#include <string>
45-
#include <thread>
4645
#include <type_traits>
4746
#include <utility>
4847
#include <vector>
@@ -1008,7 +1007,6 @@ class ChainstateManager
10081007

10091008
const util::SignalInterrupt& m_interrupt;
10101009
const Options m_options;
1011-
std::thread m_thread_load;
10121010
//! A single BlockManager instance is shared across each constructed
10131011
//! chainstate to avoid duplicating block metadata.
10141012
node::BlockManager m_blockman;

0 commit comments

Comments
 (0)