Bitcoin Core
28.99.0
P2P Digital Currency
src
util
signalinterrupt.h
Go to the documentation of this file.
1
// Copyright (c) 2023 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_UTIL_SIGNALINTERRUPT_H
6
#define BITCOIN_UTIL_SIGNALINTERRUPT_H
7
8
#ifdef WIN32
9
#include <condition_variable>
10
#include <mutex>
11
#else
12
#include <
util/tokenpipe.h
>
13
#endif
14
15
#include <atomic>
16
#include <cstdlib>
17
18
namespace
util
{
28
class
SignalInterrupt
29
{
30
public
:
31
SignalInterrupt
();
32
explicit
operator
bool()
const
;
33
[[nodiscard]]
bool
operator()
();
34
[[nodiscard]]
bool
reset
();
35
[[nodiscard]]
bool
wait
();
36
37
private
:
38
std::atomic<bool>
m_flag
;
39
40
#ifndef WIN32
41
// On UNIX-like operating systems use the self-pipe trick.
42
TokenPipeEnd
m_pipe_r
;
43
TokenPipeEnd
m_pipe_w
;
44
#else
45
// On windows use a condition variable, since we don't have any signals there
46
std::mutex m_mutex;
47
std::condition_variable m_cv;
48
#endif
49
};
50
}
// namespace util
51
52
#endif
// BITCOIN_UTIL_SIGNALINTERRUPT_H
TokenPipeEnd
One end of a token pipe.
Definition:
tokenpipe.h:15
util::SignalInterrupt
Helper class that manages an interrupt flag, and allows a thread or signal to interrupt another threa...
Definition:
signalinterrupt.h:29
util::SignalInterrupt::reset
bool reset()
Definition:
signalinterrupt.cpp:33
util::SignalInterrupt::m_pipe_r
TokenPipeEnd m_pipe_r
Definition:
signalinterrupt.h:42
util::SignalInterrupt::m_flag
std::atomic< bool > m_flag
Definition:
signalinterrupt.h:38
util::SignalInterrupt::SignalInterrupt
SignalInterrupt()
Definition:
signalinterrupt.cpp:18
util::SignalInterrupt::m_pipe_w
TokenPipeEnd m_pipe_w
Definition:
signalinterrupt.h:43
util::SignalInterrupt::operator()
bool operator()()
Definition:
signalinterrupt.cpp:42
util::SignalInterrupt::wait
bool wait()
Definition:
signalinterrupt.cpp:63
util
Definition:
httpserver.h:13
tokenpipe.h
Generated on Wed Dec 18 2024 20:00:14 for Bitcoin Core by
1.9.4