mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Replace exceptions thrown by signal and wait methods with [[nodiscard]] return values. This is mostly a refactoring, but there is a slight change of behavior if AbortShutdown function fails. The original behavior which was unintentionally changed in #27861 is restored, so it now triggers an assert failure again instead of throwing an exception. (The AbortShutdown function is only ever called in the the GUI version of Bitcoin Core when corruption is detected on loading and the user tries to reindex.) Problems with using exceptions were pointed out by MarcoFalke in https://github.com/bitcoin/bitcoin/pull/27861#discussion_r1255496707.
44 lines
980 B
C++
44 lines
980 B
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2022 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <shutdown.h>
|
|
|
|
#include <kernel/context.h>
|
|
#include <logging.h>
|
|
#include <util/check.h>
|
|
#include <util/signalinterrupt.h>
|
|
|
|
#include <assert.h>
|
|
#include <system_error>
|
|
|
|
void StartShutdown()
|
|
{
|
|
if (!Assert(kernel::g_context)->interrupt()) {
|
|
LogPrintf("Sending shutdown token failed\n");
|
|
assert(0);
|
|
}
|
|
}
|
|
|
|
void AbortShutdown()
|
|
{
|
|
if (!Assert(kernel::g_context)->interrupt.reset()) {
|
|
LogPrintf("Reading shutdown token failed\n");
|
|
assert(0);
|
|
}
|
|
}
|
|
|
|
bool ShutdownRequested()
|
|
{
|
|
return bool{Assert(kernel::g_context)->interrupt};
|
|
}
|
|
|
|
void WaitForShutdown()
|
|
{
|
|
if (!Assert(kernel::g_context)->interrupt.wait()) {
|
|
LogPrintf("Reading shutdown token failed\n");
|
|
assert(0);
|
|
}
|
|
}
|