Changeset View
Changeset View
Standalone View
Standalone View
src/threadinterrupt.h
Show All 13 Lines | |||||
/** | /** | ||||
* A helper class for interruptible sleeps. Calling operator() will interrupt | * A helper class for interruptible sleeps. Calling operator() will interrupt | ||||
* any current sleep, and after that point operator bool() will return true | * any current sleep, and after that point operator bool() will return true | ||||
* until reset. | * until reset. | ||||
*/ | */ | ||||
class CThreadInterrupt { | class CThreadInterrupt { | ||||
public: | public: | ||||
CThreadInterrupt(); | |||||
explicit operator bool() const; | explicit operator bool() const; | ||||
void operator()(); | void operator()(); | ||||
void reset(); | void reset(); | ||||
bool sleep_for(std::chrono::milliseconds rel_time); | bool sleep_for(std::chrono::milliseconds rel_time); | ||||
bool sleep_for(std::chrono::seconds rel_time); | bool sleep_for(std::chrono::seconds rel_time); | ||||
bool sleep_for(std::chrono::minutes rel_time); | bool sleep_for(std::chrono::minutes rel_time); | ||||
private: | private: | ||||
std::condition_variable cond; | std::condition_variable cond; | ||||
CWaitableCriticalSection mut; | CWaitableCriticalSection mut; | ||||
std::atomic<bool> flag; | std::atomic<bool> flag; | ||||
}; | }; | ||||
#endif // BITCOIN_THREADINTERRUPT_H | #endif // BITCOIN_THREADINTERRUPT_H |