.
[glibc.git] / nptl / sysdeps / unix / sysv / linux / x86_64 / lowlevellock.h
blob97085bf018656cd5e30d1a0aa1e0bde122ef00ba
1 /* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _LOWLEVELLOCK_H
21 #define _LOWLEVELLOCK_H 1
23 #include <time.h>
24 #include <sys/param.h>
25 #include <bits/pthreadtypes.h>
27 #ifndef LOCK_INSTR
28 # ifdef UP
29 # define LOCK_INSTR /* nothing */
30 # else
31 # define LOCK_INSTR "lock;"
32 # endif
33 #endif
35 #define SYS_futex 202
36 #define FUTEX_WAIT 0
37 #define FUTEX_WAKE 1
38 #define FUTEX_LOCK_PI 6
39 #define FUTEX_UNLOCK_PI 7
40 #define FUTEX_TRYLOCK_PI 8
43 /* Initializer for compatibility lock. */
44 #define LLL_MUTEX_LOCK_INITIALIZER (0)
45 #define LLL_MUTEX_LOCK_INITIALIZER_LOCKED (1)
46 #define LLL_MUTEX_LOCK_INITIALIZER_WAITERS (2)
48 /* Delay in spinlock loop. */
49 #define BUSY_WAIT_NOP asm ("rep; nop")
52 #define LLL_STUB_UNWIND_INFO_START \
53 ".section .eh_frame,\"a\",@progbits\n" \
54 "7:\t" ".long 9f-8f # Length of Common Information Entry\n" \
55 "8:\t" ".long 0x0 # CIE Identifier Tag\n\t" \
56 ".byte 0x1 # CIE Version\n\t" \
57 ".ascii \"zR\\0\" # CIE Augmentation\n\t" \
58 ".uleb128 0x1 # CIE Code Alignment Factor\n\t" \
59 ".sleb128 -8 # CIE Data Alignment Factor\n\t" \
60 ".byte 0x10 # CIE RA Column\n\t" \
61 ".uleb128 0x1 # Augmentation size\n\t" \
62 ".byte 0x1b # FDE Encoding (pcrel sdata4)\n\t" \
63 ".byte 0x12 # DW_CFA_def_cfa_sf\n\t" \
64 ".uleb128 0x7\n\t" \
65 ".sleb128 16\n\t" \
66 ".align 8\n" \
67 "9:\t" ".long 23f-10f # FDE Length\n" \
68 "10:\t" ".long 10b-7b # FDE CIE offset\n\t" \
69 ".long 1b-. # FDE initial location\n\t" \
70 ".long 6b-1b # FDE address range\n\t" \
71 ".uleb128 0x0 # Augmentation size\n\t" \
72 ".byte 0x16 # DW_CFA_val_expression\n\t" \
73 ".uleb128 0x10\n\t" \
74 ".uleb128 12f-11f\n" \
75 "11:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
76 ".sleb128 4b-1b\n"
77 #define LLL_STUB_UNWIND_INFO_END \
78 ".byte 0x16 # DW_CFA_val_expression\n\t" \
79 ".uleb128 0x10\n\t" \
80 ".uleb128 14f-13f\n" \
81 "13:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
82 ".sleb128 4b-2b\n" \
83 "14:\t" ".byte 0x40 + (3b-2b) # DW_CFA_advance_loc\n\t" \
84 ".byte 0x0e # DW_CFA_def_cfa_offset\n\t" \
85 ".uleb128 0\n\t" \
86 ".byte 0x16 # DW_CFA_val_expression\n\t" \
87 ".uleb128 0x10\n\t" \
88 ".uleb128 16f-15f\n" \
89 "15:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
90 ".sleb128 4b-3b\n" \
91 "16:\t" ".byte 0x40 + (4b-3b-1) # DW_CFA_advance_loc\n\t" \
92 ".byte 0x0e # DW_CFA_def_cfa_offset\n\t" \
93 ".uleb128 128\n\t" \
94 ".byte 0x16 # DW_CFA_val_expression\n\t" \
95 ".uleb128 0x10\n\t" \
96 ".uleb128 20f-17f\n" \
97 "17:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
98 ".sleb128 19f-18f\n\t" \
99 ".byte 0x0d # DW_OP_const4s\n" \
100 "18:\t" ".4byte 4b-.\n\t" \
101 ".byte 0x1c # DW_OP_minus\n\t" \
102 ".byte 0x0d # DW_OP_const4s\n" \
103 "19:\t" ".4byte 24f-.\n\t" \
104 ".byte 0x22 # DW_OP_plus\n" \
105 "20:\t" ".byte 0x40 + (5b-4b+1) # DW_CFA_advance_loc\n\t" \
106 ".byte 0x13 # DW_CFA_def_cfa_offset_sf\n\t" \
107 ".sleb128 16\n\t" \
108 ".byte 0x16 # DW_CFA_val_expression\n\t" \
109 ".uleb128 0x10\n\t" \
110 ".uleb128 22f-21f\n" \
111 "21:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
112 ".sleb128 4b-5b\n" \
113 "22:\t" ".align 8\n" \
114 "23:\t" ".previous\n"
116 /* Unwind info for
117 1: leaq ..., %rdi
118 2: subq $128, %rsp
119 3: callq ...
120 4: addq $128, %rsp
121 5: jmp 24f
123 snippet. */
124 #define LLL_STUB_UNWIND_INFO_5 \
125 LLL_STUB_UNWIND_INFO_START \
126 "12:\t" ".byte 0x40 + (2b-1b) # DW_CFA_advance_loc\n\t" \
127 LLL_STUB_UNWIND_INFO_END
129 /* Unwind info for
130 1: leaq ..., %rdi
131 0: movq ..., %rdx
132 2: subq $128, %rsp
133 3: callq ...
134 4: addq $128, %rsp
135 5: jmp 24f
137 snippet. */
138 #define LLL_STUB_UNWIND_INFO_6 \
139 LLL_STUB_UNWIND_INFO_START \
140 "12:\t" ".byte 0x40 + (0b-1b) # DW_CFA_advance_loc\n\t" \
141 ".byte 0x16 # DW_CFA_val_expression\n\t" \
142 ".uleb128 0x10\n\t" \
143 ".uleb128 26f-25f\n" \
144 "25:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
145 ".sleb128 4b-0b\n" \
146 "26:\t" ".byte 0x40 + (2b-0b) # DW_CFA_advance_loc\n\t" \
147 LLL_STUB_UNWIND_INFO_END
150 #define lll_futex_wait(futex, val) \
151 ({ \
152 int __status; \
153 register __typeof (val) _val asm ("edx") = (val); \
154 __asm __volatile ("xorq %%r10, %%r10\n\t" \
155 "syscall" \
156 : "=a" (__status) \
157 : "0" (SYS_futex), "D" (futex), "S" (FUTEX_WAIT), \
158 "d" (_val) \
159 : "memory", "cc", "r10", "r11", "cx"); \
160 __status; \
164 #define lll_futex_timed_wait(futex, val, timeout) \
165 ({ \
166 register const struct timespec *__to __asm__ ("r10") = timeout; \
167 int __status; \
168 register __typeof (val) _val asm ("edx") = (val); \
169 __asm __volatile ("syscall" \
170 : "=a" (__status) \
171 : "0" (SYS_futex), "D" (futex), "S" (FUTEX_WAIT), \
172 "d" (_val), "r" (__to) \
173 : "memory", "cc", "r11", "cx"); \
174 __status; \
178 #define lll_futex_wake(futex, nr) \
179 do { \
180 int __ignore; \
181 register __typeof (nr) _nr asm ("edx") = (nr); \
182 __asm __volatile ("syscall" \
183 : "=a" (__ignore) \
184 : "0" (SYS_futex), "D" (futex), "S" (FUTEX_WAKE), \
185 "d" (_nr) \
186 : "memory", "cc", "r10", "r11", "cx"); \
187 } while (0)
190 /* Does not preserve %eax and %ecx. */
191 extern int __lll_mutex_lock_wait (int *__futex, int __val) attribute_hidden;
192 /* Does not preserver %eax, %ecx, and %edx. */
193 extern int __lll_mutex_timedlock_wait (int *__futex, int __val,
194 const struct timespec *__abstime)
195 attribute_hidden;
196 /* Preserves all registers but %eax. */
197 extern int __lll_mutex_unlock_wait (int *__futex) attribute_hidden;
200 /* NB: in the lll_mutex_trylock macro we simply return the value in %eax
201 after the cmpxchg instruction. In case the operation succeded this
202 value is zero. In case the operation failed, the cmpxchg instruction
203 has loaded the current value of the memory work which is guaranteed
204 to be nonzero. */
205 #define lll_mutex_trylock(futex) \
206 ({ int ret; \
207 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
208 : "=a" (ret), "=m" (futex) \
209 : "r" (LLL_MUTEX_LOCK_INITIALIZER_LOCKED), "m" (futex),\
210 "0" (LLL_MUTEX_LOCK_INITIALIZER) \
211 : "memory"); \
212 ret; })
215 #define lll_robust_mutex_trylock(futex, id) \
216 ({ int ret; \
217 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
218 : "=a" (ret), "=m" (futex) \
219 : "r" (id), "m" (futex), \
220 "0" (LLL_MUTEX_LOCK_INITIALIZER) \
221 : "memory"); \
222 ret; })
225 #define lll_mutex_cond_trylock(futex) \
226 ({ int ret; \
227 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
228 : "=a" (ret), "=m" (futex) \
229 : "r" (LLL_MUTEX_LOCK_INITIALIZER_WAITERS), \
230 "m" (futex), "0" (LLL_MUTEX_LOCK_INITIALIZER) \
231 : "memory"); \
232 ret; })
235 #define lll_mutex_lock(futex) \
236 (void) ({ int ignore1, ignore2, ignore3; \
237 __asm __volatile (LOCK_INSTR "cmpxchgl %0, %2\n\t" \
238 "jnz 1f\n\t" \
239 ".subsection 1\n\t" \
240 ".type _L_mutex_lock_%=, @function\n" \
241 "_L_mutex_lock_%=:\n" \
242 "1:\tleaq %2, %%rdi\n" \
243 "2:\tsubq $128, %%rsp\n" \
244 "3:\tcallq __lll_mutex_lock_wait\n" \
245 "4:\taddq $128, %%rsp\n" \
246 "5:\tjmp 24f\n" \
247 "6:\t.size _L_mutex_lock_%=, 6b-1b\n\t" \
248 ".previous\n" \
249 LLL_STUB_UNWIND_INFO_5 \
250 "24:" \
251 : "=S" (ignore1), "=&D" (ignore2), "=m" (futex),\
252 "=a" (ignore3) \
253 : "0" (1), "m" (futex), "3" (0) \
254 : "cx", "r11", "cc", "memory"); })
257 #define lll_robust_mutex_lock(futex, id) \
258 ({ int result, ignore1, ignore2; \
259 __asm __volatile (LOCK_INSTR "cmpxchgl %0, %2\n\t" \
260 "jnz 1f\n\t" \
261 ".subsection 1\n\t" \
262 ".type _L_robust_mutex_lock_%=, @function\n" \
263 "_L_robust_mutex_lock_%=:\n" \
264 "1:\tleaq %2, %%rdi\n" \
265 "2:\tsubq $128, %%rsp\n" \
266 "3:\tcallq __lll_robust_mutex_lock_wait\n" \
267 "4:\taddq $128, %%rsp\n" \
268 "5:\tjmp 24f\n" \
269 "6:\t.size _L_robust_mutex_lock_%=, 6b-1b\n\t" \
270 ".previous\n" \
271 LLL_STUB_UNWIND_INFO_5 \
272 "24:" \
273 : "=S" (ignore1), "=&D" (ignore2), "=m" (futex), \
274 "=a" (result) \
275 : "0" (id), "m" (futex), "3" (0) \
276 : "cx", "r11", "cc", "memory"); \
277 result; })
280 #define lll_mutex_cond_lock(futex) \
281 (void) ({ int ignore1, ignore2, ignore3; \
282 __asm __volatile (LOCK_INSTR "cmpxchgl %0, %2\n\t" \
283 "jnz 1f\n\t" \
284 ".subsection 1\n\t" \
285 ".type _L_mutex_cond_lock_%=, @function\n" \
286 "_L_mutex_cond_lock_%=:\n" \
287 "1:\tleaq %2, %%rdi\n" \
288 "2:\tsubq $128, %%rsp\n" \
289 "3:\tcallq __lll_mutex_lock_wait\n" \
290 "4:\taddq $128, %%rsp\n" \
291 "5:\tjmp 24f\n" \
292 "6:\t.size _L_mutex_cond_lock_%=, 6b-1b\n\t" \
293 ".previous\n" \
294 LLL_STUB_UNWIND_INFO_5 \
295 "24:" \
296 : "=S" (ignore1), "=&D" (ignore2), "=m" (futex),\
297 "=a" (ignore3) \
298 : "0" (2), "m" (futex), "3" (0) \
299 : "cx", "r11", "cc", "memory"); })
302 #define lll_robust_mutex_cond_lock(futex, id) \
303 ({ int result, ignore1, ignore2; \
304 __asm __volatile (LOCK_INSTR "cmpxchgl %0, %2\n\t" \
305 "jnz 1f\n\t" \
306 ".subsection 1\n\t" \
307 ".type _L_robust_mutex_cond_lock_%=, @function\n" \
308 "_L_robust_mutex_cond_lock_%=:\n" \
309 "1:\tleaq %2, %%rdi\n" \
310 "2:\tsubq $128, %%rsp\n" \
311 "3:\tcallq __lll_robust_mutex_lock_wait\n" \
312 "4:\taddq $128, %%rsp\n" \
313 "5:\tjmp 24f\n" \
314 "6:\t.size _L_robust_mutex_cond_lock_%=, 6b-1b\n\t" \
315 ".previous\n" \
316 LLL_STUB_UNWIND_INFO_5 \
317 "24:" \
318 : "=S" (ignore1), "=&D" (ignore2), "=m" (futex), \
319 "=a" (result) \
320 : "0" (id | FUTEX_WAITERS), "m" (futex), "3" (0) \
321 : "cx", "r11", "cc", "memory"); \
322 result; })
325 #define lll_mutex_timedlock(futex, timeout) \
326 ({ int result, ignore1, ignore2, ignore3; \
327 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %4\n\t" \
328 "jnz 1f\n\t" \
329 ".subsection 1\n\t" \
330 ".type _L_mutex_timedlock_%=, @function\n" \
331 "_L_mutex_timedlock_%=:\n" \
332 "1:\tleaq %4, %%rdi\n" \
333 "0:\tmovq %8, %%rdx\n" \
334 "2:\tsubq $128, %%rsp\n" \
335 "3:\tcallq __lll_mutex_timedlock_wait\n" \
336 "4:\taddq $128, %%rsp\n" \
337 "5:\tjmp 24f\n" \
338 "6:\t.size _L_mutex_timedlock_%=, 6b-1b\n\t" \
339 ".previous\n" \
340 LLL_STUB_UNWIND_INFO_6 \
341 "24:" \
342 : "=a" (result), "=&D" (ignore1), "=S" (ignore2), \
343 "=&d" (ignore3), "=m" (futex) \
344 : "0" (0), "2" (1), "m" (futex), "m" (timeout) \
345 : "memory", "cx", "cc", "r10", "r11"); \
346 result; })
349 #define lll_robust_mutex_timedlock(futex, timeout, id) \
350 ({ int result, ignore1, ignore2, ignore3; \
351 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %4\n\t" \
352 "jnz 1f\n\t" \
353 ".subsection 1\n\t" \
354 ".type _L_robust_mutex_timedlock_%=, @function\n" \
355 "_L_robust_mutex_timedlock_%=:\n" \
356 "1:\tleaq %4, %%rdi\n" \
357 "0:\tmovq %8, %%rdx\n" \
358 "2:\tsubq $128, %%rsp\n" \
359 "3:\tcallq __lll_robust_mutex_timedlock_wait\n" \
360 "4:\taddq $128, %%rsp\n" \
361 "5:\tjmp 24f\n" \
362 "6:\t.size _L_robust_mutex_timedlock_%=, 6b-1b\n\t" \
363 ".previous\n" \
364 LLL_STUB_UNWIND_INFO_6 \
365 "24:" \
366 : "=a" (result), "=&D" (ignore1), "=S" (ignore2), \
367 "=&d" (ignore3), "=m" (futex) \
368 : "0" (0), "2" (id), "m" (futex), "m" (timeout) \
369 : "memory", "cx", "cc", "r10", "r11"); \
370 result; })
373 #define lll_mutex_unlock(futex) \
374 (void) ({ int ignore; \
375 __asm __volatile (LOCK_INSTR "decl %0\n\t" \
376 "jne 1f\n\t" \
377 ".subsection 1\n\t" \
378 ".type _L_mutex_unlock_%=, @function\n" \
379 "_L_mutex_unlock_%=:\n" \
380 "1:\tleaq %0, %%rdi\n" \
381 "2:\tsubq $128, %%rsp\n" \
382 "3:\tcallq __lll_mutex_unlock_wake\n" \
383 "4:\taddq $128, %%rsp\n" \
384 "5:\tjmp 24f\n" \
385 "6:\t.size _L_mutex_unlock_%=, 6b-1b\n\t" \
386 ".previous\n" \
387 LLL_STUB_UNWIND_INFO_5 \
388 "24:" \
389 : "=m" (futex), "=&D" (ignore) \
390 : "m" (futex) \
391 : "ax", "cx", "r11", "cc", "memory"); })
394 #define lll_robust_mutex_unlock(futex) \
395 (void) ({ int ignore; \
396 __asm __volatile (LOCK_INSTR "andl %2, %0\n\t" \
397 "jne 1f\n\t" \
398 ".subsection 1\n\t" \
399 ".type _L_robust_mutex_unlock_%=, @function\n" \
400 "_L_robust_mutex_unlock_%=:\n" \
401 "1:\tleaq %0, %%rdi\n" \
402 "2:\tsubq $128, %%rsp\n" \
403 "3:\tcallq __lll_mutex_unlock_wake\n" \
404 "4:\taddq $128, %%rsp\n" \
405 "5:\tjmp 24f\n" \
406 "6:\t.size _L_robust_mutex_unlock_%=, 6b-1b\n\t"\
407 ".previous\n" \
408 LLL_STUB_UNWIND_INFO_5 \
409 "24:" \
410 : "=m" (futex), "=&D" (ignore) \
411 : "i" (FUTEX_WAITERS), "m" (futex) \
412 : "ax", "cx", "r11", "cc", "memory"); })
415 #define lll_robust_mutex_dead(futex) \
416 (void) ({ int ignore; \
417 __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t" \
418 "syscall" \
419 : "=m" (futex), "=a" (ignore) \
420 : "D" (&(futex)), "i" (FUTEX_OWNER_DIED), \
421 "S" (FUTEX_WAKE), "1" (__NR_futex), \
422 "d" (1) \
423 : "cx", "r11", "cc", "memory"); })
426 #define lll_mutex_islocked(futex) \
427 (futex != LLL_MUTEX_LOCK_INITIALIZER)
430 /* We have a separate internal lock implementation which is not tied
431 to binary compatibility. */
433 /* Type for lock object. */
434 typedef int lll_lock_t;
436 /* Initializers for lock. */
437 #define LLL_LOCK_INITIALIZER (0)
438 #define LLL_LOCK_INITIALIZER_LOCKED (1)
441 extern int lll_unlock_wake_cb (int *__futex) attribute_hidden;
444 /* The states of a lock are:
445 0 - untaken
446 1 - taken by one user
447 2 - taken by more users */
450 #if defined NOT_IN_libc || defined UP
451 # define lll_trylock(futex) lll_mutex_trylock (futex)
452 # define lll_lock(futex) lll_mutex_lock (futex)
453 # define lll_unlock(futex) lll_mutex_unlock (futex)
454 #else
455 /* Special versions of the macros for use in libc itself. They avoid
456 the lock prefix when the thread library is not used.
458 The code sequence to avoid unnecessary lock prefixes is what the AMD
459 guys suggested. If you do not like it, bring it up with AMD.
461 XXX In future we might even want to avoid it on UP machines. */
463 # define lll_trylock(futex) \
464 ({ unsigned char ret; \
465 __asm __volatile ("cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
466 "je 0f\n\t" \
467 "lock; cmpxchgl %2, %1\n\t" \
468 "jmp 1f\n" \
469 "0:\tcmpxchgl %2, %1\n\t" \
470 "1:setne %0" \
471 : "=a" (ret), "=m" (futex) \
472 : "r" (LLL_MUTEX_LOCK_INITIALIZER_LOCKED), "m" (futex),\
473 "0" (LLL_MUTEX_LOCK_INITIALIZER) \
474 : "memory"); \
475 ret; })
478 # define lll_lock(futex) \
479 (void) ({ int ignore1, ignore2, ignore3; \
480 __asm __volatile ("cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
481 "je 0f\n\t" \
482 "lock; cmpxchgl %0, %2\n\t" \
483 "jnz 1f\n\t" \
484 "jmp 24f\n" \
485 "0:\tcmpxchgl %0, %2\n\t" \
486 "jnz 1f\n\t" \
487 ".subsection 1\n\t" \
488 ".type _L_lock_%=, @function\n" \
489 "_L_lock_%=:\n" \
490 "1:\tleaq %2, %%rdi\n" \
491 "2:\tsubq $128, %%rsp\n" \
492 "3:\tcallq __lll_mutex_lock_wait\n" \
493 "4:\taddq $128, %%rsp\n" \
494 "5:\tjmp 24f\n" \
495 "6:\t.size _L_lock_%=, 6b-1b\n\t" \
496 ".previous\n" \
497 LLL_STUB_UNWIND_INFO_5 \
498 "24:" \
499 : "=S" (ignore1), "=&D" (ignore2), "=m" (futex),\
500 "=a" (ignore3) \
501 : "0" (1), "m" (futex), "3" (0) \
502 : "cx", "r11", "cc", "memory"); })
505 # define lll_unlock(futex) \
506 (void) ({ int ignore; \
507 __asm __volatile ("cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
508 "je 0f\n\t" \
509 "lock; decl %0\n\t" \
510 "jne 1f\n\t" \
511 "jmp 24f\n" \
512 "0:\tdecl %0\n\t" \
513 "jne 1f\n\t" \
514 ".subsection 1\n\t" \
515 ".type _L_unlock_%=, @function\n" \
516 "_L_unlock_%=:\n" \
517 "1:\tleaq %0, %%rdi\n" \
518 "2:\tsubq $128, %%rsp\n" \
519 "3:\tcallq __lll_mutex_unlock_wake\n" \
520 "4:\taddq $128, %%rsp\n" \
521 "5:\tjmp 24f\n" \
522 "6:\t.size _L_unlock_%=, 6b-1b\n\t" \
523 ".previous\n" \
524 LLL_STUB_UNWIND_INFO_5 \
525 "24:" \
526 : "=m" (futex), "=&D" (ignore) \
527 : "m" (futex) \
528 : "ax", "cx", "r11", "cc", "memory"); })
529 #endif
532 #define lll_islocked(futex) \
533 (futex != LLL_MUTEX_LOCK_INITIALIZER)
536 /* The kernel notifies a process with uses CLONE_CLEARTID via futex
537 wakeup when the clone terminates. The memory location contains the
538 thread ID while the clone is running and is reset to zero
539 afterwards.
541 The macro parameter must not have any side effect. */
542 #define lll_wait_tid(tid) \
543 do { \
544 int __ignore; \
545 register __typeof (tid) _tid asm ("edx") = (tid); \
546 if (_tid != 0) \
547 __asm __volatile ("xorq %%r10, %%r10\n\t" \
548 "1:\tmovq %2, %%rax\n\t" \
549 "syscall\n\t" \
550 "cmpl $0, (%%rdi)\n\t" \
551 "jne 1b" \
552 : "=&a" (__ignore) \
553 : "S" (FUTEX_WAIT), "i" (SYS_futex), "D" (&tid), \
554 "d" (_tid) \
555 : "memory", "cc", "r10", "r11", "cx"); \
556 } while (0)
558 extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
559 attribute_hidden;
560 #define lll_timedwait_tid(tid, abstime) \
561 ({ \
562 int __result = 0; \
563 if (tid != 0) \
565 if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) \
566 __result = EINVAL; \
567 else \
568 __result = __lll_timedwait_tid (&tid, abstime); \
570 __result; })
573 /* Conditional variable handling. */
575 extern void __lll_cond_wait (pthread_cond_t *cond) attribute_hidden;
576 extern int __lll_cond_timedwait (pthread_cond_t *cond,
577 const struct timespec *abstime)
578 attribute_hidden;
579 extern void __lll_cond_wake (pthread_cond_t *cond) attribute_hidden;
580 extern void __lll_cond_broadcast (pthread_cond_t *cond) attribute_hidden;
583 #define lll_cond_wait(cond) \
584 __lll_cond_wait (cond)
585 #define lll_cond_timedwait(cond, abstime) \
586 __lll_cond_timedwait (cond, abstime)
587 #define lll_cond_wake(cond) \
588 __lll_cond_wake (cond)
589 #define lll_cond_broadcast(cond) \
590 __lll_cond_broadcast (cond)
593 #endif /* lowlevellock.h */