Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

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 <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 //BITCOIN_THREADINTERRUPT_H
bool sleep_for(std::chrono::milliseconds rel_time)
std::condition_variable cond
std::atomic< bool > flag
Released under the MIT license