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>
25 * sys_futex compatibility header.
26 * Use *only* *either of* futex_noasync OR futex_async on a given address.
28 * futex_noasync cannot be executed in signal handlers, but ensures that
29 * it will be put in a wait queue even in compatibility mode.
31 * futex_async is signal-handler safe for the wakeup. It uses polling
32 * on the wait-side in compatibility mode.
34 * BEWARE: sys_futex() FUTEX_WAIT may return early if interrupted
38 extern int lttng_ust_compat_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
39 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
40 __attribute__((visibility("hidden")));
42 extern int lttng_ust_compat_futex_async(int32_t *uaddr
, int op
, int32_t val
,
43 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
44 __attribute__((visibility("hidden")));
46 #if (defined(__linux__) && defined(__NR_futex))
50 #include <urcu/compiler.h>
51 #include <urcu/arch.h>
53 static inline int lttng_ust_futex(int32_t *uaddr
, int op
, int32_t val
,
54 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
56 return syscall(__NR_futex
, uaddr
, op
, val
, timeout
,
60 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
61 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
65 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
66 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
68 * The fallback on ENOSYS is the async-safe version of
69 * the compat futex implementation, because the
70 * async-safe compat implementation allows being used
71 * concurrently with calls to futex(). Indeed, sys_futex
72 * FUTEX_WAIT, on some architectures (mips and parisc),
73 * within a given process, spuriously return ENOSYS due
74 * to signal restart bugs on some kernel versions.
76 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
83 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
84 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
88 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
89 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
90 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
96 #elif defined(__FreeBSD__)
98 #include <sys/types.h>
101 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
102 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
105 void *umtx_uaddr
= NULL
, *umtx_uaddr2
= NULL
;
106 struct _umtx_time umtx_timeout
= {
107 ._flags
= UMTX_ABSTIME
,
108 ._clockid
= CLOCK_MONOTONIC
,
113 /* On FreeBSD, a "u_int" is a 32-bit integer. */
114 umtx_op
= UMTX_OP_WAIT_UINT
;
115 if (timeout
!= NULL
) {
116 umtx_timeout
._timeout
= *timeout
;
117 umtx_uaddr
= (void *) sizeof(umtx_timeout
);
118 umtx_uaddr2
= (void *) &umtx_timeout
;
122 umtx_op
= UMTX_OP_WAKE
;
129 return _umtx_op(uaddr
, umtx_op
, (uint32_t) val
, umtx_uaddr
,
133 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
134 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
136 return lttng_ust_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
139 #elif defined(__CYGWIN__)
142 * The futex_noasync compat code uses a weak symbol to share state across
143 * different shared object which is not possible on Windows with the
144 * Portable Executable format. Use the async compat code for both cases.
146 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
147 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
149 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
152 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
153 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
155 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
160 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
161 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
163 return lttng_ust_compat_futex_noasync(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
166 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
167 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
169 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
178 #endif /* _LTTNG_UST_FUTEX_H */
This page took 0.034221 seconds and 4 git commands to generate.