Refactor and fix restart (#1999)

* Refactor restart

* Correctly interrupt all threads on restart

Fixes the issue with restart when running with `-server`
This commit is contained in:
UdjinM6 2018-03-19 16:09:47 +03:00 committed by GitHub
parent 7248700b33
commit f28a58e0a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 13 deletions

View File

@ -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<bool> fRequestShutdown(false);
std::atomic<bool> fRequestRestart(false);
std::atomic<bool> 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

View File

@ -17,6 +17,7 @@ class thread_group;
} // namespace boost
void StartShutdown();
void StartRestart();
bool ShutdownRequested();
/** Interrupt threads */
void Interrupt(boost::thread_group& threadGroup);

View File

@ -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);