Raven Core  3.0.0
P2P Digital Currency
threadinterrupt.h
Go to the documentation of this file.
1 // Copyright (c) 2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef RAVEN_THREADINTERRUPT_H
7 #define RAVEN_THREADINTERRUPT_H
8 
9 #include <atomic>
10 #include <chrono>
11 #include <condition_variable>
12 #include <mutex>
13 
14 /*
15  A helper class for interruptible sleeps. Calling operator() will interrupt
16  any current sleep, and after that point operator bool() will return true
17  until reset.
18 */
20 {
21 public:
22  explicit operator bool() const;
23  void operator()();
24  void reset();
25  bool sleep_for(std::chrono::milliseconds rel_time);
26  bool sleep_for(std::chrono::seconds rel_time);
27  bool sleep_for(std::chrono::minutes rel_time);
28 
29 private:
30  std::condition_variable cond;
31  std::mutex mut;
32  std::atomic<bool> flag;
33 };
34 
35 #endif //RAVEN_THREADINTERRUPT_H
bool sleep_for(std::chrono::milliseconds rel_time)
std::condition_variable cond
std::atomic< bool > flag