Updated to fedora-glibc-20090102T2110
[glibc.git] / nptl / sysdeps / unix / sysv / linux / x86_64 / lowlevellock.h
blobf76d599c48226e601a5a9ea4adde4411a49326fd
1 /* Copyright (C) 2002-2004, 2006, 2007, 2008 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 #ifndef __ASSEMBLER__
24 # include <time.h>
25 # include <sys/param.h>
26 # include <bits/pthreadtypes.h>
27 # include <kernel-features.h>
28 # include <tcb-offsets.h>
30 # ifndef LOCK_INSTR
31 # ifdef UP
32 # define LOCK_INSTR /* nothing */
33 # else
34 # define LOCK_INSTR "lock;"
35 # endif
36 # endif
37 #else
38 # ifndef LOCK
39 # ifdef UP
40 # define LOCK
41 # else
42 # define LOCK lock
43 # endif
44 # endif
45 #endif
47 #define SYS_futex 202
48 #define FUTEX_WAIT 0
49 #define FUTEX_WAKE 1
50 #define FUTEX_CMP_REQUEUE 4
51 #define FUTEX_WAKE_OP 5
52 #define FUTEX_LOCK_PI 6
53 #define FUTEX_UNLOCK_PI 7
54 #define FUTEX_TRYLOCK_PI 8
55 #define FUTEX_WAIT_BITSET 9
56 #define FUTEX_WAKE_BITSET 10
57 #define FUTEX_PRIVATE_FLAG 128
59 #define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
61 /* Values for 'private' parameter of locking macros. Yes, the
62 definition seems to be backwards. But it is not. The bit will be
63 reversed before passing to the system call. */
64 #define LLL_PRIVATE 0
65 #define LLL_SHARED FUTEX_PRIVATE_FLAG
67 #ifndef __ASSEMBLER__
69 #if !defined NOT_IN_libc || defined IS_IN_rtld
70 /* In libc.so or ld.so all futexes are private. */
71 # ifdef __ASSUME_PRIVATE_FUTEX
72 # define __lll_private_flag(fl, private) \
73 ((fl) | FUTEX_PRIVATE_FLAG)
74 # else
75 # define __lll_private_flag(fl, private) \
76 ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))
77 # endif
78 #else
79 # ifdef __ASSUME_PRIVATE_FUTEX
80 # define __lll_private_flag(fl, private) \
81 (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
82 # else
83 # define __lll_private_flag(fl, private) \
84 (__builtin_constant_p (private) \
85 ? ((private) == 0 \
86 ? ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex)) \
87 : (fl)) \
88 : ({ unsigned int __fl = ((private) ^ FUTEX_PRIVATE_FLAG); \
89 asm ("andl %%fs:%P1, %0" : "+r" (__fl) \
90 : "i" (offsetof (struct pthread, header.private_futex))); \
91 __fl | (fl); }))
92 # endif
93 #endif
95 /* Initializer for lock. */
96 #define LLL_LOCK_INITIALIZER (0)
97 #define LLL_LOCK_INITIALIZER_LOCKED (1)
98 #define LLL_LOCK_INITIALIZER_WAITERS (2)
100 /* Delay in spinlock loop. */
101 #define BUSY_WAIT_NOP asm ("rep; nop")
104 #define LLL_STUB_UNWIND_INFO_START \
105 ".section .eh_frame,\"a\",@progbits\n" \
106 "7:\t" ".long 9f-8f # Length of Common Information Entry\n" \
107 "8:\t" ".long 0x0 # CIE Identifier Tag\n\t" \
108 ".byte 0x1 # CIE Version\n\t" \
109 ".ascii \"zR\\0\" # CIE Augmentation\n\t" \
110 ".uleb128 0x1 # CIE Code Alignment Factor\n\t" \
111 ".sleb128 -8 # CIE Data Alignment Factor\n\t" \
112 ".byte 0x10 # CIE RA Column\n\t" \
113 ".uleb128 0x1 # Augmentation size\n\t" \
114 ".byte 0x1b # FDE Encoding (pcrel sdata4)\n\t" \
115 ".byte 0x12 # DW_CFA_def_cfa_sf\n\t" \
116 ".uleb128 0x7\n\t" \
117 ".sleb128 16\n\t" \
118 ".align 8\n" \
119 "9:\t" ".long 23f-10f # FDE Length\n" \
120 "10:\t" ".long 10b-7b # FDE CIE offset\n\t" \
121 ".long 1b-. # FDE initial location\n\t" \
122 ".long 6b-1b # FDE address range\n\t" \
123 ".uleb128 0x0 # Augmentation size\n\t" \
124 ".byte 0x16 # DW_CFA_val_expression\n\t" \
125 ".uleb128 0x10\n\t" \
126 ".uleb128 12f-11f\n" \
127 "11:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
128 ".sleb128 4b-1b\n"
129 #define LLL_STUB_UNWIND_INFO_END \
130 ".byte 0x16 # DW_CFA_val_expression\n\t" \
131 ".uleb128 0x10\n\t" \
132 ".uleb128 14f-13f\n" \
133 "13:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
134 ".sleb128 4b-2b\n" \
135 "14:\t" ".byte 0x40 + (3b-2b) # DW_CFA_advance_loc\n\t" \
136 ".byte 0x0e # DW_CFA_def_cfa_offset\n\t" \
137 ".uleb128 0\n\t" \
138 ".byte 0x16 # DW_CFA_val_expression\n\t" \
139 ".uleb128 0x10\n\t" \
140 ".uleb128 16f-15f\n" \
141 "15:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
142 ".sleb128 4b-3b\n" \
143 "16:\t" ".byte 0x40 + (4b-3b-1) # DW_CFA_advance_loc\n\t" \
144 ".byte 0x0e # DW_CFA_def_cfa_offset\n\t" \
145 ".uleb128 128\n\t" \
146 ".byte 0x16 # DW_CFA_val_expression\n\t" \
147 ".uleb128 0x10\n\t" \
148 ".uleb128 20f-17f\n" \
149 "17:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
150 ".sleb128 19f-18f\n\t" \
151 ".byte 0x0d # DW_OP_const4s\n" \
152 "18:\t" ".4byte 4b-.\n\t" \
153 ".byte 0x1c # DW_OP_minus\n\t" \
154 ".byte 0x0d # DW_OP_const4s\n" \
155 "19:\t" ".4byte 24f-.\n\t" \
156 ".byte 0x22 # DW_OP_plus\n" \
157 "20:\t" ".byte 0x40 + (5b-4b+1) # DW_CFA_advance_loc\n\t" \
158 ".byte 0x13 # DW_CFA_def_cfa_offset_sf\n\t" \
159 ".sleb128 16\n\t" \
160 ".byte 0x16 # DW_CFA_val_expression\n\t" \
161 ".uleb128 0x10\n\t" \
162 ".uleb128 22f-21f\n" \
163 "21:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
164 ".sleb128 4b-5b\n" \
165 "22:\t" ".align 8\n" \
166 "23:\t" ".previous\n"
168 /* Unwind info for
169 1: leaq ..., %rdi
170 2: subq $128, %rsp
171 3: callq ...
172 4: addq $128, %rsp
173 5: jmp 24f
175 snippet. */
176 #define LLL_STUB_UNWIND_INFO_5 \
177 LLL_STUB_UNWIND_INFO_START \
178 "12:\t" ".byte 0x40 + (2b-1b) # DW_CFA_advance_loc\n\t" \
179 LLL_STUB_UNWIND_INFO_END
181 /* Unwind info for
182 1: leaq ..., %rdi
183 0: movq ..., %rdx
184 2: subq $128, %rsp
185 3: callq ...
186 4: addq $128, %rsp
187 5: jmp 24f
189 snippet. */
190 #define LLL_STUB_UNWIND_INFO_6 \
191 LLL_STUB_UNWIND_INFO_START \
192 "12:\t" ".byte 0x40 + (0b-1b) # DW_CFA_advance_loc\n\t" \
193 ".byte 0x16 # DW_CFA_val_expression\n\t" \
194 ".uleb128 0x10\n\t" \
195 ".uleb128 26f-25f\n" \
196 "25:\t" ".byte 0x80 # DW_OP_breg16\n\t" \
197 ".sleb128 4b-0b\n" \
198 "26:\t" ".byte 0x40 + (2b-0b) # DW_CFA_advance_loc\n\t" \
199 LLL_STUB_UNWIND_INFO_END
202 #define lll_futex_wait(futex, val, private) \
203 lll_futex_timed_wait(futex, val, NULL, private)
206 #define lll_futex_timed_wait(futex, val, timeout, private) \
207 ({ \
208 register const struct timespec *__to __asm ("r10") = timeout; \
209 int __status; \
210 register __typeof (val) _val __asm ("edx") = (val); \
211 __asm __volatile ("syscall" \
212 : "=a" (__status) \
213 : "0" (SYS_futex), "D" (futex), \
214 "S" (__lll_private_flag (FUTEX_WAIT, private)), \
215 "d" (_val), "r" (__to) \
216 : "memory", "cc", "r11", "cx"); \
217 __status; \
221 #define lll_futex_wake(futex, nr, private) \
222 do { \
223 int __ignore; \
224 register __typeof (nr) _nr __asm ("edx") = (nr); \
225 __asm __volatile ("syscall" \
226 : "=a" (__ignore) \
227 : "0" (SYS_futex), "D" (futex), \
228 "S" (__lll_private_flag (FUTEX_WAKE, private)), \
229 "d" (_nr) \
230 : "memory", "cc", "r10", "r11", "cx"); \
231 } while (0)
234 /* NB: in the lll_trylock macro we simply return the value in %eax
235 after the cmpxchg instruction. In case the operation succeded this
236 value is zero. In case the operation failed, the cmpxchg instruction
237 has loaded the current value of the memory work which is guaranteed
238 to be nonzero. */
239 #if defined NOT_IN_libc || defined UP
240 # define __lll_trylock_asm LOCK_INSTR "cmpxchgl %2, %1"
241 #else
242 # define __lll_trylock_asm "cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
243 "je 0f\n\t" \
244 "lock; cmpxchgl %2, %1\n\t" \
245 "jmp 1f\n\t" \
246 "0:\tcmpxchgl %2, %1\n\t" \
247 "1:"
248 #endif
250 #define lll_trylock(futex) \
251 ({ int ret; \
252 __asm __volatile (__lll_trylock_asm \
253 : "=a" (ret), "=m" (futex) \
254 : "r" (LLL_LOCK_INITIALIZER_LOCKED), "m" (futex), \
255 "0" (LLL_LOCK_INITIALIZER) \
256 : "memory"); \
257 ret; })
259 #define lll_robust_trylock(futex, id) \
260 ({ int ret; \
261 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
262 : "=a" (ret), "=m" (futex) \
263 : "r" (id), "m" (futex), "0" (LLL_LOCK_INITIALIZER) \
264 : "memory"); \
265 ret; })
267 #define lll_cond_trylock(futex) \
268 ({ int ret; \
269 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
270 : "=a" (ret), "=m" (futex) \
271 : "r" (LLL_LOCK_INITIALIZER_WAITERS), \
272 "m" (futex), "0" (LLL_LOCK_INITIALIZER) \
273 : "memory"); \
274 ret; })
276 #if defined NOT_IN_libc || defined UP
277 # define __lll_lock_asm_start LOCK_INSTR "cmpxchgl %4, %2\n\t" \
278 "jnz 1f\n\t"
279 #else
280 # define __lll_lock_asm_start "cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
281 "je 0f\n\t" \
282 "lock; cmpxchgl %4, %2\n\t" \
283 "jnz 1f\n\t" \
284 "jmp 24f\n" \
285 "0:\tcmpxchgl %4, %2\n\t" \
286 "jnz 1f\n\t"
287 #endif
289 #define lll_lock(futex, private) \
290 (void) \
291 ({ int ignore1, ignore2, ignore3; \
292 if (__builtin_constant_p (private) && (private) == LLL_PRIVATE) \
293 __asm __volatile (__lll_lock_asm_start \
294 ".subsection 1\n\t" \
295 ".type _L_lock_%=, @function\n" \
296 "_L_lock_%=:\n" \
297 "1:\tleaq %2, %%rdi\n" \
298 "2:\tsubq $128, %%rsp\n" \
299 "3:\tcallq __lll_lock_wait_private\n" \
300 "4:\taddq $128, %%rsp\n" \
301 "5:\tjmp 24f\n" \
302 "6:\t.size _L_lock_%=, 6b-1b\n\t" \
303 ".previous\n" \
304 LLL_STUB_UNWIND_INFO_5 \
305 "24:" \
306 : "=S" (ignore1), "=&D" (ignore2), "=m" (futex), \
307 "=a" (ignore3) \
308 : "0" (1), "m" (futex), "3" (0) \
309 : "cx", "r11", "cc", "memory"); \
310 else \
311 __asm __volatile (__lll_lock_asm_start \
312 ".subsection 1\n\t" \
313 ".type _L_lock_%=, @function\n" \
314 "_L_lock_%=:\n" \
315 "1:\tleaq %2, %%rdi\n" \
316 "2:\tsubq $128, %%rsp\n" \
317 "3:\tcallq __lll_lock_wait\n" \
318 "4:\taddq $128, %%rsp\n" \
319 "5:\tjmp 24f\n" \
320 "6:\t.size _L_lock_%=, 6b-1b\n\t" \
321 ".previous\n" \
322 LLL_STUB_UNWIND_INFO_5 \
323 "24:" \
324 : "=S" (ignore1), "=D" (ignore2), "=m" (futex), \
325 "=a" (ignore3) \
326 : "1" (1), "m" (futex), "3" (0), "0" (private) \
327 : "cx", "r11", "cc", "memory"); \
328 }) \
330 #define lll_robust_lock(futex, id, private) \
331 ({ int result, ignore1, ignore2; \
332 __asm __volatile (LOCK_INSTR "cmpxchgl %4, %2\n\t" \
333 "jnz 1f\n\t" \
334 ".subsection 1\n\t" \
335 ".type _L_robust_lock_%=, @function\n" \
336 "_L_robust_lock_%=:\n" \
337 "1:\tleaq %2, %%rdi\n" \
338 "2:\tsubq $128, %%rsp\n" \
339 "3:\tcallq __lll_robust_lock_wait\n" \
340 "4:\taddq $128, %%rsp\n" \
341 "5:\tjmp 24f\n" \
342 "6:\t.size _L_robust_lock_%=, 6b-1b\n\t" \
343 ".previous\n" \
344 LLL_STUB_UNWIND_INFO_5 \
345 "24:" \
346 : "=S" (ignore1), "=D" (ignore2), "=m" (futex), \
347 "=a" (result) \
348 : "1" (id), "m" (futex), "3" (0), "0" (private) \
349 : "cx", "r11", "cc", "memory"); \
350 result; })
352 #define lll_cond_lock(futex, private) \
353 (void) \
354 ({ int ignore1, ignore2, ignore3; \
355 __asm __volatile (LOCK_INSTR "cmpxchgl %4, %2\n\t" \
356 "jnz 1f\n\t" \
357 ".subsection 1\n\t" \
358 ".type _L_cond_lock_%=, @function\n" \
359 "_L_cond_lock_%=:\n" \
360 "1:\tleaq %2, %%rdi\n" \
361 "2:\tsubq $128, %%rsp\n" \
362 "3:\tcallq __lll_lock_wait\n" \
363 "4:\taddq $128, %%rsp\n" \
364 "5:\tjmp 24f\n" \
365 "6:\t.size _L_cond_lock_%=, 6b-1b\n\t" \
366 ".previous\n" \
367 LLL_STUB_UNWIND_INFO_5 \
368 "24:" \
369 : "=S" (ignore1), "=D" (ignore2), "=m" (futex), \
370 "=a" (ignore3) \
371 : "1" (2), "m" (futex), "3" (0), "0" (private) \
372 : "cx", "r11", "cc", "memory"); \
375 #define lll_robust_cond_lock(futex, id, private) \
376 ({ int result, ignore1, ignore2; \
377 __asm __volatile (LOCK_INSTR "cmpxchgl %4, %2\n\t" \
378 "jnz 1f\n\t" \
379 ".subsection 1\n\t" \
380 ".type _L_robust_cond_lock_%=, @function\n" \
381 "_L_robust_cond_lock_%=:\n" \
382 "1:\tleaq %2, %%rdi\n" \
383 "2:\tsubq $128, %%rsp\n" \
384 "3:\tcallq __lll_robust_lock_wait\n" \
385 "4:\taddq $128, %%rsp\n" \
386 "5:\tjmp 24f\n" \
387 "6:\t.size _L_robust_cond_lock_%=, 6b-1b\n\t" \
388 ".previous\n" \
389 LLL_STUB_UNWIND_INFO_5 \
390 "24:" \
391 : "=S" (ignore1), "=D" (ignore2), "=m" (futex), \
392 "=a" (result) \
393 : "1" (id | FUTEX_WAITERS), "m" (futex), "3" (0), \
394 "0" (private) \
395 : "cx", "r11", "cc", "memory"); \
396 result; })
398 #define lll_timedlock(futex, timeout, private) \
399 ({ int result, ignore1, ignore2, ignore3; \
400 __asm __volatile (LOCK_INSTR "cmpxchgl %1, %4\n\t" \
401 "jnz 1f\n\t" \
402 ".subsection 1\n\t" \
403 ".type _L_timedlock_%=, @function\n" \
404 "_L_timedlock_%=:\n" \
405 "1:\tleaq %4, %%rdi\n" \
406 "0:\tmovq %8, %%rdx\n" \
407 "2:\tsubq $128, %%rsp\n" \
408 "3:\tcallq __lll_timedlock_wait\n" \
409 "4:\taddq $128, %%rsp\n" \
410 "5:\tjmp 24f\n" \
411 "6:\t.size _L_timedlock_%=, 6b-1b\n\t" \
412 ".previous\n" \
413 LLL_STUB_UNWIND_INFO_6 \
414 "24:" \
415 : "=a" (result), "=D" (ignore1), "=S" (ignore2), \
416 "=&d" (ignore3), "=m" (futex) \
417 : "0" (0), "1" (1), "m" (futex), "m" (timeout), \
418 "2" (private) \
419 : "memory", "cx", "cc", "r10", "r11"); \
420 result; })
422 #define lll_robust_timedlock(futex, timeout, id, private) \
423 ({ int result, ignore1, ignore2, ignore3; \
424 __asm __volatile (LOCK_INSTR "cmpxchgl %1, %4\n\t" \
425 "jnz 1f\n\t" \
426 ".subsection 1\n\t" \
427 ".type _L_robust_timedlock_%=, @function\n" \
428 "_L_robust_timedlock_%=:\n" \
429 "1:\tleaq %4, %%rdi\n" \
430 "0:\tmovq %8, %%rdx\n" \
431 "2:\tsubq $128, %%rsp\n" \
432 "3:\tcallq __lll_robust_timedlock_wait\n" \
433 "4:\taddq $128, %%rsp\n" \
434 "5:\tjmp 24f\n" \
435 "6:\t.size _L_robust_timedlock_%=, 6b-1b\n\t" \
436 ".previous\n" \
437 LLL_STUB_UNWIND_INFO_6 \
438 "24:" \
439 : "=a" (result), "=D" (ignore1), "=S" (ignore2), \
440 "=&d" (ignore3), "=m" (futex) \
441 : "0" (0), "1" (id), "m" (futex), "m" (timeout), \
442 "2" (private) \
443 : "memory", "cx", "cc", "r10", "r11"); \
444 result; })
446 #if defined NOT_IN_libc || defined UP
447 # define __lll_unlock_asm_start LOCK_INSTR "decl %0\n\t" \
448 "jne 1f\n\t"
449 #else
450 # define __lll_unlock_asm_start "cmpl $0, __libc_multiple_threads(%%rip)\n\t" \
451 "je 0f\n\t" \
452 "lock; decl %0\n\t" \
453 "jne 1f\n\t" \
454 "jmp 24f\n\t" \
455 "0:\tdecl %0\n\t" \
456 "jne 1f\n\t"
457 #endif
459 #define lll_unlock(futex, private) \
460 (void) \
461 ({ int ignore; \
462 if (__builtin_constant_p (private) && (private) == LLL_PRIVATE) \
463 __asm __volatile (__lll_unlock_asm_start \
464 ".subsection 1\n\t" \
465 ".type _L_unlock_%=, @function\n" \
466 "_L_unlock_%=:\n" \
467 "1:\tleaq %0, %%rdi\n" \
468 "2:\tsubq $128, %%rsp\n" \
469 "3:\tcallq __lll_unlock_wake_private\n" \
470 "4:\taddq $128, %%rsp\n" \
471 "5:\tjmp 24f\n" \
472 "6:\t.size _L_unlock_%=, 6b-1b\n\t" \
473 ".previous\n" \
474 LLL_STUB_UNWIND_INFO_5 \
475 "24:" \
476 : "=m" (futex), "=&D" (ignore) \
477 : "m" (futex) \
478 : "ax", "cx", "r11", "cc", "memory"); \
479 else \
480 __asm __volatile (__lll_unlock_asm_start \
481 ".subsection 1\n\t" \
482 ".type _L_unlock_%=, @function\n" \
483 "_L_unlock_%=:\n" \
484 "1:\tleaq %0, %%rdi\n" \
485 "2:\tsubq $128, %%rsp\n" \
486 "3:\tcallq __lll_unlock_wake\n" \
487 "4:\taddq $128, %%rsp\n" \
488 "5:\tjmp 24f\n" \
489 "6:\t.size _L_unlock_%=, 6b-1b\n\t" \
490 ".previous\n" \
491 LLL_STUB_UNWIND_INFO_5 \
492 "24:" \
493 : "=m" (futex), "=&D" (ignore) \
494 : "m" (futex), "S" (private) \
495 : "ax", "cx", "r11", "cc", "memory"); \
498 #define lll_robust_unlock(futex, private) \
499 do \
501 int ignore; \
502 __asm __volatile (LOCK_INSTR "andl %2, %0\n\t" \
503 "jne 1f\n\t" \
504 ".subsection 1\n\t" \
505 ".type _L_robust_unlock_%=, @function\n" \
506 "_L_robust_unlock_%=:\n" \
507 "1:\tleaq %0, %%rdi\n" \
508 "2:\tsubq $128, %%rsp\n" \
509 "3:\tcallq __lll_unlock_wake\n" \
510 "4:\taddq $128, %%rsp\n" \
511 "5:\tjmp 24f\n" \
512 "6:\t.size _L_robust_unlock_%=, 6b-1b\n\t" \
513 ".previous\n" \
514 LLL_STUB_UNWIND_INFO_5 \
515 "24:" \
516 : "=m" (futex), "=&D" (ignore) \
517 : "i" (FUTEX_WAITERS), "m" (futex), \
518 "S" (private) \
519 : "ax", "cx", "r11", "cc", "memory"); \
521 while (0)
523 #define lll_robust_dead(futex, private) \
524 do \
526 int ignore; \
527 __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t" \
528 "syscall" \
529 : "=m" (futex), "=a" (ignore) \
530 : "D" (&(futex)), "i" (FUTEX_OWNER_DIED), \
531 "S" (__lll_private_flag (FUTEX_WAKE, private)), \
532 "1" (__NR_futex), "d" (1) \
533 : "cx", "r11", "cc", "memory"); \
535 while (0)
537 /* Returns non-zero if error happened, zero if success. */
538 #define lll_futex_requeue(ftx, nr_wake, nr_move, mutex, val, private) \
539 ({ int __res; \
540 register int __nr_move __asm ("r10") = nr_move; \
541 register void *__mutex __asm ("r8") = mutex; \
542 register int __val __asm ("r9") = val; \
543 __asm __volatile ("syscall" \
544 : "=a" (__res) \
545 : "0" (__NR_futex), "D" ((void *) ftx), \
546 "S" (__lll_private_flag (FUTEX_CMP_REQUEUE, \
547 private)), "d" (nr_wake), \
548 "r" (__nr_move), "r" (__mutex), "r" (__val) \
549 : "cx", "r11", "cc", "memory"); \
550 __res < 0; })
552 #define lll_islocked(futex) \
553 (futex != LLL_LOCK_INITIALIZER)
556 /* The kernel notifies a process with uses CLONE_CLEARTID via futex
557 wakeup when the clone terminates. The memory location contains the
558 thread ID while the clone is running and is reset to zero
559 afterwards.
561 The macro parameter must not have any side effect. */
562 #define lll_wait_tid(tid) \
563 do { \
564 int __ignore; \
565 register __typeof (tid) _tid asm ("edx") = (tid); \
566 if (_tid != 0) \
567 __asm __volatile ("xorq %%r10, %%r10\n\t" \
568 "1:\tmovq %2, %%rax\n\t" \
569 "syscall\n\t" \
570 "cmpl $0, (%%rdi)\n\t" \
571 "jne 1b" \
572 : "=&a" (__ignore) \
573 : "S" (FUTEX_WAIT), "i" (SYS_futex), "D" (&tid), \
574 "d" (_tid) \
575 : "memory", "cc", "r10", "r11", "cx"); \
576 } while (0)
578 extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
579 attribute_hidden;
580 #define lll_timedwait_tid(tid, abstime) \
581 ({ \
582 int __result = 0; \
583 if (tid != 0) \
585 if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) \
586 __result = EINVAL; \
587 else \
588 __result = __lll_timedwait_tid (&tid, abstime); \
590 __result; })
592 #endif /* !__ASSEMBLER__ */
594 #endif /* lowlevellock.h */