4 * Userspace RCU library - sys_futex compatibility code
6 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <urcu/arch.h>
32 #include <urcu/futex.h>
34 static pthread_mutex_t compat_futex_lock
= PTHREAD_MUTEX_INITIALIZER
;
35 static pthread_cond_t compat_futex_cond
= PTHREAD_COND_INITIALIZER
;
38 * _NOT SIGNAL-SAFE_. pthread_cond is not signal-safe anyway. Though.
39 * For now, timeout, uaddr2 and val3 are unused.
40 * Waiter will relinquish the CPU until woken up.
43 int compat_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
44 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
49 * Check if NULL. Don't let users expect that they are taken into
57 * memory barriers to serialize with the previous uaddr modification.
61 ret
= pthread_mutex_lock(&compat_futex_lock
);
67 pthread_cond_wait(&compat_futex_cond
, &compat_futex_lock
);
70 for (i
= 0; i
< val
; i
++)
71 pthread_cond_signal(&compat_futex_cond
);
77 ret
= pthread_mutex_unlock(&compat_futex_lock
);
83 * _ASYNC SIGNAL-SAFE_.
84 * For now, timeout, uaddr2 and val3 are unused.
85 * Waiter will busy-loop trying to read the condition.
88 int compat_futex_async(int32_t *uaddr
, int op
, int32_t val
,
89 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
94 * Check if NULL. Don't let users expect that they are taken into
102 * Ensure previous memory operations on uaddr have completed.
108 while (*uaddr
== val
)