1
2
3
4
5
6
7
8#ifndef _FUTEX_H
9#define _FUTEX_H
10
11#include <unistd.h>
12#include <sys/syscall.h>
13#include <sys/types.h>
14#include <linux/futex.h>
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \
37 syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3)
38
39
40
41
42
43static inline int
44futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec *timeout, int opflags)
45{
46 return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags);
47}
48
49
50
51
52
53static inline int
54futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)
55{
56 return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags);
57}
58
59
60
61
62static inline int
63futex_lock_pi(u_int32_t *uaddr, struct timespec *timeout, int opflags)
64{
65 return futex(uaddr, FUTEX_LOCK_PI, 0, timeout, NULL, 0, opflags);
66}
67
68
69
70
71static inline int
72futex_unlock_pi(u_int32_t *uaddr, int opflags)
73{
74 return futex(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags);
75}
76
77
78
79
80
81
82static inline int
83futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wake,
84 int nr_requeue, int opflags)
85{
86 return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2,
87 val, opflags);
88}
89
90#ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
91#include <pthread.h>
92#include <linux/compiler.h>
93static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr __maybe_unused,
94 size_t cpusetsize __maybe_unused,
95 cpu_set_t *cpuset __maybe_unused)
96{
97 return 0;
98}
99#endif
100
101#endif
102