Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
util
threadinterrupt.h
Go to the documentation of this file.
1
// Copyright (c) 2016-present 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_THREADINTERRUPT_H
6
#define BITCOIN_UTIL_THREADINTERRUPT_H
7
8
#include <
sync.h
>
9
#include <
threadsafety.h
>
10
11
#include <atomic>
12
#include <chrono>
13
#include <condition_variable>
14
25
26
class
CThreadInterrupt
27
{
28
public
:
29
using
Clock
= std::chrono::steady_clock;
30
31
CThreadInterrupt
();
32
33
virtual
~CThreadInterrupt
() =
default
;
34
36
virtual
bool
interrupted
()
const
;
37
39
virtual
explicit
operator
bool()
const
;
40
42
virtual
void
operator()
()
EXCLUSIVE_LOCKS_REQUIRED
(!
mut
);
43
45
virtual
void
reset
();
46
50
virtual
bool
sleep_for
(
Clock
::duration rel_time)
EXCLUSIVE_LOCKS_REQUIRED
(!
mut
);
51
52
private:
53
std
::condition_variable
cond
;
54
Mutex
mut
;
55
std
::atomic<
bool
>
flag
;
56
};
57
58
#endif
// BITCOIN_UTIL_THREADINTERRUPT_H
CThreadInterrupt::Clock
std::chrono::steady_clock Clock
Definition
threadinterrupt.h:29
CThreadInterrupt::operator()
virtual void operator()() EXCLUSIVE_LOCKS_REQUIRED(!mut)
Interrupt any sleeps. After this interrupted() will return true.
Definition
threadinterrupt.cpp:27
CThreadInterrupt::reset
virtual void reset()
Reset to an non-interrupted state.
Definition
threadinterrupt.cpp:22
CThreadInterrupt::flag
std::atomic< bool > flag
Definition
threadinterrupt.h:55
CThreadInterrupt::mut
Mutex mut
Definition
threadinterrupt.h:54
CThreadInterrupt::sleep_for
virtual bool sleep_for(Clock::duration rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut)
Sleep for the given duration.
Definition
threadinterrupt.cpp:36
CThreadInterrupt::interrupted
virtual bool interrupted() const
Return true if operator()() has been called.
Definition
threadinterrupt.cpp:12
CThreadInterrupt::cond
std::condition_variable cond
Definition
threadinterrupt.h:53
CThreadInterrupt::~CThreadInterrupt
virtual ~CThreadInterrupt()=default
CThreadInterrupt::CThreadInterrupt
CThreadInterrupt()
Definition
threadinterrupt.cpp:10
std
Definition
common.h:29
sync.h
Mutex
AnnotatedMixin< std::mutex > Mutex
Wrapped mutex: supports waiting but not recursive locking.
Definition
sync.h:123
threadsafety.h
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition
threadsafety.h:51
Generated on
for Bitcoin Core by
1.17.0