Skip to content

Commit

Permalink
Merge bitcoin#13235: Break circular dependency: init -> * -> init by …
Browse files Browse the repository at this point in the history
…extracting shutdown.h

1fabd59 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfe Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
  • Loading branch information
laanwj authored and UdjinM6 committed Jul 1, 2021
1 parent d25d155 commit 4cd32e4
Show file tree
Hide file tree
Showing 35 changed files with 90 additions and 90 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ BITCOIN_CORE_H = \
script/sigcache.h \
script/sign.h \
script/standard.h \
shutdown.h \
spork.h \
stacktraces.h \
streams.h \
Expand Down Expand Up @@ -382,6 +383,7 @@ libdash_server_a_SOURCES = \
rpc/coinjoin.cpp \
rpc/util.cpp \
script/sigcache.cpp \
shutdown.cpp \
spork.cpp \
statsd_client.cpp \
timedata.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/coinjoin/coinjoin-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

#include <consensus/validation.h>
#include <core_io.h>
#include <init.h>
#include <evo/deterministicmns.h>
#include <masternode/masternode-sync.h>
#include <masternode/masternode-meta.h>
#include <netmessagemaker.h>
#include <net_processing.h>
#include <script/sign.h>
#include <shutdown.h>
#include <txmempool.h>
#include <util/system.h>
#include <util/moneystr.h>
Expand Down
2 changes: 1 addition & 1 deletion src/coinjoin/coinjoin-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include <evo/deterministicmns.h>
#include <consensus/validation.h>
#include <core_io.h>
#include <init.h>
#include <masternode/masternode-meta.h>
#include <masternode/masternode-sync.h>
#include <net_processing.h>
#include <netmessagemaker.h>
#include <script/interpreter.h>
#include <shutdown.h>
#include <txmempool.h>
#include <util/system.h>
#include <util/moneystr.h>
Expand Down
3 changes: 2 additions & 1 deletion src/dashd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2014-2021 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
Expand All @@ -15,6 +15,7 @@
#include <rpc/server.h>
#include <init.h>
#include <noui.h>
#include <shutdown.h>
#include <util/system.h>
#include <httpserver.h>
#include <httprpc.h>
Expand Down
2 changes: 1 addition & 1 deletion src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include <consensus/validation.h>
#include <governance/governance-classes.h>
#include <governance/governance-validators.h>
#include <init.h>
#include <masternode/masternode-meta.h>
#include <masternode/masternode-sync.h>
#include <net_processing.h>
#include <netfulfilledman.h>
#include <netmessagemaker.h>
#include <protocol.h>
#include <shutdown.h>
#include <spork.h>

#include <evo/deterministicmns.h>
Expand Down
2 changes: 1 addition & 1 deletion src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

#include <httpserver.h>

#include <init.h>
#include <chainparamsbase.h>
#include <compat.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <util/threadnames.h>
#include <netbase.h>
#include <rpc/protocol.h> // For HTTP status codes
#include <shutdown.h>
#include <sync.h>
#include <ui_interface.h>

Expand Down
2 changes: 1 addition & 1 deletion src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <chainparams.h>
#include <index/base.h>
#include <init.h>
#include <shutdown.h>
#include <tinyformat.h>
#include <ui_interface.h>
#include <validation.h>
Expand Down
2 changes: 1 addition & 1 deletion src/index/txindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <index/txindex.h>
#include <init.h>
#include <shutdown.h>
#include <ui_interface.h>
#include <util/system.h>
#include <validation.h>
Expand Down
48 changes: 16 additions & 32 deletions src/init.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2014-2021 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
Expand Down Expand Up @@ -39,7 +39,7 @@
#include <script/standard.h>
#include <script/sigcache.h>
#include <scheduler.h>
#include <util/threadnames.h>
#include <shutdown.h>
#include <timedata.h>
#include <txdb.h>
#include <txmempool.h>
Expand All @@ -49,6 +49,7 @@
#include <util/error.h>
#include <util/moneystr.h>
#include <util/system.h>
#include <util/threadnames.h>
#include <util/validation.h>
#include <validationinterface.h>

