2 ports/sysdeps/unix/sysv/linux/hppa/linuxthreads/lowlevellock.h | 298 ++++++++++
3 ports/sysdeps/unix/sysv/linux/hppa/linuxthreads/sysdep-cancel.h | 7
4 2 files changed, 305 insertions(+)
7 +++ b/ports/sysdeps/unix/sysv/linux/hppa/linuxthreads/lowlevellock.h
9 +/* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
10 + This file is part of the GNU C Library.
12 + The GNU C Library is free software; you can redistribute it and/or
13 + modify it under the terms of the GNU Lesser General Public
14 + License as published by the Free Software Foundation; either
15 + version 2.1 of the License, or (at your option) any later version.
17 + The GNU C Library is distributed in the hope that it will be useful,
18 + but WITHOUT ANY WARRANTY; without even the implied warranty of
19 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 + Lesser General Public License for more details.
22 + You should have received a copy of the GNU Lesser General Public
23 + License along with the GNU C Library; if not, write to the Free
24 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 +#ifndef _LOWLEVELLOCK_H
28 +#define _LOWLEVELLOCK_H 1
31 +#include <sys/param.h>
32 +#include <bits/pthreadtypes.h>
36 +/* The hppa only has one atomic read and modify memory operation,
37 + load and clear, so hppa uses a kernel helper routine to implement
38 + compare_and_exchange. See atomic.h for the userspace calling
43 +#define FUTEX_REQUEUE 3
44 +#define FUTEX_CMP_REQUEUE 4
45 +#define FUTEX_WAKE_OP 5
46 +#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
47 +#define FUTEX_LOCK_PI 6
48 +#define FUTEX_UNLOCK_PI 7
49 +#define FUTEX_TRYLOCK_PI 8
51 +/* Initialize locks to zero. */
52 +#define LLL_MUTEX_LOCK_INITIALIZER (0)
55 +/* Type for lock object. */
56 +typedef int lll_lock_t;
59 +#define lll_futex_wait(futexp, val) \
61 + INTERNAL_SYSCALL_DECL (__err); \
63 + __ret = INTERNAL_SYSCALL (futex, __err, 4, \
64 + (futexp), FUTEX_WAIT, (val), 0); \
68 +#define lll_futex_timed_wait(futexp, val, timespec) \
70 + INTERNAL_SYSCALL_DECL (__err); \
72 + __ret = INTERNAL_SYSCALL (futex, __err, 4, \
73 + (futexp), FUTEX_WAIT, (val), (timespec)); \
77 +#define lll_futex_wake(futexp, nr) \
79 + INTERNAL_SYSCALL_DECL (__err); \
81 + __ret = INTERNAL_SYSCALL (futex, __err, 4, \
82 + (futexp), FUTEX_WAKE, (nr), 0); \
86 +#define lll_robust_mutex_dead(futexv) \
89 + int *__futexp = &(futexv); \
90 + atomic_or (__futexp, FUTEX_OWNER_DIED); \
91 + lll_futex_wake (__futexp, 1); \
95 +/* Returns non-zero if error happened, zero if success. */
96 +#define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val) \
98 + INTERNAL_SYSCALL_DECL (__err); \
100 + __ret = INTERNAL_SYSCALL (futex, __err, 6, \
101 + (futexp), FUTEX_CMP_REQUEUE, (nr_wake), \
102 + (nr_move), (mutex), (val)); \
106 +/* Returns non-zero if error happened, zero if success. */
107 +#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2) \
109 + INTERNAL_SYSCALL_DECL (__err); \
111 + __ret = INTERNAL_SYSCALL (futex, __err, 6, \
112 + (futexp), FUTEX_WAKE_OP, (nr_wake), \
113 + (nr_wake2), (futexp2), \
114 + FUTEX_OP_CLEAR_WAKE_IF_GT_ONE); \
118 +static inline int __attribute__((always_inline))
119 +__lll_mutex_trylock(lll_lock_t *futex)
121 + return atomic_compare_and_exchange_val_acq (futex, 1, 0) != 0;
123 +#define lll_mutex_trylock(lock) __lll_mutex_trylock (&(lock))
125 +static inline int __attribute__((always_inline))
126 +__lll_robust_mutex_trylock(int *futex, int id)
128 + return atomic_compare_and_exchange_val_acq (futex, id, 0) != 0;
130 +#define lll_robust_mutex_trylock(lock, id) \
131 + __lll_robust_mutex_trylock (&(lock), id)
134 +static inline int __attribute__((always_inline))
135 +__lll_mutex_cond_trylock(lll_lock_t *futex)
137 + return atomic_compare_and_exchange_val_acq (futex, 2, 0) != 0;
139 +#define lll_mutex_cond_trylock(lock) __lll_mutex_cond_trylock (&(lock))
142 +extern void __lll_lock_wait (lll_lock_t *futex) attribute_hidden;
144 +static inline void __attribute__((always_inline))
145 +__lll_mutex_lock(lll_lock_t *futex)
147 + if (atomic_compare_and_exchange_bool_acq (futex, 1, 0) != 0)
148 + __lll_lock_wait (futex);
150 +#define lll_mutex_lock(futex) __lll_mutex_lock (&(futex))
152 +extern int __lll_robust_lock_wait (int *futex) attribute_hidden;
154 +static inline int __attribute__ ((always_inline))
155 +__lll_robust_mutex_lock (int *futex, int id)
158 + if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
159 + result = __lll_robust_lock_wait (futex);
162 +#define lll_robust_mutex_lock(futex, id) \
163 + __lll_robust_mutex_lock (&(futex), id)
165 +static inline void __attribute__ ((always_inline))
166 +__lll_mutex_cond_lock (lll_lock_t *futex)
168 + if (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0)
169 + __lll_lock_wait (futex);
171 +#define lll_mutex_cond_lock(futex) __lll_mutex_cond_lock (&(futex))
174 +#define lll_robust_mutex_cond_lock(futex, id) \
175 + __lll_robust_mutex_lock (&(futex), (id) | FUTEX_WAITERS)
178 +extern int __lll_timedlock_wait (lll_lock_t *futex, const struct timespec *)
180 +extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *)
183 +static inline int __attribute__ ((always_inline))
184 +__lll_mutex_timedlock (lll_lock_t *futex, const struct timespec *abstime)
187 + if (atomic_compare_and_exchange_bool_acq (futex, 1, 0) != 0)
188 + result = __lll_timedlock_wait (futex, abstime);
191 +#define lll_mutex_timedlock(futex, abstime) \
192 + __lll_mutex_timedlock (&(futex), abstime)
194 +static inline int __attribute__ ((always_inline))
195 +__lll_robust_mutex_timedlock (int *futex, const struct timespec *abstime,
199 + if (atomic_compare_and_exchange_bool_acq (futex, id, 0) != 0)
200 + result = __lll_robust_timedlock_wait (futex, abstime);
203 +#define lll_robust_mutex_timedlock(futex, abstime, id) \
204 + __lll_robust_mutex_timedlock (&(futex), abstime, id)
207 +static inline void __attribute__ ((always_inline))
208 +__lll_mutex_unlock (lll_lock_t *futex)
210 + int val = atomic_exchange_rel (futex, 0);
211 + if (__builtin_expect (val > 1, 0))
212 + lll_futex_wake (futex, 1);
214 +#define lll_mutex_unlock(futex) __lll_mutex_unlock(&(futex))
217 +static inline void __attribute__ ((always_inline))
218 +__lll_robust_mutex_unlock (int *futex, int mask)
220 + int val = atomic_exchange_rel (futex, 0);
221 + if (__builtin_expect (val & mask, 0))
222 + lll_futex_wake (futex, 1);
224 +#define lll_robust_mutex_unlock(futex) \
225 + __lll_robust_mutex_unlock(&(futex), FUTEX_WAITERS)
228 +static inline void __attribute__ ((always_inline))
229 +__lll_mutex_unlock_force (lll_lock_t *futex)
231 + (void) atomic_exchange_rel (futex, 0);
232 + lll_futex_wake (futex, 1);
234 +#define lll_mutex_unlock_force(futex) __lll_mutex_unlock_force(&(futex))
236 +#define lll_mutex_islocked(futex) \
239 +/* Our internal lock implementation is identical to the binary-compatible
240 + mutex implementation. */
242 +#define LLL_LOCK_INITIALIZER (0)
243 +#define LLL_LOCK_INITIALIZER_CONST (0)
244 +#define LLL_LOCK_INITIALIZER_LOCKED (1)
247 +#define THREAD_INIT_LOCK(PD, LOCK) \
248 + (PD)->LOCK = LLL_LOCK_INITIALIZER
250 +extern int lll_unlock_wake_cb (lll_lock_t *__futex) attribute_hidden;
252 +/* The states of a lock are:
254 + 1 - taken by one user
255 + >1 - taken by more users */
257 +#define lll_trylock(lock) lll_mutex_trylock (lock)
258 +#define lll_lock(lock) lll_mutex_lock (lock)
259 +#define lll_unlock(lock) lll_mutex_unlock (lock)
260 +#define lll_islocked(lock) lll_mutex_islocked (lock)
262 +/* The kernel notifies a process which uses CLONE_CLEARTID via futex
263 + wakeup when the clone terminates. The memory location contains the
264 + thread ID while the clone is running and is reset to zero
266 +#define lll_wait_tid(tid) \
268 + __typeof (tid) __tid; \
269 + while ((__tid = (tid)) != 0) \
270 + lll_futex_wait (&(tid), __tid); \
273 +extern int __lll_timedwait_tid (int *, const struct timespec *)
276 +#define lll_timedwait_tid(tid, abstime) \
280 + __res = __lll_timedwait_tid (&(tid), (abstime)); \
285 +/* Conditional variable handling. */
287 +extern void __lll_cond_wait (pthread_cond_t *cond)
289 +extern int __lll_cond_timedwait (pthread_cond_t *cond,
290 + const struct timespec *abstime)
292 +extern void __lll_cond_wake (pthread_cond_t *cond)
294 +extern void __lll_cond_broadcast (pthread_cond_t *cond)
297 +#define lll_cond_wait(cond) \
298 + __lll_cond_wait (cond)
299 +#define lll_cond_timedwait(cond, abstime) \
300 + __lll_cond_timedwait (cond, abstime)
301 +#define lll_cond_wake(cond) \
302 + __lll_cond_wake (cond)
303 +#define lll_cond_broadcast(cond) \
304 + __lll_cond_broadcast (cond)
306 +#endif /* lowlevellock.h */
307 --- a/ports/sysdeps/unix/sysv/linux/hppa/linuxthreads/sysdep-cancel.h
308 +++ b/ports/sysdeps/unix/sysv/linux/hppa/linuxthreads/sysdep-cancel.h
312 /* !defined NOT_IN_libc || defined IS_IN_libpthread */
314 +#ifndef __ASSEMBLER__
315 +# define RTLD_SINGLE_THREAD_P \
316 + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
317 + p_multiple_threads) == 0, 1)