1 /* Copyright (C) 2002, 2003, 2004 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
21 #include <shlib-compat.h>
22 #include <lowlevelcond.h>
23 #include <tcb-offsets.h>
39 .type __condvar_cleanup, @function
40 .globl __condvar_cleanup
41 .hidden __condvar_cleanup
45 /* Get internal lock. */
54 cmpxchgl %esi, cond_lock(%rdi)
61 callq __lll_mutex_lock_wait
66 1: movl broadcast_seq(%rdi), %edx
74 3: subl $(1 << clock_bits), cond_nwaiters(%rdi)
76 /* Wake up a thread which wants to destroy the condvar object. */
78 cmpq $0xffffffffffffffff, total_seq(%rdi)
80 movl cond_nwaiters(%rdi), %eax
81 andl $~((1 << clock_bits) - 1), %eax
84 addq $cond_nwaiters, %rdi
86 movq $FUTEX_WAKE, %rsi
89 subq $cond_nwaiters, %rdi
100 addq $cond_lock, %rdi
102 callq __lll_mutex_unlock_wake
104 /* Wake up all waiters to make sure no signal gets lost. */
107 addq $cond_futex, %rdi
108 movq $FUTEX_WAKE, %rsi
109 movl $0x7fffffff, %edx
110 movq $SYS_futex, %rax
113 5: movq 16(%r8), %rdi
114 callq __pthread_mutex_cond_lock
119 .size __condvar_cleanup, .-__condvar_cleanup
122 /* int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) */
123 .globl __pthread_cond_wait
124 .type __pthread_cond_wait, @function
130 #define FRAME_SIZE 64
131 subq $FRAME_SIZE, %rsp
136 +--------------------------+
137 rsp + 32 | cleanup buffer |
138 +--------------------------+
139 rsp + 24 | old wake_seq value |
140 +--------------------------+
141 rsp + 16 | mutex pointer |
142 +--------------------------+
143 rsp + 8 | condvar pointer |
144 +--------------------------+
145 rsp + 4 | old broadcast_seq value |
146 +--------------------------+
147 rsp + 0 | old cancellation mode |
148 +--------------------------+
151 cmpq $-1, dep_mutex(%rdi)
153 /* Prepare structure passed to cancellation handler. */
158 movq %rsi, dep_mutex(%rdi)
160 /* Get internal lock. */
165 cmpxchgl %esi, (%rdi)
167 cmpxchgl %esi, cond_lock(%rdi)
171 /* Unlock the mutex. */
172 2: movq 16(%rsp), %rdi
174 callq __pthread_mutex_unlock_usercnt
181 incl cond_futex(%rdi)
182 addl $(1 << clock_bits), cond_nwaiters(%rdi)
184 /* Install cancellation handler. */
186 leaq __condvar_cleanup(%rip), %rsi
188 leaq __condvar_cleanup, %rsi
192 callq __pthread_cleanup_push
194 /* Get and store current wakeup_seq value. */
196 movq wakeup_seq(%rdi), %r9
197 movl broadcast_seq(%rdi), %edx
202 8: movl cond_futex(%rdi), %r12d
211 4: callq __pthread_enable_asynccancel
217 addq $cond_futex-cond_lock, %rdi
218 movq $SYS_futex, %rax
219 movq %r10, %rsi /* movq $FUTEX_WAIT, %rsi */
223 callq __pthread_disable_asynccancel
231 cmpxchgl %esi, (%rdi)
233 cmpxchgl %esi, cond_lock(%rdi)
237 6: movl broadcast_seq(%rdi), %edx
239 movq woken_seq(%rdi), %rax
241 movq wakeup_seq(%rdi), %r9
255 16: subl $(1 << clock_bits), cond_nwaiters(%rdi)
257 /* Wake up a thread which wants to destroy the condvar object. */
258 cmpq $0xffffffffffffffff, total_seq(%rdi)
260 movl cond_nwaiters(%rdi), %eax
261 andl $~((1 << clock_bits) - 1), %eax
264 addq $cond_nwaiters, %rdi
265 movq $SYS_futex, %rax
266 movq $FUTEX_WAKE, %rsi
269 subq $cond_nwaiters, %rdi
279 /* Remove cancellation handler. */
280 11: movq 32+CLEANUP_PREV(%rsp), %rdx
281 movq %rdx, %fs:CLEANUP
284 callq __pthread_mutex_cond_lock
285 14: addq $FRAME_SIZE, %rsp
291 /* We return the result of the mutex_lock operation. */
294 /* Initial locking failed. */
298 addq $cond_lock, %rdi
300 callq __lll_mutex_lock_wait
303 /* Unlock in loop requires wakeup. */
306 addq $cond_lock, %rdi
308 callq __lll_mutex_unlock_wake
311 /* Locking in loop failed. */
314 addq $cond_lock, %rdi
316 callq __lll_mutex_lock_wait
318 subq $cond_lock, %rdi
322 /* Unlock after loop requires wakeup. */
325 addq $cond_lock, %rdi
327 callq __lll_mutex_unlock_wake
330 /* The initial unlocking of the mutex failed. */
342 addq $cond_lock, %rdi
344 callq __lll_mutex_unlock_wake
349 .size __pthread_cond_wait, .-__pthread_cond_wait
350 versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
354 .section .eh_frame,"a",@progbits
356 .long L(ENDCIE)-L(STARTCIE) # Length of the CIE.
359 .byte 1 # Version number.
361 .string "zR" # NUL-terminated augmentation
364 .ascii "\0" # NUL-terminated augmentation
367 .uleb128 1 # Code alignment factor.
368 .sleb128 -8 # Data alignment factor.
369 .byte 16 # Return address register
372 .uleb128 1 # Augmentation value length.
373 .byte 0x1b # Encoding: DW_EH_PE_pcrel
376 .byte 0x0c # DW_CFA_def_cfa
379 .byte 0x90 # DW_CFA_offset, column 0x8
384 .long .LENDFDE-.LSTARTFDE # Length of the FDE.
386 .long .LSTARTFDE-.LSTARTFRAME # CIE pointer.
388 .long .LSTARTCODE-. # PC-relative start address
391 .long .LSTARTCODE # Start address of the code.
393 .long .LENDCODE-.LSTARTCODE # Length of the code.
395 .uleb128 0 # No augmentation data.
397 .byte 0x40+.Lpush_r12-.LSTARTCODE # DW_CFA_advance_loc+N
398 .byte 14 # DW_CFA_def_cfa_offset
400 .byte 0x8c # DW_CFA_offset %r12
402 .byte 0x40+.Lsubq-.Lpush_r12 # DW_CFA_advance_loc+N
403 .byte 14 # DW_CFA_def_cfa_offset
404 .uleb128 16+FRAME_SIZE
405 .byte 3 # DW_CFA_advance_loc2
407 .byte 14 # DW_CFA_def_cfa_offset
409 .byte 0x40+.Lpop_r12-.Laddq # DW_CFA_advance_loc+N
410 .byte 14 # DW_CFA_def_cfa_offset
412 .byte 0xcc # DW_CFA_restore %r12
413 .byte 0x40+.LSbl1-.Lpop_r12 # DW_CFA_advance_loc+N
414 .byte 14 # DW_CFA_def_cfa_offset
416 .byte 0x8c # DW_CFA_offset %r12