Fabcoin Core  0.16.2
P2P Digital Currency
threadinterrupt.h
Go to the documentation of this file.
1 // Copyright (c)2016-2017 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 FABCOIN_THREADINTERRUPT_H
6 #define FABCOIN_THREADINTERRUPT_H
7 
8 #include <atomic>
9 #include <chrono>
10 #include <condition_variable>
11 #include <mutex>
12 
13 /*
14  A helper class for interruptible sleeps. Calling operator() will interrupt
15  any current sleep, and after that point operator bool() will return true
16  until reset.
17 */
19 {
20 public:
21  explicit operator bool() const;
22  void operator()();
23  void reset();
24  bool sleep_for(std::chrono::milliseconds rel_time);
25  bool sleep_for(std::chrono::seconds rel_time);
26  bool sleep_for(std::chrono::minutes rel_time);
27 
28 private:
29  std::condition_variable cond;
30  std::mutex mut;
31  std::atomic<bool> flag;
32 };
33 
34 #endif //FABCOIN_THREADINTERRUPT_H
bool sleep_for(std::chrono::milliseconds rel_time)
std::condition_variable cond
std::atomic< bool > flag