diff options
Diffstat (limited to '')
| -rw-r--r-- | src/common/thread.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/common/thread.h b/src/common/thread.h index 9c08be7e3..fa475ab51 100644 --- a/src/common/thread.h +++ b/src/common/thread.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <chrono> | ||
| 7 | #include <condition_variable> | 8 | #include <condition_variable> |
| 8 | #include <cstddef> | 9 | #include <cstddef> |
| 9 | #include <mutex> | 10 | #include <mutex> |
| @@ -54,6 +55,15 @@ public: | |||
| 54 | is_set = false; | 55 | is_set = false; |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 58 | template <class Clock, class Duration> | ||
| 59 | bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { | ||
| 60 | std::unique_lock<std::mutex> lk(mutex); | ||
| 61 | if (!condvar.wait_until(lk, time, [this] { return is_set; })) | ||
| 62 | return false; | ||
| 63 | is_set = false; | ||
| 64 | return true; | ||
| 65 | } | ||
| 66 | |||
| 57 | void Reset() { | 67 | void Reset() { |
| 58 | std::unique_lock<std::mutex> lk(mutex); | 68 | std::unique_lock<std::mutex> lk(mutex); |
| 59 | // no other action required, since wait loops on the predicate and any lingering signal will | 69 | // no other action required, since wait loops on the predicate and any lingering signal will |