summaryrefslogtreecommitdiff
path: root/rts/posix
diff options
context:
space:
mode:
authorDouglas Wilson <douglas.wilson@gmail.com>2021-01-04 09:46:58 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-01-17 05:49:54 -0500
commit33fc453fd46e54410472a7bad7585e5d1821c0ec (patch)
tree948b2b5af172fcac62364c656e71b70af4ce0bde /rts/posix
parent345ae06b3334a64e9d6db9ea69573ef3227e535a (diff)
downloadhaskell-33fc453fd46e54410472a7bad7585e5d1821c0ec.tar.gz
rts: add timedWaitCondition
Diffstat (limited to 'rts/posix')
-rw-r--r--rts/posix/OSThreads.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index be2b596c35..200a4ccdad 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -78,6 +78,9 @@
#include <numa.h>
#endif
+// TODO does this need configure magic?
+#include <time.h>
+
/*
* This (allegedly) OS threads independent layer was initially
* abstracted away from code that used Pthreads, so the functions
@@ -117,6 +120,19 @@ waitCondition ( Condition* pCond, Mutex* pMut )
return (pthread_cond_wait(pCond,pMut) == 0);
}
+bool
+timedWaitCondition ( Condition* pCond, Mutex* pMut, Time timeout) {
+ timeout += getMonotonicNSec();
+ uint64_t secs = TimeToSeconds(timeout);
+
+ const struct timespec t = (struct timespec) {
+ .tv_sec = secs,
+ .tv_nsec = TimeToNS(timeout - SecondsToTime(secs))
+ };
+
+ return pthread_cond_timedwait(pCond,pMut, &t) == 0;
+}
+
void
yieldThread(void)
{