2018-05-16 19:17:40 +00:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2009-2022 The Bitcoin Core developers
|
2018-05-16 19:17:40 +00:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <shutdown.h>
|
|
|
|
|
2023-06-01 16:53:33 -04:00
|
|
|
#include <kernel/context.h>
|
2021-01-26 19:34:47 +01:00
|
|
|
#include <logging.h>
|
2023-05-20 10:51:17 -03:00
|
|
|
#include <util/check.h>
|
2023-06-01 16:53:33 -04:00
|
|
|
#include <util/signalinterrupt.h>
|
2023-05-20 10:51:17 -03:00
|
|
|
|
2023-05-09 11:15:46 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <system_error>
|
2018-05-16 19:17:40 +00:00
|
|
|
|
|
|
|
void StartShutdown()
|
|
|
|
{
|
2023-06-01 16:53:33 -04:00
|
|
|
try {
|
|
|
|
Assert(kernel::g_context)->interrupt();
|
|
|
|
} catch (const std::system_error&) {
|
|
|
|
LogPrintf("Sending shutdown token failed\n");
|
|
|
|
assert(0);
|
2020-12-08 21:49:06 +01:00
|
|
|
}
|
2018-05-16 19:17:40 +00:00
|
|
|
}
|
2020-12-08 21:49:06 +01:00
|
|
|
|
2018-05-16 19:17:40 +00:00
|
|
|
void AbortShutdown()
|
|
|
|
{
|
2023-06-01 16:53:33 -04:00
|
|
|
Assert(kernel::g_context)->interrupt.reset();
|
2018-05-16 19:17:40 +00:00
|
|
|
}
|
2020-12-08 21:49:06 +01:00
|
|
|
|
2018-05-16 19:17:40 +00:00
|
|
|
bool ShutdownRequested()
|
|
|
|
{
|
2023-06-01 16:53:33 -04:00
|
|
|
return bool{Assert(kernel::g_context)->interrupt};
|
2018-05-16 19:17:40 +00:00
|
|
|
}
|
2020-12-08 21:49:06 +01:00
|
|
|
|
|
|
|
void WaitForShutdown()
|
|
|
|
{
|
2023-06-01 16:53:33 -04:00
|
|
|
try {
|
|
|
|
Assert(kernel::g_context)->interrupt.wait();
|
|
|
|
} catch (const std::system_error&) {
|
2021-01-26 19:34:47 +01:00
|
|
|
LogPrintf("Reading shutdown token failed\n");
|
|
|
|
assert(0);
|
2020-12-08 21:49:06 +01:00
|
|
|
}
|
|
|
|
}
|