diff options
Diffstat (limited to 'src/common/thread.h')
| -rw-r--r-- | src/common/thread.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/common/thread.h b/src/common/thread.h index 0cfd98be6..2fc071685 100644 --- a/src/common/thread.h +++ b/src/common/thread.h | |||
| @@ -28,6 +28,15 @@ public: | |||
| 28 | is_set = false; | 28 | is_set = false; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | template <class Duration> | ||
| 32 | bool WaitFor(const std::chrono::duration<Duration>& time) { | ||
| 33 | std::unique_lock lk{mutex}; | ||
| 34 | if (!condvar.wait_for(lk, time, [this] { return is_set; })) | ||
| 35 | return false; | ||
| 36 | is_set = false; | ||
| 37 | return true; | ||
| 38 | } | ||
| 39 | |||
| 31 | template <class Clock, class Duration> | 40 | template <class Clock, class Duration> |
| 32 | bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { | 41 | bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { |
| 33 | std::unique_lock lk{mutex}; | 42 | std::unique_lock lk{mutex}; |