mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
refactor: Split up NodeContext shutdown_signal and shutdown_request
Instead of having a single NodeContext::shutdown member that is used both to request shutdowns and check if they have been requested, use separate members for each. Benefits of this change: 1. Should make code a little clearer and easier to search because it is easier to see which parts of code are triggering shutdowns and which parts are just checking to see if they were triggered. 2. Makes it possible for init.cpp to specify additional code to run when a shutdown is requested, like signalling the m_tip_block_cv condition variable. Motivation for this change was to remove hacky NodeContext argument and m_tip_block_cv access from the StopRPC function, so StopRPC can just be concerned with RPC functionality, not other node functionality.
This commit is contained in:
@@ -169,7 +169,7 @@ static RPCHelpMan stop()
|
||||
{
|
||||
// Event loop will exit after current HTTP requests have been handled, so
|
||||
// this reply will get back to the client.
|
||||
CHECK_NONFATAL((*CHECK_NONFATAL(EnsureAnyNodeContext(jsonRequest.context).shutdown))());
|
||||
CHECK_NONFATAL((CHECK_NONFATAL(EnsureAnyNodeContext(jsonRequest.context).shutdown_request))());
|
||||
if (jsonRequest.params[0].isNum()) {
|
||||
UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].getInt<int>()});
|
||||
}
|
||||
@@ -294,7 +294,7 @@ void InterruptRPC()
|
||||
});
|
||||
}
|
||||
|
||||
void StopRPC(const std::any& context)
|
||||
void StopRPC()
|
||||
{
|
||||
static std::once_flag g_rpc_stop_flag;
|
||||
// This function could be called twice if the GUI has been started with -server=1.
|
||||
@@ -303,9 +303,6 @@ void StopRPC(const std::any& context)
|
||||
LogDebug(BCLog::RPC, "Stopping RPC\n");
|
||||
WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
|
||||
DeleteAuthCookie();
|
||||
node::NodeContext& node = EnsureAnyNodeContext(context);
|
||||
// The notifications interface doesn't exist between initialization step 4a and 7.
|
||||
if (node.notifications) WITH_LOCK(node.notifications->m_tip_block_mutex, node.notifications->m_tip_block_cv.notify_all());
|
||||
LogDebug(BCLog::RPC, "RPC stopped.\n");
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user