Linux Perf
futex.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Glibc independent futex library for testing kernel functionality.
4  * Shamelessly stolen from Darren Hart <dvhltc@us.ibm.com>
5  * http://git.kernel.org/cgit/linux/kernel/git/dvhart/futextest.git/
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 
36 #define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \
37  syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3)
38 
43 static inline int
44 futex_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 
53 static inline int
54 futex_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 
62 static inline int
63 futex_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 
71 static inline int
72 futex_unlock_pi(u_int32_t *uaddr, int opflags)
73 {
74  return futex(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags);
75 }
76 
82 static inline int
83 futex_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>
93 static 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 /* _FUTEX_H */
int FUTEX_WAIT
Definition: Util.py:11
static int futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wake, int nr_requeue, int opflags)
Definition: futex.h:83
#define futex(uaddr, op, val, timeout, uaddr2, val3, opflags)
Definition: futex.h:36
int FUTEX_WAKE
Definition: Util.py:12
static int pthread_attr_setaffinity_np(pthread_attr_t *attr __maybe_unused, size_t cpusetsize __maybe_unused, cpu_set_t *cpuset __maybe_unused)
Definition: futex.h:93
static int futex_lock_pi(u_int32_t *uaddr, struct timespec *timeout, int opflags)
Definition: futex.h:63
static int futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec *timeout, int opflags)
Definition: futex.h:44
Definition: attr.py:1
static int futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)
Definition: futex.h:54
static int futex_unlock_pi(u_int32_t *uaddr, int opflags)
Definition: futex.h:72