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