BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
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 BITCOIN_THREADINTERRUPT_H
6 #define BITCOIN_THREADINTERRUPT_H
7 
8 #include <sync.h>
9 
10 #include <atomic>
11 #include <chrono>
12 #include <condition_variable>
13 #include <mutex>
14 
15 /*
16  A helper class for interruptible sleeps. Calling operator() will interrupt
17  any current sleep, and after that point operator bool() will return true
18  until reset.
19 */
21 {
22 public:
24  explicit operator bool() const;
25  void operator()();
26  void reset();
27  bool sleep_for(std::chrono::milliseconds rel_time);
28  bool sleep_for(std::chrono::seconds rel_time);
29  bool sleep_for(std::chrono::minutes rel_time);
30 
31 private:
32  std::condition_variable cond;
34  std::atomic<bool> flag;
35 };
36 
37 #endif //BITCOIN_THREADINTERRUPT_H
bool sleep_for(std::chrono::milliseconds rel_time)
std::condition_variable cond
std::atomic< bool > flag