summaryrefslogtreecommitdiff
path: root/src/thread/PosixCond.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread/PosixCond.hxx')
-rw-r--r--src/thread/PosixCond.hxx13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/thread/PosixCond.hxx b/src/thread/PosixCond.hxx
index 4e1988ece..2428aa5c7 100644
--- a/src/thread/PosixCond.hxx
+++ b/src/thread/PosixCond.hxx
@@ -32,6 +32,8 @@
#include "PosixMutex.hxx"
+#include <chrono>
+
#include <sys/time.h>
/**
@@ -87,6 +89,17 @@ public:
return pthread_cond_timedwait(&cond, &mutex.mutex, &ts) == 0;
}
+
+ bool timed_wait(PosixMutex &mutex,
+ std::chrono::steady_clock::duration timeout) {
+ auto timeout_ms = std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count();
+ if (timeout_ms < 0)
+ timeout_ms = 0;
+ else if (timeout_ms > std::numeric_limits<unsigned>::max())
+ timeout_ms = std::numeric_limits<unsigned>::max();
+
+ return timed_wait(mutex, timeout_ms);
+ }
};
#endif