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:
parent
7248700b33
commit
f28a58e0a9
12
src/init.cpp
12
src/init.cpp
@ -92,7 +92,6 @@
|
|||||||
extern void ThreadSendAlert(CConnman& connman);
|
extern void ThreadSendAlert(CConnman& connman);
|
||||||
|
|
||||||
bool fFeeEstimatesInitialized = false;
|
bool fFeeEstimatesInitialized = false;
|
||||||
bool fRestartRequested = false; // true: restart false: shutdown
|
|
||||||
static const bool DEFAULT_PROXYRANDOMIZE = true;
|
static const bool DEFAULT_PROXYRANDOMIZE = true;
|
||||||
static const bool DEFAULT_REST_ENABLE = false;
|
static const bool DEFAULT_REST_ENABLE = false;
|
||||||
static const bool DEFAULT_DISABLE_SAFEMODE = 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> fRequestShutdown(false);
|
||||||
|
std::atomic<bool> fRequestRestart(false);
|
||||||
std::atomic<bool> fDumpMempoolLater(false);
|
std::atomic<bool> fDumpMempoolLater(false);
|
||||||
|
|
||||||
void StartShutdown()
|
void StartShutdown()
|
||||||
{
|
{
|
||||||
fRequestShutdown = true;
|
fRequestShutdown = true;
|
||||||
}
|
}
|
||||||
|
void StartRestart()
|
||||||
|
{
|
||||||
|
fRequestShutdown = fRequestRestart = true;
|
||||||
|
}
|
||||||
bool ShutdownRequested()
|
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 */
|
/** Preparing steps before shutting down or restarting the wallet */
|
||||||
void PrepareShutdown()
|
void PrepareShutdown()
|
||||||
{
|
{
|
||||||
fRequestShutdown = true; // Needed when we shutdown the wallet
|
|
||||||
fRestartRequested = true; // Needed when we restart the wallet
|
|
||||||
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);
|
||||||
@ -319,7 +321,7 @@ void PrepareShutdown()
|
|||||||
void Shutdown()
|
void Shutdown()
|
||||||
{
|
{
|
||||||
// Shutdown part 1: prepare shutdown
|
// Shutdown part 1: prepare shutdown
|
||||||
if(!fRestartRequested){
|
if(!fRequestRestart) {
|
||||||
PrepareShutdown();
|
PrepareShutdown();
|
||||||
}
|
}
|
||||||
// Shutdown part 2: Stop TOR thread and delete wallet instance
|
// Shutdown part 2: Stop TOR thread and delete wallet instance
|
||||||
|
@ -17,6 +17,7 @@ class thread_group;
|
|||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
void StartShutdown();
|
void StartShutdown();
|
||||||
|
void StartRestart();
|
||||||
bool ShutdownRequested();
|
bool ShutdownRequested();
|
||||||
/** Interrupt threads */
|
/** Interrupt threads */
|
||||||
void Interrupt(boost::thread_group& threadGroup);
|
void Interrupt(boost::thread_group& threadGroup);
|
||||||
|
@ -191,9 +191,6 @@ private:
|
|||||||
boost::thread_group threadGroup;
|
boost::thread_group threadGroup;
|
||||||
CScheduler scheduler;
|
CScheduler scheduler;
|
||||||
|
|
||||||
/// Flag indicating a restart
|
|
||||||
bool execute_restart;
|
|
||||||
|
|
||||||
/// Pass fatal exception message to UI thread
|
/// Pass fatal exception message to UI thread
|
||||||
void handleRunawayException(const std::exception *e);
|
void handleRunawayException(const std::exception *e);
|
||||||
};
|
};
|
||||||
@ -275,8 +272,6 @@ void BitcoinCore::handleRunawayException(const std::exception *e)
|
|||||||
|
|
||||||
void BitcoinCore::initialize()
|
void BitcoinCore::initialize()
|
||||||
{
|
{
|
||||||
execute_restart = true;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
qDebug() << __func__ << ": Running AppInit2 in thread";
|
qDebug() << __func__ << ": Running AppInit2 in thread";
|
||||||
@ -306,13 +301,16 @@ void BitcoinCore::initialize()
|
|||||||
|
|
||||||
void BitcoinCore::restart(QStringList args)
|
void BitcoinCore::restart(QStringList args)
|
||||||
{
|
{
|
||||||
if(execute_restart) { // Only restart 1x, no matter how often a user clicks on a restart-button
|
static bool executing_restart{false};
|
||||||
execute_restart = false;
|
|
||||||
|
if(!executing_restart) { // Only restart 1x, no matter how often a user clicks on a restart-button
|
||||||
|
executing_restart = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
qDebug() << __func__ << ": Running Restart in thread";
|
qDebug() << __func__ << ": Running Restart in thread";
|
||||||
threadGroup.interrupt_all();
|
Interrupt(threadGroup);
|
||||||
threadGroup.join_all();
|
threadGroup.join_all();
|
||||||
|
StartRestart();
|
||||||
PrepareShutdown();
|
PrepareShutdown();
|
||||||
qDebug() << __func__ << ": Shutdown finished";
|
qDebug() << __func__ << ": Shutdown finished";
|
||||||
Q_EMIT shutdownResult(1);
|
Q_EMIT shutdownResult(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user