Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | |||||
// | // | ||||
// A clean exit happens when StartShutdown() or the SIGTERM signal handler sets | // A clean exit happens when StartShutdown() or the SIGTERM signal handler sets | ||||
// fRequestShutdown, which triggers the DetectShutdownThread(), which interrupts | // fRequestShutdown, which triggers the DetectShutdownThread(), which interrupts | ||||
// the main thread group. DetectShutdownThread() then exits, which causes | // the main thread group. DetectShutdownThread() then exits, which causes | ||||
// AppInit() to continue (it .joins the shutdown thread). Shutdown() is then | // AppInit() to continue (it .joins the shutdown thread). Shutdown() is then | ||||
// called to clean up database connections, and stop other threads that should | // called to clean up database connections, and stop other threads that should | ||||
// only be stopped after the main network-processing threads have exited. | // only be stopped after the main network-processing threads have exited. | ||||
// | // | ||||
// Note that if running -daemon the parent process returns from AppInit2 before | |||||
// adding any threads to the threadGroup, so .join_all() returns immediately and | |||||
// the parent exits from main(). | |||||
// | |||||
// 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 | ||||
// fRequestShutdown getting set, and then does the normal Qt shutdown thing. | // fRequestShutdown getting set, and then does the normal Qt shutdown thing. | ||||
// | // | ||||
std::atomic<bool> fRequestShutdown(false); | std::atomic<bool> fRequestShutdown(false); | ||||
void StartShutdown() { | void StartShutdown() { | ||||
fRequestShutdown = true; | fRequestShutdown = true; | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
void Shutdown() { | void Shutdown() { | ||||
LogPrintf("%s: In progress...\n", __func__); | LogPrintf("%s: In progress...\n", __func__); | ||||
static CCriticalSection cs_Shutdown; | static CCriticalSection cs_Shutdown; | ||||
TRY_LOCK(cs_Shutdown, lockShutdown); | TRY_LOCK(cs_Shutdown, lockShutdown); | ||||
if (!lockShutdown) { | if (!lockShutdown) { | ||||
return; | return; | ||||
} | } | ||||
/// Note: Shutdown() must be able to handle cases in which AppInit2() failed | /// Note: Shutdown() must be able to handle cases in which initialization | ||||
/// part of the way, for example if the data directory was found to be | /// failed part of the way, for example if the data directory was found to | ||||
/// locked. Be sure that anything that writes files or flushes caches only | /// be locked. Be sure that anything that writes files or flushes caches | ||||
/// does this if the respective module was initialized. | /// only does this if the respective module was initialized. | ||||
RenameThread("bitcoin-shutoff"); | RenameThread("bitcoin-shutoff"); | ||||
g_mempool.AddTransactionsUpdated(1); | g_mempool.AddTransactionsUpdated(1); | ||||
StopHTTPRPC(); | StopHTTPRPC(); | ||||
StopREST(); | StopREST(); | ||||
StopRPC(); | StopRPC(); | ||||
StopHTTPServer(); | StopHTTPServer(); | ||||
g_wallet_init_interface->Flush(); | g_wallet_init_interface->Flush(); | ||||
▲ Show 20 Lines • Show All 2,186 Lines • Show Last 20 Lines |