mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-12 11:19:08 -05:00
Merge bitcoin/bitcoin#30896: kernel: Move background load thread to node context
bc7900f33d
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: ACKbc7900f33d
🔄 achow101: ACKbc7900f33d
ryanofsky: Code review ACKbc7900f33d
. Nice cleanup jonatack: Light ACKbc7900f33d
stickies-v: ACKbc7900f33d
Tree-SHA512: add9c4823731324e3db50f95e023e99d55db7cc75c69083ae7c9c2157e5540968caa6cf10674aa4901f91366b02ebb1ff18bb977fec0a46431e2196448958b9d
This commit is contained in:
commit
0c4ff18ee9
4 changed files with 4 additions and 6 deletions
|
@ -283,8 +283,6 @@ int main(int argc, char* argv[])
|
||||||
epilogue:
|
epilogue:
|
||||||
// Without this precise shutdown sequence, there will be a lot of nullptr
|
// Without this precise shutdown sequence, there will be a lot of nullptr
|
||||||
// dereferencing and UB.
|
// dereferencing and UB.
|
||||||
if (chainman.m_thread_load.joinable()) chainman.m_thread_load.join();
|
|
||||||
|
|
||||||
validation_signals.FlushBackgroundCallbacks();
|
validation_signals.FlushBackgroundCallbacks();
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
|
@ -298,7 +298,7 @@ void Shutdown(NodeContext& node)
|
||||||
|
|
||||||
StopTorControl();
|
StopTorControl();
|
||||||
|
|
||||||
if (node.chainman && node.chainman->m_thread_load.joinable()) node.chainman->m_thread_load.join();
|
if (node.background_init_thread.joinable()) node.background_init_thread.join();
|
||||||
// After everything has been shut down, but before things get flushed, stop the
|
// After everything has been shut down, but before things get flushed, stop the
|
||||||
// the scheduler. After this point, SyncWithValidationInterfaceQueue() should not be called anymore
|
// the scheduler. After this point, SyncWithValidationInterfaceQueue() should not be called anymore
|
||||||
// as this would prevent the shutdown from completing.
|
// as this would prevent the shutdown from completing.
|
||||||
|
@ -1789,7 +1789,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
vImportFiles.push_back(fs::PathFromString(strFile));
|
vImportFiles.push_back(fs::PathFromString(strFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
chainman.m_thread_load = std::thread(&util::TraceThread, "initload", [=, &chainman, &args, &node] {
|
node.background_init_thread = std::thread(&util::TraceThread, "initload", [=, &chainman, &args, &node] {
|
||||||
ScheduleBatchPriority();
|
ScheduleBatchPriority();
|
||||||
// Import blocks
|
// Import blocks
|
||||||
ImportBlocks(chainman, vImportFiles);
|
ImportBlocks(chainman, vImportFiles);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class ArgsManager;
|
class ArgsManager;
|
||||||
|
@ -86,6 +87,7 @@ struct NodeContext {
|
||||||
std::atomic<int> exit_status{EXIT_SUCCESS};
|
std::atomic<int> exit_status{EXIT_SUCCESS};
|
||||||
//! Manages all the node warnings
|
//! Manages all the node warnings
|
||||||
std::unique_ptr<node::Warnings> warnings;
|
std::unique_ptr<node::Warnings> warnings;
|
||||||
|
std::thread background_init_thread;
|
||||||
|
|
||||||
//! Declare default constructor and destructor that are not inline, so code
|
//! Declare default constructor and destructor that are not inline, so code
|
||||||
//! instantiating the NodeContext struct doesn't need to #include class
|
//! instantiating the NodeContext struct doesn't need to #include class
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -1008,7 +1007,6 @@ public:
|
||||||
|
|
||||||
const util::SignalInterrupt& m_interrupt;
|
const util::SignalInterrupt& m_interrupt;
|
||||||
const Options m_options;
|
const Options m_options;
|
||||||
std::thread m_thread_load;
|
|
||||||
//! A single BlockManager instance is shared across each constructed
|
//! A single BlockManager instance is shared across each constructed
|
||||||
//! chainstate to avoid duplicating block metadata.
|
//! chainstate to avoid duplicating block metadata.
|
||||||
node::BlockManager m_blockman;
|
node::BlockManager m_blockman;
|
||||||
|
|
Loading…
Add table
Reference in a new issue