aboutsummaryrefslogtreecommitdiff
path: root/src/shutdown.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-12-16 16:40:42 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-12-16 16:43:51 +0100
commit3f205808a5f20c9398d8e74b7e83220a129acc7d (patch)
treea9bcd69823f9b283939a798da3003cbd1c58e573 /src/shutdown.h
parent9dbcd37105212d0fa7a1f0657e31de013fd93a16 (diff)
parentcd03513dc2fcccaa142e9632a28b38efd0056436 (diff)
Merge #20605: init: Signal-safe instant shutdown
cd03513dc2fcccaa142e9632a28b38efd0056436 init: Signal-safe instant shutdown (Wladimir J. van der Laan) Pull request description: Replace the 200ms polling loop with a faster and more efficient waiting operation. This should speed up short RPC tests. This change has been tried a few times before, but abandoned every time because solutions used a condition variable which is not safe for use in signals, as they need to be reentrant. On UNIX-ish OSes, use a safe way: a pipe. When shutdown is requested write a dummy byte to the pipe. Waiting for shutdown is a matter of a blocking read from the pipe. On Windows, there are no signals so using a condition variable is safe. This only affects bitcoind. The GUI is unaffected by this change, and keeps polling as before in `BitcoinGUI::detectShutdown()`. It might be possible to listen to a pipe there, too, but I'm not sure, and it's complicated by the GUI-node abstraction. ACKs for top commit: jonatack: ACK cd03513dc2fcccaa142e9632a28b38efd0056436 tested on Debian 5.9.11-1 (2020-11-27) x86_64 GNU/Linux Tree-SHA512: ed2f532f69fec4855c17bf7b8f3d0eb96e78ee2a3c13d374dd2c6add06e3ad6a190da8ed8f9d7a76532cf998222d67f57e35b206aec29675e96437448ae7e13c
Diffstat (limited to 'src/shutdown.h')
-rw-r--r--src/shutdown.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/shutdown.h b/src/shutdown.h
index 3ed851c789..23f84179e9 100644
--- a/src/shutdown.h
+++ b/src/shutdown.h
@@ -6,8 +6,25 @@
#ifndef BITCOIN_SHUTDOWN_H
#define BITCOIN_SHUTDOWN_H
+/** Initialize shutdown state. This must be called before using either StartShutdown(),
+ * AbortShutdown() or WaitForShutdown(). Calling ShutdownRequested() is always safe.
+ */
+bool InitShutdownState();
+
+/** Request shutdown of the application. */
void StartShutdown();
+
+/** Clear shutdown flag. Only use this during init (before calling WaitForShutdown in any
+ * thread), or in the unit tests. Calling it in other circumstances will cause a race condition.
+ */
void AbortShutdown();
+
+/** Returns true if a shutdown is requested, false otherwise. */
bool ShutdownRequested();
+/** Wait for StartShutdown to be called in any thread. This can only be used
+ * from a single thread.
+ */
+void WaitForShutdown();
+
#endif