Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | |||||
// have exited. | // have exited. | ||||
// | // | ||||
// Shutdown for Qt is very similar, only it uses a QTimer to detect | // Shutdown for Qt is very similar, only it uses a QTimer to detect | ||||
// ShutdownRequested() getting set, and then does the normal Qt shutdown thing. | // ShutdownRequested() getting set, and then does the normal Qt shutdown thing. | ||||
// | // | ||||
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle; | static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle; | ||||
static std::thread g_load_block; | |||||
static boost::thread_group threadGroup; | static boost::thread_group threadGroup; | ||||
void Interrupt(NodeContext &node) { | void Interrupt(NodeContext &node) { | ||||
InterruptHTTPServer(); | InterruptHTTPServer(); | ||||
InterruptHTTPRPC(); | InterruptHTTPRPC(); | ||||
InterruptRPC(); | InterruptRPC(); | ||||
InterruptREST(); | InterruptREST(); | ||||
InterruptTorControl(); | InterruptTorControl(); | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | if (node.connman) { | ||||
node.connman->StopThreads(); | node.connman->StopThreads(); | ||||
LOCK2(::cs_main, ::g_cs_orphans); | LOCK2(::cs_main, ::g_cs_orphans); | ||||
node.connman->StopNodes(); | node.connman->StopNodes(); | ||||
} | } | ||||
StopTorControl(); | StopTorControl(); | ||||
// After everything has been shut down, but before things get flushed, stop | // After everything has been shut down, but before things get flushed, stop | ||||
// the CScheduler/checkqueue threadGroup | // the CScheduler/checkqueue, threadGroup and load block thread. | ||||
if (node.scheduler) { | if (node.scheduler) { | ||||
node.scheduler->stop(); | node.scheduler->stop(); | ||||
} | } | ||||
if (g_load_block.joinable()) { | |||||
g_load_block.join(); | |||||
} | |||||
threadGroup.interrupt_all(); | threadGroup.interrupt_all(); | ||||
threadGroup.join_all(); | threadGroup.join_all(); | ||||
// After the threads that potentially access these pointers have been | // After the threads that potentially access these pointers have been | ||||
// stopped, destruct and reset all to nullptr. | // stopped, destruct and reset all to nullptr. | ||||
node.peerman.reset(); | node.peerman.reset(); | ||||
// Destroy various global instances | // Destroy various global instances | ||||
▲ Show 20 Lines • Show All 1,107 Lines • ▼ Show 20 Lines | for (const auto &item : mapBlockFiles) { | ||||
} | } | ||||
remove(item.second); | remove(item.second); | ||||
} | } | ||||
} | } | ||||
static void ThreadImport(const Config &config, ChainstateManager &chainman, | static void ThreadImport(const Config &config, ChainstateManager &chainman, | ||||
std::vector<fs::path> vImportFiles, | std::vector<fs::path> vImportFiles, | ||||
const ArgsManager &args) { | const ArgsManager &args) { | ||||
util::ThreadRename("loadblk"); | |||||
ScheduleBatchPriority(); | ScheduleBatchPriority(); | ||||
{ | { | ||||
const CChainParams &chainParams = config.GetChainParams(); | const CChainParams &chainParams = config.GetChainParams(); | ||||
CImportingNow imp; | CImportingNow imp; | ||||
// -reindex | // -reindex | ||||
▲ Show 20 Lines • Show All 1,504 Lines • ▼ Show 20 Lines | #if defined(HAVE_SYSTEM) | ||||
} | } | ||||
#endif | #endif | ||||
std::vector<fs::path> vImportFiles; | std::vector<fs::path> vImportFiles; | ||||
for (const std::string &strFile : args.GetArgs("-loadblock")) { | for (const std::string &strFile : args.GetArgs("-loadblock")) { | ||||
vImportFiles.push_back(strFile); | vImportFiles.push_back(strFile); | ||||
} | } | ||||
threadGroup.create_thread([=, &config, &chainman, &args] { | g_load_block = | ||||
std::thread(&TraceThread<std::function<void()>>, "loadblk", | |||||
[=, &config, &chainman, &args] { | |||||
ThreadImport(config, chainman, vImportFiles, args); | ThreadImport(config, chainman, vImportFiles, args); | ||||
}); | }); | ||||
// Wait for genesis block to be processed | // Wait for genesis block to be processed | ||||
{ | { | ||||
WAIT_LOCK(g_genesis_wait_mutex, lock); | WAIT_LOCK(g_genesis_wait_mutex, lock); | ||||
// We previously could hang here if StartShutdown() is called prior to | // We previously could hang here if StartShutdown() is called prior to | ||||
// ThreadImport getting started, so instead we just wait on a timer to | // ThreadImport getting started, so instead we just wait on a timer to | ||||
// check ShutdownRequested() regularly. | // check ShutdownRequested() regularly. | ||||
while (!fHaveGenesis && !ShutdownRequested()) { | while (!fHaveGenesis && !ShutdownRequested()) { | ||||
▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines |