From e9af364c26b0e474b87a7fe5fb2222a399f8e180 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Sat, 18 May 2024 00:34:06 -0400 Subject: [PATCH] Use futex on OpenBSD Tested with "make check", "make regtest". Signed-off-by: Brad Smith Signed-off-by: Mathieu Desnoyers Change-Id: Icd334cda928f998a2cf455839d428ebbb4460f5e --- include/urcu/futex.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/urcu/futex.h b/include/urcu/futex.h index 9d0a997..b219835 100644 --- a/include/urcu/futex.h +++ b/include/urcu/futex.h @@ -31,14 +31,21 @@ #include #include +#elif defined(__OpenBSD__) + +#include +#include + #endif #ifdef __cplusplus extern "C" { #endif +#ifndef __OpenBSD__ #define FUTEX_WAIT 0 #define FUTEX_WAKE 1 +#endif /* * sys_futex compatibility header. @@ -146,6 +153,36 @@ static inline int futex_noasync(int32_t *uaddr, int op, int32_t val, return futex_async(uaddr, op, val, timeout, uaddr2, val3); } +#elif defined(__OpenBSD__) + +static inline int futex_noasync(int32_t *uaddr, int op, int32_t val, + const struct timespec *timeout, int32_t *uaddr2, int32_t val3) +{ + int ret; + + ret = futex((volatile uint32_t *) uaddr, op, val, timeout, + (volatile uint32_t *) uaddr2); + if (caa_unlikely(ret < 0 && errno == ENOSYS)) { + return compat_futex_noasync(uaddr, op, val, timeout, + uaddr2, val3); + } + return ret; +} + +static inline int futex_async(int32_t *uaddr, int op, int32_t val, + const struct timespec *timeout, int32_t *uaddr2, int32_t val3) +{ + int ret; + + ret = futex((volatile uint32_t *) uaddr, op, val, timeout, + (volatile uint32_t *) uaddr2); + if (caa_unlikely(ret < 0 && errno == ENOSYS)) { + return compat_futex_async(uaddr, op, val, timeout, + uaddr2, val3); + } + return ret; +} + #elif defined(__CYGWIN__) /* -- 2.34.1