Here is a diff to add futex support for liburcu.
Index: Makefile =================================================================== RCS file: /cvs/ports/devel/liburcu/Makefile,v retrieving revision 1.28 diff -u -p -u -p -r1.28 Makefile --- Makefile 17 Oct 2023 06:17:19 -0000 1.28 +++ Makefile 4 Jun 2024 04:00:59 -0000 @@ -3,7 +3,7 @@ COMMENT = user-level RCU implementation V = 0.14.0 DISTNAME = userspace-rcu-$V PKGNAME = liburcu-$V -REVISION = 0 +REVISION = 1 SHARED_LIBS += urcu-bp 3.0 # 9.0 SHARED_LIBS += urcu-cds 2.1 # 9.0 @@ -34,5 +34,13 @@ COMPILER = base-clang ports-gcc USE_GMAKE = Yes CONFIGURE_STYLE = gnu + +TEST_DEPENDS += shells/bash + +# Adjust shell scripts to allow Bash in other locations +# da56d5cad05a280a8171ef51f185e6d0d29610f0 +post-extract: + find ${WRKSRC}/tests -exec grep -q '/bin/bash' {} \; -print |\ + xargs sed -i "s#/bin/bash#/usr/bin/env bash#g" .include <bsd.port.mk> Index: patches/patch-include_urcu_futex_h =================================================================== RCS file: patches/patch-include_urcu_futex_h diff -N patches/patch-include_urcu_futex_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-include_urcu_futex_h 4 Jun 2024 04:00:59 -0000 @@ -0,0 +1,121 @@ +- Use futex on OpenBSD + e9af364c26b0e474b87a7fe5fb2222a399f8e180 +- futex.h: Use urcu_posix_assert to validate unused values + e463c38f0ec65d06e544681d1916991808a6a2b9 + +Index: include/urcu/futex.h +--- include/urcu/futex.h.orig ++++ include/urcu/futex.h +@@ -39,20 +39,28 @@ + #include <errno.h> + #include <urcu/compiler.h> + #include <urcu/arch.h> ++#include <urcu/assert.h> + + #elif defined(__FreeBSD__) + + #include <sys/types.h> + #include <sys/umtx.h> + ++#elif defined(__OpenBSD__) ++ ++#include <sys/time.h> ++#include <sys/futex.h> ++ + #endif + + #ifdef __cplusplus + extern "C" { + #endif + ++#ifndef __OpenBSD__ + #define FUTEX_WAIT 0 + #define FUTEX_WAKE 1 ++#endif + + /* + * sys_futex compatibility header. +@@ -78,8 +86,7 @@ extern int compat_futex_async(int32_t *uaddr, int op, + static inline int futex(int32_t *uaddr, int op, int32_t val, + const struct timespec *timeout, int32_t *uaddr2, int32_t val3) + { +- return syscall(__NR_futex, uaddr, op, val, timeout, +- uaddr2, val3); ++ return syscall(__NR_futex, uaddr, op, val, timeout, uaddr2, val3); + } + + static inline int futex_noasync(int32_t *uaddr, int op, int32_t val, +@@ -121,9 +128,7 @@ static inline int futex_async(int32_t *uaddr, int op, + #elif defined(__FreeBSD__) + + static inline int futex_async(int32_t *uaddr, int op, int32_t val, +- const struct timespec *timeout, +- int32_t *uaddr2 __attribute__((unused)), +- int32_t val3 __attribute__((unused))) ++ const struct timespec *timeout, int32_t *uaddr2, int32_t val3) + { + int umtx_op; + void *umtx_uaddr = NULL, *umtx_uaddr2 = NULL; +@@ -132,6 +137,13 @@ static inline int futex_async(int32_t *uaddr, int op, + ._clockid = CLOCK_MONOTONIC, + }; + ++ /* ++ * Check if NULL or zero. Don't let users expect that they are ++ * taken into account. ++ */ ++ urcu_posix_assert(!uaddr2); ++ urcu_posix_assert(!val3); ++ + switch (op) { + case FUTEX_WAIT: + /* On FreeBSD, a "u_int" is a 32-bit integer. */ +@@ -158,6 +170,48 @@ static inline int futex_noasync(int32_t *uaddr, int op + const struct timespec *timeout, int32_t *uaddr2, int32_t val3) + { + 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; ++ ++ /* ++ * Check that val3 is zero. Don't let users expect that it is ++ * taken into account. ++ */ ++ urcu_posix_assert(!val3); ++ ++ 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; ++ ++ /* ++ * Check that val3 is zero. Don't let users expect that it is ++ * taken into account. ++ */ ++ urcu_posix_assert(!val3); ++ ++ 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__) Index: patches/patch-include_urcu_syscall-compat_h =================================================================== RCS file: /cvs/ports/devel/liburcu/patches/patch-include_urcu_syscall-compat_h,v retrieving revision 1.3 diff -u -p -u -p -r1.3 patch-include_urcu_syscall-compat_h --- patches/patch-include_urcu_syscall-compat_h 10 Mar 2022 00:04:05 -0000 1.3 +++ patches/patch-include_urcu_syscall-compat_h 4 Jun 2024 04:00:59 -0000 @@ -1,12 +1,16 @@ +Add support for OpenBSD +11f3d1c24e6179abf8247611c5308f41d95389a1 + Index: include/urcu/syscall-compat.h --- include/urcu/syscall-compat.h.orig +++ include/urcu/syscall-compat.h -@@ -33,7 +33,7 @@ +@@ -33,7 +33,8 @@ #include <syscall.h> #elif defined(__CYGWIN__) || defined(__APPLE__) || \ - defined(__FreeBSD__) || defined(__DragonFly__) -+ defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) ++ defined(__FreeBSD__) || defined(__DragonFly__) || \ ++ defined(__OpenBSD__) /* Don't include anything on these platforms. */ #else Index: patches/patch-tests_common_thread-id_h =================================================================== RCS file: /cvs/ports/devel/liburcu/patches/patch-tests_common_thread-id_h,v retrieving revision 1.4 diff -u -p -u -p -r1.4 patch-tests_common_thread-id_h --- patches/patch-tests_common_thread-id_h 10 Mar 2022 00:04:05 -0000 1.4 +++ patches/patch-tests_common_thread-id_h 4 Jun 2024 04:00:59 -0000 @@ -1,4 +1,5 @@ -XXX not portable, but used by tests only. +Add support for OpenBSD +11f3d1c24e6179abf8247611c5308f41d95389a1 Index: tests/common/thread-id.h --- tests/common/thread-id.h.orig @@ -8,7 +9,7 @@ Index: tests/common/thread-id.h } +#elif defined(__OpenBSD__) -+# include <unistd.h> ++#include <unistd.h> + +static inline +unsigned long urcu_get_thread_id(void)