1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 #ifndef _LOWLEVELLOCK_H
20 #define _LOWLEVELLOCK_H 1
23 #include <sys/param.h>
24 #include <bits/pthreadtypes.h>
31 /* Initializer for compatibility lock. */
32 #define LLL_MUTEX_LOCK_INITIALIZER (0)
34 extern int __lll_mutex_lock_wait (int val, int *__futex) attribute_hidden;
35 extern int __lll_mutex_timedlock_wait (int val, int *__futex,
36 const struct timespec *abstime)
38 extern int __lll_mutex_unlock_wake (int *__futex) attribute_hidden;
41 #define lll_mutex_trylock(futex) \
42 ({ unsigned char __result; \
56 : "=r" (__result) : "r" (&(futex)), "r" (1), "r" (0) \
57 : "r0", "r1", "r2", "t", "memory"); \
60 #define lll_mutex_lock(futex) \
61 (void) ({ int __result, val, *__futex = &(futex); \
71 : "=&r" (__result), "=&r" (val) : "r" (__futex), "1" (1) \
72 : "r0", "r1", "memory"); \
74 __lll_mutex_lock_wait (__result, __futex); })
76 #define lll_mutex_timedlock(futex, timeout) \
77 ({ int __result, val, *__futex = &(futex); \
87 : "=&r" (__result), "=&r" (val) : "r" (__futex), "1" (1) \
88 : "r0", "r1", "memory"); \
90 __result = __lll_mutex_timedlock_wait (__result, __futex, timeout); \
93 #define lll_mutex_unlock(futex) \
94 (void) ({ int __result, *__futex = &(futex); \
104 : "=&r" (__result) : "r" (__futex) \
105 : "r0", "r1", "memory"); \
107 __lll_mutex_unlock_wake (__futex); })
109 #define lll_mutex_islocked(futex) \
113 /* We have a separate internal lock implementation which is not tied
114 to binary compatibility. */
116 /* Type for lock object. */
117 typedef int lll_lock_t;
119 /* Initializers for lock. */
120 #define LLL_LOCK_INITIALIZER (1)
121 #define LLL_LOCK_INITIALIZER_LOCKED (0)
124 extern int __lll_lock_wait (int val, int *__futex) attribute_hidden;
125 extern int __lll_unlock_wake (int *__futex) attribute_hidden;
126 extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
129 /* The states of a lock are:
131 0 - taken by one user
132 <0 - taken by more users */
135 #define lll_trylock(futex) \
136 ({ unsigned char __result; \
150 : "=r" (__result) : "r" (&(futex)), "r" (0), "r" (1) \
151 : "r0", "r1", "r2", "t", "memory"); \
154 #define lll_lock(futex) \
155 (void) ({ int __result, val, *__futex = &(futex); \
165 : "=&r" (__result), "=&r" (val) : "r" (__futex), "1" (-1) \
166 : "r0", "r1", "memory"); \
168 __lll_lock_wait (__result, __futex); })
170 #define lll_unlock(futex) \
171 (void) ({ int __result, *__futex = &(futex); \
181 : "=&r" (__result) : "r" (__futex) \
182 : "r0", "r1", "memory"); \
184 __lll_unlock_wake (__futex); })
186 #define lll_islocked(futex) \
190 /* The kernel notifies a process with uses CLONE_CLEARTID via futex
191 wakeup when the clone terminates. The memory location contains the
192 thread ID while the clone is running and is reset to zero
195 extern int __lll_wait_tid (int *tid) attribute_hidden;
196 #define lll_wait_tid(tid) \
198 __typeof (tid) *__tid = &(tid); \
200 __lll_wait_tid (__tid); \
203 extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
205 #define lll_timedwait_tid(tid, abstime) \
210 if (abstime == NULL || abstime->tv_nsec >= 1000000000) \
213 __result = __lll_timedwait_tid (&tid, abstime); \
218 extern int __lll_wake_tid (int *tid) attribute_hidden;
219 #define lll_wake_tid(tid) \
222 ___lll_wake_tid (&tid); \
226 /* Conditional variable handling. */
228 extern void __lll_cond_wait (pthread_cond_t *cond) attribute_hidden;
229 extern int __lll_cond_timedwait (pthread_cond_t *cond,
230 const struct timespec *abstime)
232 extern void __lll_cond_wake (pthread_cond_t *cond) attribute_hidden;
233 extern void __lll_cond_broadcast (pthread_cond_t *cond) attribute_hidden;
236 #define lll_cond_wait(cond) \
237 __lll_cond_wait (cond)
238 #define lll_cond_timedwait(cond, abstime) \
239 __lll_cond_timedwait (cond, abstime)
240 #define lll_cond_wake(cond) \
241 __lll_cond_wake (cond)
242 #define lll_cond_broadcast(cond) \
243 __lll_cond_broadcast (cond)
245 #endif /* lowlevellock.h */