Debian Codegraph @

ulib/FUTX.h

raw
1 #ifndef ULIB__FUTX_H
2 #define ULIB__FUTX_H
3
4 #include "ulib/UUID.h"
5
6 /* OpenBSD added futex() to libc since syscall mostly blocked from luserland. */
7 #if defined(__OpenBSD__)
8 #define futex_wait(uaddr, val, timeout) futex(uaddr, FUTEX_WAIT, val, timeout, 0);
9 #define futex_wake(uaddr, val) futex(uaddr, FUTEX_WAKE, val, 0, 0);
10 #endif
11
12 /* FreeBSD does not have futex() function or syscall. */
13
14 /*
15 * Not needed with AcquireSRWLockExclusive().
16 *
17 #if defined(_WIN32)
18 #include <Windows.h>
19 bool futex_wait(LONG *uaddr, LONG val, DWORD timeout);
20 void futex_wake(LONG *uaddr, LONG val);
21 #endif
22 */
23
24 /*
25 * Not needed with AcquireSRWLockExclusive().
26 *
27 #if defined(__CYGWIN__)
28 #include <Windows.h>
29 #define futex_wait(uaddr, val, timeout) ({ typeof(*(uaddr)) _val = (val); WaitOnAddress(uaddr, &_val, sizeof(_val), timeout); })
30 #define futex_wake(uaddr, val) WakeByAddressSingle(uaddr)
31 #endif
32 */
33
34 /*
35 * Not needed with switch to sem_wait().
36 *
37 #if defined(__linux__)
38 #include <unistd.h>
39 #include <linux/futex.h>
40 #include <sys/syscall.h>
41 #define futex_wait(uaddr, val, timeout) syscall(SYS_futex, uaddr, FUTEX_WAIT, val, timeout, 0, 0);
42 #define futex_wake(uaddr, val) syscall(SYS_futex, uaddr, FUTEX_WAKE, val, 0, 0, 0);
43 #endif
44 */
45
46 #endif