Expand Down Expand Up @@ -172,7 +173,7 @@ static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
// created by AppInit() or the Qt main() function.
//
// A clean exit happens when StartShutdown() or the SIGTERM
// signal handler sets fRequestShutdown, which makes main thread's
// signal handler sets ShutdownRequested(), which makes main thread's
// WaitForShutdown() interrupts the thread group.
// And then, WaitForShutdown() makes all other on-going threads
// in the thread group join the main thread.
Expand All @@ -181,26 +182,10 @@ static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
// threads have exited.
//
// Shutdown for Qt is very similar, only it uses a QTimer to detect
// fRequestShutdown getting set, and then does the normal Qt
// ShutdownRequested() getting set, and then does the normal Qt
// shutdown thing.
//

std::atomic<bool> fRequestShutdown(false);
std::atomic<bool> fRequestRestart(false);

void StartShutdown()
{
fRequestShutdown = true;
}
void StartRestart()
{
fRequestShutdown = fRequestRestart = true;
}
bool ShutdownRequested()
{
return fRequestShutdown;
}

/**
* This is a minimally invasive approach to shutdown on LevelDB read errors from the
* chainstate, while keeping user interface out of the common library, which is shared
Expand Down Expand Up @@ -406,7 +391,7 @@ void PrepareShutdown()
void Shutdown()
{
// Shutdown part 1: prepare shutdown
if(!fRequestRestart) {
if(!RestartRequested()) {
PrepareShutdown();
}
// Shutdown part 2: delete wallet instance
Expand All @@ -424,7 +409,7 @@ void Shutdown()
#ifndef WIN32
static void HandleSIGTERM(int)
{
fRequestShutdown = true;
StartShutdown();
}

static void HandleSIGHUP(int)
Expand All @@ -434,7 +419,7 @@ static void HandleSIGHUP(int)
#else
static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType)
{
fRequestShutdown = true;
StartShutdown();
Sleep(INFINITE);
return true;
}
Expand Down Expand Up @@ -943,7 +928,7 @@ static void ThreadImport(std::vector<fs::path> vImportFiles)
if (gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
LoadMempool();
}
g_is_mempool_loaded = !fRequestShutdown;
g_is_mempool_loaded = !ShutdownRequested();
}

void PeriodicStats()
Expand Down Expand Up @@ -2053,7 +2038,7 @@ bool AppInitMain()
bool fLoaded = false;
int64_t nStart = GetTimeMillis();

while (!fLoaded && !fRequestShutdown) {
while (!fLoaded && !ShutdownRequested()) {
bool fReset = fReindex;
std::string strLoadError;

Expand Down Expand Up @@ -2088,7 +2073,7 @@ bool AppInitMain()
CleanupBlockRevFiles();
}

if (fRequestShutdown) break;
if (ShutdownRequested()) break;

// LoadBlockIndex will load fHavePruned if we've ever removed a
// block file from disk.
Expand Down Expand Up @@ -2230,7 +2215,7 @@ bool AppInitMain()
LogPrintf(" block index %15dms\n", GetTimeMillis() - load_block_index_start_time);
} while(false);

if (!fLoaded && !fRequestShutdown) {
if (!fLoaded && !ShutdownRequested()) {
// first suggest a reindex
if (!fReset) {
bool fRet = uiInterface.ThreadSafeQuestion(
Expand All @@ -2239,7 +2224,7 @@ bool AppInitMain()
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
if (fRet) {
fReindex = true;
fRequestShutdown = false;
AbortShutdown();
} else {
LogPrintf("Aborted block database rebuild. Exiting.\n");
return false;
Expand All @@ -2253,8 +2238,7 @@ bool AppInitMain()
// As LoadBlockIndex can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
// As the program has not fully started yet, Shutdown() is possibly overkill.
if (fRequestShutdown)
{
if (ShutdownRequested()) {
LogPrintf("Shutdown requested. Exiting.\n");
return false;
}
Expand All @@ -2277,7 +2261,7 @@ bool AppInitMain()

// As InitLoadWallet can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
if (fRequestShutdown)
if (ShutdownRequested())
{
LogPrintf("Shutdown requested. Exiting.\n");
return false;
Expand All @@ -2298,7 +2282,7 @@ bool AppInitMain()

// As PruneAndFlush can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
if (fRequestShutdown)
if (ShutdownRequested())
{
LogPrintf("Shutdown requested. Exiting.\n");
return false;
Expand Down
5 changes: 1 addition & 4 deletions src/init.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -21,9 +21,6 @@ namespace boost
class thread_group;
} // namespace boost

void StartShutdown();
void StartRestart();
bool ShutdownRequested();
/** Interrupt threads */
void Interrupt();
void Shutdown();
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <primitives/block.h>
#include <rpc/server.h>
#include <scheduler.h>
#include <shutdown.h>
#include <sync.h>
#include <txmempool.h>
#include <ui_interface.h>
Expand Down
1 change: 0 additions & 1 deletion src/llmq/quorums_signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <evo/deterministicmns.h>
#include <masternode/activemasternode.h>
#include <bls/bls_batchverifier.h>
#include <init.h>
#include <net_processing.h>
#include <netmessagemaker.h>
#include <spork.h>
Expand Down
2 changes: 1 addition & 1 deletion src/masternode/masternode-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <governance/governance.h>
#include <init.h>
#include <validation.h>
#include <masternode/masternode-sync.h>
#include <netfulfilledman.h>
#include <netmessagemaker.h>
#include <shutdown.h>
#include <ui_interface.h>
#include <evo/deterministicmns.h>

