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
10 #include <condition_variable>
14 A helper class for interruptible sleeps. Calling operator() will interrupt
15 any current sleep, and after that point operator bool() will return true
18 class CThreadInterrupt
21 explicit operator bool() const;
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
);
29 std::condition_variable cond
;
31 std::atomic
<bool> flag
;
34 #endif //BITCOIN_THREADINTERRUPT_H