6565#include < scheduler.h>
6666#include < script/sigcache.h>
6767#include < script/standard.h>
68- #include < shutdown.h>
6968#include < sync.h>
7069#include < timedata.h>
7170#include < torcontrol.h>
@@ -184,17 +183,16 @@ static fs::path GetPidFile(const ArgsManager& args)
184183// The network-processing threads are all part of a thread group
185184// created by AppInit() or the Qt main() function.
186185//
187- // A clean exit happens when StartShutdown() or the SIGTERM
188- // signal handler sets ShutdownRequested(), which makes main thread's
189- // WaitForShutdown() interrupts the thread group.
190- // And then, WaitForShutdown() makes all other on-going threads
191- // in the thread group join the main thread.
186+ // A clean exit happens when the SignalInterrupt object or SIGTERM signal
187+ // handler is triggered. Which makes main thread's SignalInterrupt::wait() call
188+ // return, and join all other ongoing threads in the thread group to the main
189+ // thread.
192190// Shutdown() is then called to clean up database connections, and stop other
193191// threads that should only be stopped after the main network-processing
194192// threads have exited.
195193//
196194// Shutdown for Qt is very similar, only it uses a QTimer to detect
197- // ShutdownRequested() getting set, and then does the normal Qt
195+ // SignalInterrupt getting set, and then does the normal Qt
198196// shutdown thing.
199197//
200198
@@ -365,7 +363,7 @@ void Shutdown(NodeContext& node)
365363#ifndef WIN32
366364static void HandleSIGTERM (int )
367365{
368- StartShutdown ();
366+ Assert (kernel::g_context)-> interrupt ();
369367}
370368
371369static void HandleSIGHUP (int )
@@ -375,7 +373,7 @@ static void HandleSIGHUP(int)
375373#else
376374static BOOL WINAPI consoleCtrlHandler (DWORD dwCtrlType)
377375{
378- StartShutdown ();
376+ Assert (kernel::g_context)-> interrupt ();
379377 Sleep (INFINITE);
380378 return true ;
381379}
@@ -663,7 +661,7 @@ static bool AppInitServers(NodeContext& node)
663661 const ArgsManager& args = *Assert (node.args );
664662 RPCServer::OnStarted (&OnRPCStarted);
665663 RPCServer::OnStopped (&OnRPCStopped);
666- if (!InitHTTPServer ())
664+ if (!InitHTTPServer (node. kernel -> interrupt ))
667665 return false ;
668666 StartRPC ();
669667 node.rpc_interruption_point = RpcInterruptionPoint;
@@ -1407,7 +1405,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14071405
14081406 // ********************************************************* Step 7: load block chain
14091407
1410- node.notifications = std::make_unique<KernelNotifications>(node.exit_status );
1408+ node.notifications = std::make_unique<KernelNotifications>(node.kernel -> interrupt , node. exit_status );
14111409 fReindex = args.GetBoolArg (" -reindex" , false );
14121410 bool fReindexChainState = args.GetBoolArg (" -reindex-chainstate" , false );
14131411 ChainstateManager::Options chainman_opts{
@@ -1458,7 +1456,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14581456 }
14591457 LogPrintf (" * Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n " , cache_sizes.coins * (1.0 / 1024 / 1024 ), mempool_opts.max_size_bytes * (1.0 / 1024 / 1024 ));
14601458
1461- for (bool fLoaded = false ; !fLoaded && !ShutdownRequested () ;) {
1459+ for (bool fLoaded = false ; !fLoaded && !node. kernel -> interrupt ;) {
14621460 node.mempool = std::make_unique<CTxMemPool>(mempool_opts);
14631461
14641462 node.chainman = std::make_unique<ChainstateManager>(node.kernel ->interrupt , chainman_opts, blockman_opts);
@@ -1472,7 +1470,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14721470 options.check_blocks = args.GetIntArg (" -checkblocks" , DEFAULT_CHECKBLOCKS);
14731471 options.check_level = args.GetIntArg (" -checklevel" , DEFAULT_CHECKLEVEL);
14741472 options.require_full_verification = args.IsArgSet (" -checkblocks" ) || args.IsArgSet (" -checklevel" );
1475- options.check_interrupt = ShutdownRequested;
14761473 options.coins_error_cb = [] {
14771474 uiInterface.ThreadSafeMessageBox (
14781475 _ (" Error reading from database, shutting down." ),
@@ -1507,7 +1504,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15071504 return InitError (error);
15081505 }
15091506
1510- if (!fLoaded && !ShutdownRequested () ) {
1507+ if (!fLoaded && !node. kernel -> interrupt ) {
15111508 // first suggest a reindex
15121509 if (!options.reindex ) {
15131510 bool fRet = uiInterface.ThreadSafeQuestion (
@@ -1516,7 +1513,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15161513 " " , CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
15171514 if (fRet ) {
15181515 fReindex = true ;
1519- AbortShutdown ();
1516+ node. kernel -> interrupt . reset ();
15201517 } else {
15211518 LogPrintf (" Aborted block database rebuild. Exiting.\n " );
15221519 return false ;
@@ -1530,7 +1527,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15301527 // As LoadBlockIndex can take several minutes, it's possible the user
15311528 // requested to kill the GUI during the last operation. If so, exit.
15321529 // As the program has not fully started yet, Shutdown() is possibly overkill.
1533- if (ShutdownRequested () ) {
1530+ if (node. kernel -> interrupt ) {
15341531 LogPrintf (" Shutdown requested. Exiting.\n " );
15351532 return false ;
15361533 }
@@ -1655,7 +1652,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16551652 ImportBlocks (chainman, vImportFiles);
16561653 if (args.GetBoolArg (" -stopafterblockimport" , DEFAULT_STOPAFTERBLOCKIMPORT)) {
16571654 LogPrintf (" Stopping after block import\n " );
1658- StartShutdown ();
1655+ node. kernel -> interrupt ();
16591656 return ;
16601657 }
16611658
@@ -1672,16 +1669,16 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16721669 // Wait for genesis block to be processed
16731670 {
16741671 WAIT_LOCK (g_genesis_wait_mutex, lock);
1675- // We previously could hang here if StartShutdown () is called prior to
1672+ // We previously could hang here if node.kernel->interrupt () is called prior to
16761673 // ImportBlocks getting started, so instead we just wait on a timer to
1677- // check ShutdownRequested() regularly.
1678- while (!fHaveGenesis && !ShutdownRequested () ) {
1674+ // check node.kernel->interrupt regularly.
1675+ while (!fHaveGenesis && !node. kernel -> interrupt ) {
16791676 g_genesis_wait_cv.wait_for (lock, std::chrono::milliseconds (500 ));
16801677 }
16811678 block_notify_genesis_wait_connection.disconnect ();
16821679 }
16831680
1684- if (ShutdownRequested () ) {
1681+ if (node. kernel -> interrupt ) {
16851682 return false ;
16861683 }
16871684
0 commit comments