Expand Down
2 changes: 1 addition & 1 deletion src/masternode/masternode-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#ifdef ENABLE_WALLET
#include <coinjoin/coinjoin-client.h>
#endif
#include <init.h>
#include <masternode/masternode-sync.h>
#include <net.h>
#include <shutdown.h>
#include <validation.h>


Expand Down
1 change: 0 additions & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <chainparams.h>
#include <consensus/validation.h>
#include <hash.h>
#include <init.h>
#include <merkleblock.h>
#include <netmessagemaker.h>
#include <netbase.h>
Expand Down
2 changes: 1 addition & 1 deletion src/netfulfilledman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chainparams.h>
#include <init.h>
#include <netfulfilledman.h>
#include <shutdown.h>
#include <util/system.h>

CNetFulfilledRequestManager netfulfilledman;
Expand Down
1 change: 0 additions & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#endif

#include <chainparams.h>
#include <init.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <ui_interface.h>
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private Q_SLOTS:
/** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */
void toggleHidden();

/** called by a timer to check if fRequestShutdown has been set **/
/** called by a timer to check if ShutdownRequested() has been set **/
void detectShutdown();

/** Show progress dialog e.g. for verifychain */
Expand Down
1 change: 0 additions & 1 deletion src/qt/dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <qt/walletmodel.h>
#endif

#include <init.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <rpc/server.h>
Expand Down
1 change: 0 additions & 1 deletion src/qt/signverifymessagedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <qt/guiutil.h>
#include <qt/walletmodel.h>

#include <init.h>
#include <key_io.h>
#include <util/strencodings.h>
#include <util/validation.h> // For strMessageMagic
Expand Down
1 change: 0 additions & 1 deletion src/qt/splashscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <chainparams.h>
#include <clientversion.h>
#include <init.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>
Expand Down
2 changes: 1 addition & 1 deletion src/qt/winshutdownmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <qt/winshutdownmonitor.h>

#if defined(Q_OS_WIN)
#include <init.h>
#include <shutdown.h>
#include <util/system.h>

#include <windows.h>
Expand Down
Loading

0 comments on commit 4cd32e4

Please sign in to comment.