View | Details | Raw Unified | Return to bug 225415 | Differences between
and this patch

Collapse All | Expand All

(-)src/util/futex.h (+26 lines)
Lines 29-38 Link Here
29
#include <limits.h>
29
#include <limits.h>
30
#include <stdint.h>
30
#include <stdint.h>
31
#include <unistd.h>
31
#include <unistd.h>
32
#if defined(__FreeBSD__)
33
# if __FreeBSD__ < 11
34
#  include <machine/atomic.h>
35
# endif
36
#include <errno.h>
37
#include <sys/umtx.h>
38
#else
32
#include <linux/futex.h>
39
#include <linux/futex.h>
33
#include <sys/syscall.h>
40
#include <sys/syscall.h>
41
#endif
34
#include <sys/time.h>
42
#include <sys/time.h>
35
43
44
#if defined(__FreeBSD__)
45
static inline int futex_wake(uint32_t *addr, int count)
46
{
47
   return _umtx_op(addr, UMTX_OP_WAKE, (uint32_t)count, NULL, NULL) == -1 ? errno : 0;
48
}
49
50
static inline int futex_wait(uint32_t *addr, int32_t value, struct timespec *timeout)
51
{
52
   void *uaddr = NULL, *uaddr2 = NULL;
53
   if (timeout != NULL) {
54
      const struct _umtx_time tmo = { ._clockid = CLOCK_MONOTONIC, ._flags = UMTX_ABSTIME, ._timeout = *timeout };
55
      uaddr = (void *)(uintptr_t)sizeof(tmo);
56
      uaddr2 = (void *)&tmo;
57
   }
58
   return _umtx_op(addr, UMTX_OP_WAIT_UINT, (uint32_t)value, uaddr, uaddr2) == -1 ? errno : 0;
59
}
60
#else
36
static inline long sys_futex(void *addr1, int op, int val1, const struct timespec *timeout, void *addr2, int val3)
61
static inline long sys_futex(void *addr1, int op, int val1, const struct timespec *timeout, void *addr2, int val3)
37
{
62
{
38
   return syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
63
   return syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
Lines 50-55 static inline int futex_wait(uint32_t *addr, int32_t v Link Here
50
   return sys_futex(addr, FUTEX_WAIT_BITSET, value, timeout, NULL,
75
   return sys_futex(addr, FUTEX_WAIT_BITSET, value, timeout, NULL,
51
                    FUTEX_BITSET_MATCH_ANY);
76
                    FUTEX_BITSET_MATCH_ANY);
52
}
77
}
78
#endif
53
79
54
#endif
80
#endif
55
81

Return to bug 225415