Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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
21public:
23 explicit operator bool() const;
25 void reset();
26 bool sleep_for(std::chrono::milliseconds rel_time)
28 bool sleep_for(std::chrono::seconds rel_time)
30 bool sleep_for(std::chrono::minutes rel_time)
32
33private:
34 std::condition_variable cond;
36 std::atomic<bool> flag;
37};
38
39#endif // BITCOIN_THREADINTERRUPT_H
A helper class for interruptible sleeps.
void operator()() EXCLUSIVE_LOCKS_REQUIRED(!mut)
std::atomic< bool > flag
bool sleep_for(std::chrono::milliseconds rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut)
std::condition_variable cond
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
#define EXCLUSIVE_LOCKS_REQUIRED(...)