diff --git a/src/init.cpp b/src/init.cpp index fe6a1bfb9..6d99d0429 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -92,7 +92,6 @@ extern void ThreadSendAlert(CConnman& connman); bool fFeeEstimatesInitialized = false; -bool fRestartRequested = false; // true: restart false: shutdown static const bool DEFAULT_PROXYRANDOMIZE = true; static const bool DEFAULT_REST_ENABLE = false; static const bool DEFAULT_DISABLE_SAFEMODE = false; @@ -158,15 +157,20 @@ static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat"; // std::atomic fRequestShutdown(false); +std::atomic fRequestRestart(false); std::atomic fDumpMempoolLater(false); void StartShutdown() { fRequestShutdown = true; } +void StartRestart() +{ + fRequestShutdown = fRequestRestart = true; +} bool ShutdownRequested() { - return fRequestShutdown || fRestartRequested; + return fRequestShutdown; } /** @@ -212,8 +216,6 @@ void Interrupt(boost::thread_group& threadGroup) /** Preparing steps before shutting down or restarting the wallet */ void PrepareShutdown() { - fRequestShutdown = true; // Needed when we shutdown the wallet - fRestartRequested = true; // Needed when we restart the wallet LogPrintf("%s: In progress...\n", __func__); static CCriticalSection cs_Shutdown; TRY_LOCK(cs_Shutdown, lockShutdown); @@ -319,7 +321,7 @@ void PrepareShutdown() void Shutdown() { // Shutdown part 1: prepare shutdown - if(!fRestartRequested){ + if(!fRequestRestart) { PrepareShutdown(); } // Shutdown part 2: Stop TOR thread and delete wallet instance diff --git a/src/init.h b/src/init.h index 64bc99a7b..0706895f3 100644 --- a/src/init.h +++ b/src/init.h @@ -17,6 +17,7 @@ class thread_group; } // namespace boost void StartShutdown(); +void StartRestart(); bool ShutdownRequested(); /** Interrupt threads */ void Interrupt(boost::thread_group& threadGroup); diff --git a/src/qt/dash.cpp b/src/qt/dash.cpp index 9166ea070..5b08ca36e 100644 --- a/src/qt/dash.cpp +++ b/src/qt/dash.cpp @@ -191,9 +191,6 @@ private: boost::thread_group threadGroup; CScheduler scheduler; - /// Flag indicating a restart - bool execute_restart; - /// Pass fatal exception message to UI thread void handleRunawayException(const std::exception *e); }; @@ -275,8 +272,6 @@ void BitcoinCore::handleRunawayException(const std::exception *e) void BitcoinCore::initialize() { - execute_restart = true; - try { qDebug() << __func__ << ": Running AppInit2 in thread"; @@ -306,13 +301,16 @@ void BitcoinCore::initialize() void BitcoinCore::restart(QStringList args) { - if(execute_restart) { // Only restart 1x, no matter how often a user clicks on a restart-button - execute_restart = false; + static bool executing_restart{false}; + + if(!executing_restart) { // Only restart 1x, no matter how often a user clicks on a restart-button + executing_restart = true; try { qDebug() << __func__ << ": Running Restart in thread"; - threadGroup.interrupt_all(); + Interrupt(threadGroup); threadGroup.join_all(); + StartRestart(); PrepareShutdown(); qDebug() << __func__ << ": Shutdown finished"; Q_EMIT shutdownResult(1);