summaryrefslogtreecommitdiffstats
path: root/src/common/thread.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2017-01-07 18:39:20 +0100
committerGitHub <noreply@github.com>2017-01-07 18:39:20 +0100
commit7cfe3ef0463ace034b1e5786c9581cfa5f2e810c (patch)
tree6b06cb03d276b29070ca29599fc4c5fcf77edb39 /src/common/thread.h
parentMerge pull request #2410 from Subv/sleepthread (diff)
parentFrontend: make motion sensor interfaced thread-safe (diff)
downloadyuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar
yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar.gz
yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar.bz2
yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar.lz
yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar.xz
yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar.zst
yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.zip
Diffstat (limited to 'src/common/thread.h')
-rw-r--r--src/common/thread.h10
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 @@
#pragma once
+#include <chrono>
#include <condition_variable>
#include <cstddef>
#include <mutex>
@@ -54,6 +55,15 @@ public:
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() {
std::unique_lock<std::mutex> lk(mutex);
// no other action required, since wait loops on the predicate and any lingering signal will