X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Ffutex.h;h=43097f4cd5b4ff9afd55460d192ea7a154ef9f70;hb=76a1fb3b42c245a425fde55b97a393d3e1984112;hp=a8b2c0f3527df7626958a9e50ea672cf1f016a15;hpb=7dc2f4788288ec9c7ab63e37fdea750c08503eca;p=mesa.git diff --git a/src/util/futex.h b/src/util/futex.h index a8b2c0f3527..43097f4cd5b 100644 --- a/src/util/futex.h +++ b/src/util/futex.h @@ -25,6 +25,7 @@ #define UTIL_FUTEX_H #if defined(HAVE_LINUX_FUTEX_H) +#define UTIL_FUTEX_SUPPORTED 1 #include #include @@ -52,6 +53,7 @@ static inline int futex_wait(uint32_t *addr, int32_t value, const struct timespe } #elif defined(__FreeBSD__) +#define UTIL_FUTEX_SUPPORTED 1 #include #include @@ -69,15 +71,15 @@ static inline int futex_wake(uint32_t *addr, int count) static inline int futex_wait(uint32_t *addr, int32_t value, struct timespec *timeout) { void *uaddr = NULL, *uaddr2 = NULL; + struct _umtx_time tmo = { + ._flags = UMTX_ABSTIME, + ._clockid = CLOCK_MONOTONIC + }; assert(value == (int)(uint32_t)value); /* Check that bits weren't discarded */ if (timeout != NULL) { - const struct _umtx_time tmo = { - ._timeout = *timeout, - ._flags = UMTX_ABSTIME, - ._clockid = CLOCK_MONOTONIC - }; + tmo._timeout = *timeout; uaddr = (void *)(uintptr_t)sizeof(tmo); uaddr2 = (void *)&tmo; } @@ -85,6 +87,34 @@ 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__) +#define UTIL_FUTEX_SUPPORTED 1 + +#include +#include + +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 tsnow, tsrel; + + if (timeout == NULL) + return futex(addr, FUTEX_WAIT, value, NULL, NULL); + + clock_gettime(CLOCK_MONOTONIC, &tsnow); + if (timespeccmp(&tsnow, timeout, <)) + timespecsub(timeout, &tsnow, &tsrel); + else + timespecclear(&tsrel); + return futex(addr, FUTEX_WAIT, value, &tsrel, NULL); +} + +#else +#define UTIL_FUTEX_SUPPORTED 0 #endif #endif /* UTIL_FUTEX_H */