2 * SPDX-License-Identifier: LGPL-2.1-or-later
4 * Copyright 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Userspace RCU - sys_futex/compat_futex header.
9 #ifndef _LTTNG_UST_FUTEX_H
10 #define _LTTNG_UST_FUTEX_H
15 #include <sys/syscall.h>
17 #include "ust-helper.h"
27 * sys_futex compatibility header.
28 * Use *only* *either of* futex_noasync OR futex_async on a given address.
30 * futex_noasync cannot be executed in signal handlers, but ensures that
31 * it will be put in a wait queue even in compatibility mode.
33 * futex_async is signal-handler safe for the wakeup. It uses polling
34 * on the wait-side in compatibility mode.
36 * BEWARE: sys_futex() FUTEX_WAIT may return early if interrupted
41 extern int lttng_ust_compat_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
42 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
44 extern int lttng_ust_compat_futex_async(int32_t *uaddr
, int op
, int32_t val
,
45 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
47 #if (defined(__linux__) && defined(__NR_futex))
51 #include <urcu/compiler.h>
52 #include <urcu/arch.h>
54 static inline int lttng_ust_futex(int32_t *uaddr
, int op
, int32_t val
,
55 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
57 return syscall(__NR_futex
, uaddr
, op
, val
, timeout
,
61 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
62 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
66 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
67 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
69 * The fallback on ENOSYS is the async-safe version of
70 * the compat futex implementation, because the
71 * async-safe compat implementation allows being used
72 * concurrently with calls to futex(). Indeed, sys_futex
73 * FUTEX_WAIT, on some architectures (mips and parisc),
74 * within a given process, spuriously return ENOSYS due
75 * to signal restart bugs on some kernel versions.
77 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
84 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
85 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
89 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
90 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
91 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
97 #elif defined(__FreeBSD__)
99 #include <sys/types.h>
100 #include <sys/umtx.h>
102 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
103 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
106 void *umtx_uaddr
= NULL
, *umtx_uaddr2
= NULL
;
107 struct _umtx_time umtx_timeout
= {
108 ._flags
= UMTX_ABSTIME
,
109 ._clockid
= CLOCK_MONOTONIC
,
114 /* On FreeBSD, a "u_int" is a 32-bit integer. */
115 umtx_op
= UMTX_OP_WAIT_UINT
;
116 if (timeout
!= NULL
) {
117 umtx_timeout
._timeout
= *timeout
;
118 umtx_uaddr
= (void *) sizeof(umtx_timeout
);
119 umtx_uaddr2
= (void *) &umtx_timeout
;
123 umtx_op
= UMTX_OP_WAKE
;
130 return _umtx_op(uaddr
, umtx_op
, (uint32_t) val
, umtx_uaddr
,
134 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
135 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
137 return lttng_ust_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
140 #elif defined(__CYGWIN__)
143 * The futex_noasync compat code uses a weak symbol to share state across
144 * different shared object which is not possible on Windows with the
145 * Portable Executable format. Use the async compat code for both cases.
147 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
148 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
150 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
153 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
154 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
156 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
161 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
162 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
164 return lttng_ust_compat_futex_noasync(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
167 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
168 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
170 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
179 #endif /* _LTTNG_UST_FUTEX_H */
This page took 0.034591 seconds and 4 git commands to generate.