util/futex: use futex syscall on OpenBSD
authorJonathan Gray <jsg@jsg.id.au>
Sat, 30 Nov 2019 15:19:38 +0000 (02:19 +1100)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 2 Dec 2019 22:23:49 +0000 (17:23 -0500)
Make use of the futex syscall added in OpenBSD 6.2.

Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
src/util/futex.h

index 268af92882a1660a691d3c0fbc5cde870bd0b2a1..cf8dd0206c98fdb04ed2e00abe348be163f4d4fa 100644 (file)
@@ -85,6 +85,24 @@ static inline int futex_wait(uint32_t *addr, int32_t value, struct timespec *tim
    return _umtx_op(addr, UMTX_OP_WAIT_UINT, (uint32_t)value, uaddr, uaddr2) == -1 ? errno : 0;
 }
 
+#elif defined(__OpenBSD__)
+
+#include <sys/time.h>
+#include <sys/futex.h>
+
+static inline int futex_wake(uint32_t *addr, int count)
+{
+   return futex(addr, FUTEX_WAKE, count, NULL, NULL);
+}
+
+static inline int futex_wait(uint32_t *addr, int32_t value, const struct timespec *timeout)
+{
+   struct timespec tsrel, tsnow;
+   clock_gettime(CLOCK_MONOTONIC, &tsnow); 
+   timespecsub(timeout, &tsrel, &tsrel);
+   return futex(addr, FUTEX_WAIT, value, &tsrel, NULL);
+}
+
 #endif
 
 #endif /* UTIL_FUTEX_H */