mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-15 22:32:37 -03:00
cd03513dc2
Replace the 200ms polling loop with a faster and more efficient waiting operation. This was tried a few times before, but given up every time because solutions use 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.
30 lines
1,009 B
C
30 lines
1,009 B
C
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// 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.
|
|
|
|
#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
|