forked from ShuriZma/suyu
Common::Event: add WaitUntil
This commit is contained in:
parent
51dd13b8a0
commit
2a069e76a5
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -54,6 +55,15 @@ public:
|
||||||
is_set = false;
|
is_set = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Clock, class Duration>
|
||||||
|
bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) {
|
||||||
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
|
if (!condvar.wait_until(lk, time, [this] { return is_set; }))
|
||||||
|
return false;
|
||||||
|
is_set = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Reset() {
|
void Reset() {
|
||||||
std::unique_lock<std::mutex> lk(mutex);
|
std::unique_lock<std::mutex> lk(mutex);
|
||||||
// no other action required, since wait loops on the predicate and any lingering signal will
|
// no other action required, since wait loops on the predicate and any lingering signal will
|
||||||
|
|
Loading…
Reference in New Issue