1 #ifndef _LTTNG_UST_FUTEX_H
2 #define _LTTNG_UST_FUTEX_H
7 * Userspace RCU - sys_futex/compat_futex header.
9 * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <sys/syscall.h>
41 * sys_futex compatibility header.
42 * Use *only* *either of* futex_noasync OR futex_async on a given address.
44 * futex_noasync cannot be executed in signal handlers, but ensures that
45 * it will be put in a wait queue even in compatibility mode.
47 * futex_async is signal-handler safe for the wakeup. It uses polling
48 * on the wait-side in compatibility mode.
50 * BEWARE: sys_futex() FUTEX_WAIT may return early if interrupted
55 extern int lttng_ust_compat_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
56 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
58 extern int lttng_ust_compat_futex_async(int32_t *uaddr
, int op
, int32_t val
,
59 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
61 #if (defined(__linux__) && defined(__NR_futex))
65 #include <urcu/compiler.h>
66 #include <urcu/arch.h>
68 static inline int lttng_ust_futex(int32_t *uaddr
, int op
, int32_t val
,
69 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
71 return syscall(__NR_futex
, uaddr
, op
, val
, timeout
,
75 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
76 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
80 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
81 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
83 * The fallback on ENOSYS is the async-safe version of
84 * the compat futex implementation, because the
85 * async-safe compat implementation allows being used
86 * concurrently with calls to futex(). Indeed, sys_futex
87 * FUTEX_WAIT, on some architectures (mips and parisc),
88 * within a given process, spuriously return ENOSYS due
89 * to signal restart bugs on some kernel versions.
91 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
98 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
99 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
103 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
104 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
105 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
111 #elif defined(__FreeBSD__)
113 #include <sys/types.h>
114 #include <sys/umtx.h>
116 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
117 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
120 void *umtx_uaddr
= NULL
, *umtx_uaddr2
= NULL
;
121 struct _umtx_time umtx_timeout
= {
122 ._flags
= UMTX_ABSTIME
,
123 ._clockid
= CLOCK_MONOTONIC
,
128 /* On FreeBSD, a "u_int" is a 32-bit integer. */
129 umtx_op
= UMTX_OP_WAIT_UINT
;
130 if (timeout
!= NULL
) {
131 umtx_timeout
._timeout
= *timeout
;
132 umtx_uaddr
= (void *) sizeof(umtx_timeout
);
133 umtx_uaddr2
= (void *) &umtx_timeout
;
137 umtx_op
= UMTX_OP_WAKE
;
144 return _umtx_op(uaddr
, umtx_op
, (uint32_t) val
, umtx_uaddr
,
148 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
149 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
151 return lttng_ust_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
154 #elif defined(__CYGWIN__)
157 * The futex_noasync compat code uses a weak symbol to share state across
158 * different shared object which is not possible on Windows with the
159 * Portable Executable format. Use the async compat code for both cases.
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_async(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
);
175 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
176 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
178 return lttng_ust_compat_futex_noasync(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
181 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
182 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
184 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
193 #endif /* _LTTNG_UST_FUTEX_H */
This page took 0.033694 seconds and 4 git commands to generate.