From 2a069e76a5093db44a87732edb72a1bb2b771e61 Mon Sep 17 00:00:00 2001 From: wwylele Date: Sun, 11 Dec 2016 23:26:23 +0200 Subject: Common::Event: add WaitUntil --- src/common/thread.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') 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 @@ #pragma once +#include #include #include #include @@ -54,6 +55,15 @@ public: is_set = false; } + template + bool WaitUntil(const std::chrono::time_point& time) { + std::unique_lock lk(mutex); + if (!condvar.wait_until(lk, time, [this] { return is_set; })) + return false; + is_set = false; + return true; + } + void Reset() { std::unique_lock lk(mutex); // no other action required, since wait loops on the predicate and any lingering signal will -- cgit v1.2.3