scripted-diff: various renames for per-utxo consistency
[bitcoinplatinum.git] / src / threadinterrupt.h
blob54e31028089f2031178739aa3792289ed30aaa00
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.
5 #ifndef BITCOIN_THREADINTERRUPT_H
6 #define BITCOIN_THREADINTERRUPT_H
8 #include <atomic>
9 #include <chrono>
10 #include <condition_variable>
11 #include <mutex>
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.
18 class CThreadInterrupt
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);
28 private:
29 std::condition_variable cond;
30 std::mutex mut;
31 std::atomic<bool> flag;
34 #endif //BITCOIN_THREADINTERRUPT_H