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