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
26 #include <urcu/config.h>
38 * sys_futex compatibility header.
39 * Use *only* *either of* futex_noasync OR futex_async on a given address.
41 * futex_noasync cannot be executed in signal handlers, but ensures that
42 * it will be put in a wait queue even in compatibility mode.
44 * futex_async is signal-handler safe for the wakeup. It uses polling
45 * on the wait-side in compatibility mode.
47 * BEWARE: sys_futex() FUTEX_WAIT may return early if interrupted
51 extern int compat_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
52 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
53 extern int compat_futex_async(int32_t *uaddr
, int op
, int32_t val
,
54 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
);
56 #ifdef CONFIG_RCU_HAVE_FUTEX
60 #include <urcu/compiler.h>
61 #include <urcu/arch.h>
63 static inline int futex(int32_t *uaddr
, int op
, int32_t val
,
64 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
66 return syscall(__NR_futex
, uaddr
, op
, val
, timeout
,
70 static inline int futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
71 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
75 ret
= futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
76 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
78 * The fallback on ENOSYS is the async-safe version of
79 * the compat futex implementation, because the
80 * async-safe compat implementation allows being used
81 * concurrently with calls to futex(). Indeed, sys_futex
82 * FUTEX_WAIT, on some architectures (mips and parisc),
83 * within a given process, spuriously return ENOSYS due
84 * to signal restart bugs on some kernel versions.
86 return compat_futex_async(uaddr
, op
, val
, timeout
,
93 static inline int futex_async(int32_t *uaddr
, int op
, int32_t val
,
94 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
98 ret
= futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
99 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
100 return compat_futex_async(uaddr
, op
, val
, timeout
,
106 #elif defined(__CYGWIN__)
109 * The futex_noasync compat code uses a weak symbol to share state across
110 * different shared object which is not possible on Windows with the
111 * Portable Executable format. Use the async compat code for both cases.
113 static inline int futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
114 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
116 return compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
119 static inline int futex_async(int32_t *uaddr
, int op
, int32_t val
,
120 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
122 return compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
127 static inline int futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
128 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
130 return compat_futex_noasync(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
133 static inline int futex_async(int32_t *uaddr
, int op
, int32_t val
,
134 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
136 return compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
145 #endif /* _URCU_FUTEX_H */
This page took 0.059434 seconds and 4 git commands to generate.