Update copyright notices with scripts/update-copyrights
[glibc.git] / nptl / sysdeps / unix / sysv / linux / i386 / lowlevellock.h
blob44ef4190b556b14df58d3d315572afda46cf9487
1 /* Copyright (C) 2002-2014 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 240
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
74 #if !defined NOT_IN_libc || defined IS_IN_rtld
75 /* In libc.so or ld.so all futexes are private. */
76 # ifdef __ASSUME_PRIVATE_FUTEX
77 # define __lll_private_flag(fl, private) \
78 ((fl) | FUTEX_PRIVATE_FLAG)
79 # else
80 # define __lll_private_flag(fl, private) \
81 ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))
82 # endif
83 #else
84 # ifdef __ASSUME_PRIVATE_FUTEX
85 # define __lll_private_flag(fl, private) \
86 (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
87 # else
88 # define __lll_private_flag(fl, private) \
89 (__builtin_constant_p (private) \
90 ? ((private) == 0 \
91 ? ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex)) \
92 : (fl)) \
93 : ({ unsigned int __fl = ((private) ^ FUTEX_PRIVATE_FLAG); \
94 asm ("andl %%gs:%P1, %0" : "+r" (__fl) \
95 : "i" (offsetof (struct pthread, header.private_futex))); \
96 __fl | (fl); }))
97 # endif
98 #endif
100 #ifndef __ASSEMBLER__
102 /* Initializer for compatibility lock. */
103 #define LLL_LOCK_INITIALIZER (0)
104 #define LLL_LOCK_INITIALIZER_LOCKED (1)
105 #define LLL_LOCK_INITIALIZER_WAITERS (2)
108 #ifdef PIC
109 # define LLL_EBX_LOAD "xchgl %2, %%ebx\n"
110 # define LLL_EBX_REG "D"
111 #else
112 # define LLL_EBX_LOAD
113 # define LLL_EBX_REG "b"
114 #endif
116 #ifdef I386_USE_SYSENTER
117 # ifdef SHARED
118 # define LLL_ENTER_KERNEL "call *%%gs:%P6\n\t"
119 # else
120 # define LLL_ENTER_KERNEL "call *_dl_sysinfo\n\t"
121 # endif
122 #else
123 # define LLL_ENTER_KERNEL "int $0x80\n\t"
124 #endif
126 /* Delay in spinlock loop. */
127 #define BUSY_WAIT_NOP asm ("rep; nop")
130 #define LLL_STUB_UNWIND_INFO_START \
131 ".section .eh_frame,\"a\",@progbits\n" \
132 "5:\t" ".long 7f-6f # Length of Common Information Entry\n" \
133 "6:\t" ".long 0x0 # CIE Identifier Tag\n\t" \
134 ".byte 0x1 # CIE Version\n\t" \
135 ".ascii \"zR\\0\" # CIE Augmentation\n\t" \
136 ".uleb128 0x1 # CIE Code Alignment Factor\n\t" \
137 ".sleb128 -4 # CIE Data Alignment Factor\n\t" \
138 ".byte 0x8 # CIE RA Column\n\t" \
139 ".uleb128 0x1 # Augmentation size\n\t" \
140 ".byte 0x1b # FDE Encoding (pcrel sdata4)\n\t" \
141 ".byte 0xc # DW_CFA_def_cfa\n\t" \
142 ".uleb128 0x4\n\t" \
143 ".uleb128 0x0\n\t" \
144 ".align 4\n" \
145 "7:\t" ".long 17f-8f # FDE Length\n" \
146 "8:\t" ".long 8b-5b # FDE CIE offset\n\t" \
147 ".long 1b-. # FDE initial location\n\t" \
148 ".long 4b-1b # FDE address range\n\t" \
149 ".uleb128 0x0 # Augmentation size\n\t" \
150 ".byte 0x16 # DW_CFA_val_expression\n\t" \
151 ".uleb128 0x8\n\t" \
152 ".uleb128 10f-9f\n" \
153 "9:\t" ".byte 0x78 # DW_OP_breg8\n\t" \
154 ".sleb128 3b-1b\n"
155 #define LLL_STUB_UNWIND_INFO_END \
156 ".byte 0x16 # DW_CFA_val_expression\n\t" \
157 ".uleb128 0x8\n\t" \
158 ".uleb128 12f-11f\n" \
159 "11:\t" ".byte 0x78 # DW_OP_breg8\n\t" \
160 ".sleb128 3b-2b\n" \
161 "12:\t" ".byte 0x40 + (3b-2b-1) # DW_CFA_advance_loc\n\t" \
162 ".byte 0x16 # DW_CFA_val_expression\n\t" \
163 ".uleb128 0x8\n\t" \
164 ".uleb128 16f-13f\n" \
165 "13:\t" ".byte 0x78 # DW_OP_breg8\n\t" \
166 ".sleb128 15f-14f\n\t" \
167 ".byte 0x0d # DW_OP_const4s\n" \
168 "14:\t" ".4byte 3b-.\n\t" \
169 ".byte 0x1c # DW_OP_minus\n\t" \
170 ".byte 0x0d # DW_OP_const4s\n" \
171 "15:\t" ".4byte 18f-.\n\t" \
172 ".byte 0x22 # DW_OP_plus\n" \
173 "16:\t" ".align 4\n" \
174 "17:\t" ".previous\n"
176 /* Unwind info for
177 1: lea ..., ...
178 2: call ...
179 3: jmp 18f
181 snippet. */
182 #define LLL_STUB_UNWIND_INFO_3 \
183 LLL_STUB_UNWIND_INFO_START \
184 "10:\t" ".byte 0x40 + (2b-1b) # DW_CFA_advance_loc\n\t" \
185 LLL_STUB_UNWIND_INFO_END
187 /* Unwind info for
188 1: lea ..., ...
189 0: movl ..., ...
190 2: call ...
191 3: jmp 18f
193 snippet. */
194 #define LLL_STUB_UNWIND_INFO_4 \
195 LLL_STUB_UNWIND_INFO_START \
196 "10:\t" ".byte 0x40 + (0b-1b) # DW_CFA_advance_loc\n\t" \
197 ".byte 0x16 # DW_CFA_val_expression\n\t" \
198 ".uleb128 0x8\n\t" \
199 ".uleb128 20f-19f\n" \
200 "19:\t" ".byte 0x78 # DW_OP_breg8\n\t" \
201 ".sleb128 3b-0b\n" \
202 "20:\t" ".byte 0x40 + (2b-0b) # DW_CFA_advance_loc\n\t" \
203 LLL_STUB_UNWIND_INFO_END
206 #define lll_futex_wait(futex, val, private) \
207 lll_futex_timed_wait (futex, val, NULL, private)
210 #define lll_futex_timed_wait(futex, val, timeout, private) \
211 ({ \
212 int __status; \
213 register __typeof (val) _val asm ("edx") = (val); \
214 __asm __volatile (LLL_EBX_LOAD \
215 LLL_ENTER_KERNEL \
216 LLL_EBX_LOAD \
217 : "=a" (__status) \
218 : "0" (SYS_futex), LLL_EBX_REG (futex), "S" (timeout), \
219 "c" (__lll_private_flag (FUTEX_WAIT, private)), \
220 "d" (_val), "i" (offsetof (tcbhead_t, sysinfo)) \
221 : "memory"); \
222 __status; \
226 #define lll_futex_wake(futex, nr, private) \
227 ({ \
228 int __status; \
229 register __typeof (nr) _nr asm ("edx") = (nr); \
230 LIBC_PROBE (lll_futex_wake, 3, futex, nr, private); \
231 __asm __volatile (LLL_EBX_LOAD \
232 LLL_ENTER_KERNEL \
233 LLL_EBX_LOAD \
234 : "=a" (__status) \
235 : "0" (SYS_futex), LLL_EBX_REG (futex), \
236 "c" (__lll_private_flag (FUTEX_WAKE, private)), \
237 "d" (_nr), \
238 "i" (0) /* phony, to align next arg's number */, \
239 "i" (offsetof (tcbhead_t, sysinfo))); \
240 __status; \
244 /* NB: in the lll_trylock macro we simply return the value in %eax
245 after the cmpxchg instruction. In case the operation succeded this
246 value is zero. In case the operation failed, the cmpxchg instruction
247 has loaded the current value of the memory work which is guaranteed
248 to be nonzero. */
249 #if defined NOT_IN_libc || defined UP
250 # define __lll_trylock_asm LOCK_INSTR "cmpxchgl %2, %1"
251 #else
252 # define __lll_trylock_asm "cmpl $0, %%gs:%P5\n\t" \
253 "je 0f\n\t" \
254 "lock\n" \
255 "0:\tcmpxchgl %2, %1"
256 #endif
258 #define lll_trylock(futex) \
259 ({ int ret; \
260 __asm __volatile (__lll_trylock_asm \
261 : "=a" (ret), "=m" (futex) \
262 : "r" (LLL_LOCK_INITIALIZER_LOCKED), "m" (futex), \
263 "0" (LLL_LOCK_INITIALIZER), \
264 "i" (MULTIPLE_THREADS_OFFSET) \
265 : "memory"); \
266 ret; })
268 #define lll_robust_trylock(futex, id) \
269 ({ int ret; \
270 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
271 : "=a" (ret), "=m" (futex) \
272 : "r" (id), "m" (futex), \
273 "0" (LLL_LOCK_INITIALIZER) \
274 : "memory"); \
275 ret; })
278 #define lll_cond_trylock(futex) \
279 ({ int ret; \
280 __asm __volatile (LOCK_INSTR "cmpxchgl %2, %1" \
281 : "=a" (ret), "=m" (futex) \
282 : "r" (LLL_LOCK_INITIALIZER_WAITERS), \
283 "m" (futex), "0" (LLL_LOCK_INITIALIZER) \
284 : "memory"); \
285 ret; })
287 #if defined NOT_IN_libc || defined UP
288 # define __lll_lock_asm_start LOCK_INSTR "cmpxchgl %1, %2\n\t"
289 #else
290 # define __lll_lock_asm_start "cmpl $0, %%gs:%P6\n\t" \
291 "je 0f\n\t" \
292 "lock\n" \
293 "0:\tcmpxchgl %1, %2\n\t"
294 #endif
296 #define lll_lock(futex, private) \
297 (void) \
298 ({ int ignore1, ignore2; \
299 if (__builtin_constant_p (private) && (private) == LLL_PRIVATE) \
300 __asm __volatile (__lll_lock_asm_start \
301 "jnz _L_lock_%=\n\t" \
302 ".subsection 1\n\t" \
303 ".type _L_lock_%=,@function\n" \
304 "_L_lock_%=:\n" \
305 "1:\tleal %2, %%ecx\n" \
306 "2:\tcall __lll_lock_wait_private\n" \
307 "3:\tjmp 18f\n" \
308 "4:\t.size _L_lock_%=, 4b-1b\n\t" \
309 ".previous\n" \
310 LLL_STUB_UNWIND_INFO_3 \
311 "18:" \
312 : "=a" (ignore1), "=c" (ignore2), "=m" (futex) \
313 : "0" (0), "1" (1), "m" (futex), \
314 "i" (MULTIPLE_THREADS_OFFSET) \
315 : "memory"); \
316 else \
318 int ignore3; \
319 __asm __volatile (__lll_lock_asm_start \
320 "jnz _L_lock_%=\n\t" \
321 ".subsection 1\n\t" \
322 ".type _L_lock_%=,@function\n" \
323 "_L_lock_%=:\n" \
324 "1:\tleal %2, %%edx\n" \
325 "0:\tmovl %8, %%ecx\n" \
326 "2:\tcall __lll_lock_wait\n" \
327 "3:\tjmp 18f\n" \
328 "4:\t.size _L_lock_%=, 4b-1b\n\t" \
329 ".previous\n" \
330 LLL_STUB_UNWIND_INFO_4 \
331 "18:" \
332 : "=a" (ignore1), "=c" (ignore2), \
333 "=m" (futex), "=&d" (ignore3) \
334 : "1" (1), "m" (futex), \
335 "i" (MULTIPLE_THREADS_OFFSET), "0" (0), \
336 "g" ((int) (private)) \
337 : "memory"); \
341 #define lll_robust_lock(futex, id, private) \
342 ({ int result, ignore1, ignore2; \
343 __asm __volatile (LOCK_INSTR "cmpxchgl %1, %2\n\t" \
344 "jnz _L_robust_lock_%=\n\t" \
345 ".subsection 1\n\t" \
346 ".type _L_robust_lock_%=,@function\n" \
347 "_L_robust_lock_%=:\n" \
348 "1:\tleal %2, %%edx\n" \
349 "0:\tmovl %7, %%ecx\n" \
350 "2:\tcall __lll_robust_lock_wait\n" \
351 "3:\tjmp 18f\n" \
352 "4:\t.size _L_robust_lock_%=, 4b-1b\n\t" \
353 ".previous\n" \
354 LLL_STUB_UNWIND_INFO_4 \
355 "18:" \
356 : "=a" (result), "=c" (ignore1), "=m" (futex), \
357 "=&d" (ignore2) \
358 : "0" (0), "1" (id), "m" (futex), "g" ((int) (private))\
359 : "memory"); \
360 result; })
363 /* Special version of lll_lock which causes the unlock function to
364 always wakeup waiters. */
365 #define lll_cond_lock(futex, private) \
366 (void) \
367 ({ int ignore1, ignore2, ignore3; \
368 __asm __volatile (LOCK_INSTR "cmpxchgl %1, %2\n\t" \
369 "jnz _L_cond_lock_%=\n\t" \
370 ".subsection 1\n\t" \
371 ".type _L_cond_lock_%=,@function\n" \
372 "_L_cond_lock_%=:\n" \
373 "1:\tleal %2, %%edx\n" \
374 "0:\tmovl %7, %%ecx\n" \
375 "2:\tcall __lll_lock_wait\n" \
376 "3:\tjmp 18f\n" \
377 "4:\t.size _L_cond_lock_%=, 4b-1b\n\t" \
378 ".previous\n" \
379 LLL_STUB_UNWIND_INFO_4 \
380 "18:" \
381 : "=a" (ignore1), "=c" (ignore2), "=m" (futex), \
382 "=&d" (ignore3) \
383 : "0" (0), "1" (2), "m" (futex), "g" ((int) (private))\
384 : "memory"); \
388 #define lll_robust_cond_lock(futex, id, private) \
389 ({ int result, ignore1, ignore2; \
390 __asm __volatile (LOCK_INSTR "cmpxchgl %1, %2\n\t" \
391 "jnz _L_robust_cond_lock_%=\n\t" \
392 ".subsection 1\n\t" \
393 ".type _L_robust_cond_lock_%=,@function\n" \
394 "_L_robust_cond_lock_%=:\n" \
395 "1:\tleal %2, %%edx\n" \
396 "0:\tmovl %7, %%ecx\n" \
397 "2:\tcall __lll_robust_lock_wait\n" \
398 "3:\tjmp 18f\n" \
399 "4:\t.size _L_robust_cond_lock_%=, 4b-1b\n\t" \
400 ".previous\n" \
401 LLL_STUB_UNWIND_INFO_4 \
402 "18:" \
403 : "=a" (result), "=c" (ignore1), "=m" (futex), \
404 "=&d" (ignore2) \
405 : "0" (0), "1" (id | FUTEX_WAITERS), "m" (futex), \
406 "g" ((int) (private)) \
407 : "memory"); \
408 result; })
411 #define lll_timedlock(futex, timeout, private) \
412 ({ int result, ignore1, ignore2, ignore3; \
413 __asm __volatile (LOCK_INSTR "cmpxchgl %1, %3\n\t" \
414 "jnz _L_timedlock_%=\n\t" \
415 ".subsection 1\n\t" \
416 ".type _L_timedlock_%=,@function\n" \
417 "_L_timedlock_%=:\n" \
418 "1:\tleal %3, %%ecx\n" \
419 "0:\tmovl %8, %%edx\n" \
420 "2:\tcall __lll_timedlock_wait\n" \
421 "3:\tjmp 18f\n" \
422 "4:\t.size _L_timedlock_%=, 4b-1b\n\t" \
423 ".previous\n" \
424 LLL_STUB_UNWIND_INFO_4 \
425 "18:" \
426 : "=a" (result), "=c" (ignore1), "=&d" (ignore2), \
427 "=m" (futex), "=S" (ignore3) \
428 : "0" (0), "1" (1), "m" (futex), "m" (timeout), \
429 "4" ((int) (private)) \
430 : "memory"); \
431 result; })
433 extern int __lll_timedlock_elision (int *futex, short *adapt_count,
434 const struct timespec *timeout,
435 int private) attribute_hidden;
437 #define lll_timedlock_elision(futex, adapt_count, timeout, private) \
438 __lll_timedlock_elision(&(futex), &(adapt_count), timeout, private)
440 #define lll_robust_timedlock(futex, timeout, id, private) \
441 ({ int result, ignore1, ignore2, ignore3; \
442 __asm __volatile (LOCK_INSTR "cmpxchgl %1, %3\n\t" \
443 "jnz _L_robust_timedlock_%=\n\t" \
444 ".subsection 1\n\t" \
445 ".type _L_robust_timedlock_%=,@function\n" \
446 "_L_robust_timedlock_%=:\n" \
447 "1:\tleal %3, %%ecx\n" \
448 "0:\tmovl %8, %%edx\n" \
449 "2:\tcall __lll_robust_timedlock_wait\n" \
450 "3:\tjmp 18f\n" \
451 "4:\t.size _L_robust_timedlock_%=, 4b-1b\n\t" \
452 ".previous\n" \
453 LLL_STUB_UNWIND_INFO_4 \
454 "18:" \
455 : "=a" (result), "=c" (ignore1), "=&d" (ignore2), \
456 "=m" (futex), "=S" (ignore3) \
457 : "0" (0), "1" (id), "m" (futex), "m" (timeout), \
458 "4" ((int) (private)) \
459 : "memory"); \
460 result; })
462 #if defined NOT_IN_libc || defined UP
463 # define __lll_unlock_asm LOCK_INSTR "subl $1, %0\n\t"
464 #else
465 # define __lll_unlock_asm "cmpl $0, %%gs:%P3\n\t" \
466 "je 0f\n\t" \
467 "lock\n" \
468 "0:\tsubl $1,%0\n\t"
469 #endif
471 #define lll_unlock(futex, private) \
472 (void) \
473 ({ int ignore; \
474 if (__builtin_constant_p (private) && (private) == LLL_PRIVATE) \
475 __asm __volatile (__lll_unlock_asm \
476 "jne _L_unlock_%=\n\t" \
477 ".subsection 1\n\t" \
478 ".type _L_unlock_%=,@function\n" \
479 "_L_unlock_%=:\n" \
480 "1:\tleal %0, %%eax\n" \
481 "2:\tcall __lll_unlock_wake_private\n" \
482 "3:\tjmp 18f\n" \
483 "4:\t.size _L_unlock_%=, 4b-1b\n\t" \
484 ".previous\n" \
485 LLL_STUB_UNWIND_INFO_3 \
486 "18:" \
487 : "=m" (futex), "=&a" (ignore) \
488 : "m" (futex), "i" (MULTIPLE_THREADS_OFFSET) \
489 : "memory"); \
490 else \
492 int ignore2; \
493 __asm __volatile (__lll_unlock_asm \
494 "jne _L_unlock_%=\n\t" \
495 ".subsection 1\n\t" \
496 ".type _L_unlock_%=,@function\n" \
497 "_L_unlock_%=:\n" \
498 "1:\tleal %0, %%eax\n" \
499 "0:\tmovl %5, %%ecx\n" \
500 "2:\tcall __lll_unlock_wake\n" \
501 "3:\tjmp 18f\n" \
502 "4:\t.size _L_unlock_%=, 4b-1b\n\t" \
503 ".previous\n" \
504 LLL_STUB_UNWIND_INFO_4 \
505 "18:" \
506 : "=m" (futex), "=&a" (ignore), "=&c" (ignore2) \
507 : "i" (MULTIPLE_THREADS_OFFSET), "m" (futex), \
508 "g" ((int) (private)) \
509 : "memory"); \
513 #define lll_robust_unlock(futex, private) \
514 (void) \
515 ({ int ignore, ignore2; \
516 __asm __volatile (LOCK_INSTR "andl %3, %0\n\t" \
517 "jne _L_robust_unlock_%=\n\t" \
518 ".subsection 1\n\t" \
519 ".type _L_robust_unlock_%=,@function\n" \
520 "_L_robust_unlock_%=:\n\t" \
521 "1:\tleal %0, %%eax\n" \
522 "0:\tmovl %5, %%ecx\n" \
523 "2:\tcall __lll_unlock_wake\n" \
524 "3:\tjmp 18f\n" \
525 "4:\t.size _L_robust_unlock_%=, 4b-1b\n\t" \
526 ".previous\n" \
527 LLL_STUB_UNWIND_INFO_4 \
528 "18:" \
529 : "=m" (futex), "=&a" (ignore), "=&c" (ignore2) \
530 : "i" (FUTEX_WAITERS), "m" (futex), \
531 "g" ((int) (private)) \
532 : "memory"); \
536 #define lll_robust_dead(futex, private) \
537 (void) \
538 ({ int __ignore; \
539 register int _nr asm ("edx") = 1; \
540 __asm __volatile (LOCK_INSTR "orl %5, (%2)\n\t" \
541 LLL_EBX_LOAD \
542 LLL_ENTER_KERNEL \
543 LLL_EBX_LOAD \
544 : "=a" (__ignore) \
545 : "0" (SYS_futex), LLL_EBX_REG (&(futex)), \
546 "c" (__lll_private_flag (FUTEX_WAKE, private)), \
547 "d" (_nr), "i" (FUTEX_OWNER_DIED), \
548 "i" (offsetof (tcbhead_t, sysinfo))); \
551 #define lll_islocked(futex) \
552 (futex != LLL_LOCK_INITIALIZER)
554 /* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex
555 wakeup when the clone terminates. The memory location contains the
556 thread ID while the clone is running and is reset to zero
557 afterwards.
559 The macro parameter must not have any side effect. */
560 #define lll_wait_tid(tid) \
561 do { \
562 int __ignore; \
563 register __typeof (tid) _tid asm ("edx") = (tid); \
564 if (_tid != 0) \
565 __asm __volatile (LLL_EBX_LOAD \
566 "1:\tmovl %1, %%eax\n\t" \
567 LLL_ENTER_KERNEL \
568 "cmpl $0, (%%ebx)\n\t" \
569 "jne 1b\n\t" \
570 LLL_EBX_LOAD \
571 : "=&a" (__ignore) \
572 : "i" (SYS_futex), LLL_EBX_REG (&tid), "S" (0), \
573 "c" (FUTEX_WAIT), "d" (_tid), \
574 "i" (offsetof (tcbhead_t, sysinfo)) \
575 : "memory"); \
576 } while (0)
578 extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
579 __attribute__ ((regparm (2))) 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 extern int __lll_lock_elision (int *futex, short *adapt_count, int private)
593 attribute_hidden;
595 extern int __lll_unlock_elision(int *lock, int private)
596 attribute_hidden;
598 extern int __lll_trylock_elision(int *lock, short *adapt_count)
599 attribute_hidden;
601 #define lll_lock_elision(futex, adapt_count, private) \
602 __lll_lock_elision (&(futex), &(adapt_count), private)
603 #define lll_unlock_elision(futex, private) \
604 __lll_unlock_elision (&(futex), private)
605 #define lll_trylock_elision(futex, adapt_count) \
606 __lll_trylock_elision(&(futex), &(adapt_count))
608 #endif /* !__ASSEMBLER__ */
610 #endif /* lowlevellock.h */