Bitcoin ABC
0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
src
threadinterrupt.h
Go to the documentation of this file.
1
// Copyright (c) 2016 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_THREADINTERRUPT_H
6
#define BITCOIN_THREADINTERRUPT_H
7
8
#include <
sync.h
>
9
#include <
threadsafety.h
>
10
11
#include <atomic>
12
#include <chrono>
13
#include <condition_variable>
14
20
class
CThreadInterrupt
{
21
public
:
22
CThreadInterrupt
();
23
explicit
operator
bool
()
const
;
24
void
operator()
()
EXCLUSIVE_LOCKS_REQUIRED
(!
mut
);
25
void
reset
();
26
bool
sleep_for
(std::chrono::milliseconds
rel_time
)
27
EXCLUSIVE_LOCKS_REQUIRED
(!
mut
);
28
bool
sleep_for
(std::chrono::seconds
rel_time
)
29
EXCLUSIVE_LOCKS_REQUIRED
(!
mut
);
30
bool
sleep_for
(std::chrono::minutes
rel_time
)
31
EXCLUSIVE_LOCKS_REQUIRED
(!
mut
);
32
33
private
:
34
std::condition_variable
cond
;
35
Mutex
mut
;
36
std::atomic<bool>
flag
;
37
};
38
39
#endif
// BITCOIN_THREADINTERRUPT_H
AnnotatedMixin< std::mutex >
CThreadInterrupt
A helper class for interruptible sleeps.
Definition
threadinterrupt.h:20
CThreadInterrupt::operator()
void operator()() EXCLUSIVE_LOCKS_REQUIRED(!mut)
Definition
threadinterrupt.cpp:18
CThreadInterrupt::reset
void reset()
Definition
threadinterrupt.cpp:14
CThreadInterrupt::flag
std::atomic< bool > flag
Definition
threadinterrupt.h:36
CThreadInterrupt::mut
Mutex mut
Definition
threadinterrupt.h:35
CThreadInterrupt::sleep_for
bool sleep_for(std::chrono::milliseconds rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut)
Definition
threadinterrupt.cpp:26
CThreadInterrupt::cond
std::condition_variable cond
Definition
threadinterrupt.h:34
CThreadInterrupt::CThreadInterrupt
CThreadInterrupt()
Definition
threadinterrupt.cpp:8
GetRand
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition
random.h:85
sync.h
threadsafety.h
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition
threadsafety.h:56
Generated on Fri Nov 22 2024 02:38:24 for Bitcoin ABC by
1.9.8