Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2023-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_UTIL_SIGNALINTERRUPT_H6#define BITCOIN_UTIL_SIGNALINTERRUPT_H8#ifdef WIN329#include <condition_variable>10#include <mutex>11#else12#include <util/tokenpipe.h>13#endif15#include <atomic>17namespace util {18/**19* Helper class that manages an interrupt flag, and allows a thread or20* signal to interrupt another thread.21*22* This class is safe to be used in a signal handler. If sending an interrupt23* from a signal handler is not necessary, the more lightweight \ref24* CThreadInterrupt class can be used instead.25*/27class SignalInterrupt28{29public:30SignalInterrupt();31explicit operator bool() const;32[[nodiscard]] bool operator()();33[[nodiscard]] bool reset();34[[nodiscard]] bool wait();36private:37std::atomic<bool> m_flag;39#ifndef WIN3240// On UNIX-like operating systems use the self-pipe trick.41TokenPipeEnd m_pipe_r;42TokenPipeEnd m_pipe_w;43#else44// On windows use a condition variable, since we don't have any signals there45std::mutex m_mutex;46std::condition_variable m_cv;47#endif48};49} // namespace util51#endif // BITCOIN_UTIL_SIGNALINTERRUPT_H