1 /* Copyright (C) 2002, 2003 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
43 /* Get internal lock. */
52 cmpxchgl %esi, cond_lock(%rdi)
59 callq __lll_mutex_lock_wait
64 1: movl broadcast_seq(%rdi), %edx
82 callq __lll_mutex_unlock_wake
84 /* Wake up all waiters to make sure no signal gets lost. */
85 2: addq $wakeup_seq, %rdi
86 movq $FUTEX_WAKE, %rsi
87 movl $0x7fffffff, %edx
92 callq __pthread_mutex_cond_lock
95 .size __condvar_cleanup, .-__condvar_cleanup
98 /* int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) */
99 .globl __pthread_cond_wait
100 .type __pthread_cond_wait, @function
106 #define FRAME_SIZE 64
107 subq $FRAME_SIZE, %rsp
112 +--------------------------+
113 rsp + 32 | cleanup buffer |
114 +--------------------------+
115 rsp + 24 | old wake_seq value |
116 +--------------------------+
117 rsp + 16 | mutex pointer |
118 +--------------------------+
119 rsp + 8 | condvar pointer |
120 +--------------------------+
121 rsp + 4 | old broadcast_seq value |
122 +--------------------------+
123 rsp + 0 | old cancellation mode |
124 +--------------------------+
127 cmpq $-1, dep_mutex(%rdi)
129 /* Prepare structure passed to cancellation handler. */
134 movq %rsi, dep_mutex(%rdi)
136 /* Get internal lock. */
141 cmpxchgl %esi, (%rdi)
143 cmpxchgl %esi, cond_lock(%rdi)
147 /* Unlock the mutex. */
148 2: movq 16(%rsp), %rdi
150 callq __pthread_mutex_unlock_usercnt
158 /* Install cancellation handler. */
160 leaq __condvar_cleanup(%rip), %rsi
162 leaq __condvar_cleanup, %rsi
166 callq __pthread_cleanup_push
168 /* Get and store current wakeup_seq value. */
170 movq wakeup_seq(%rdi), %r12
171 movl broadcast_seq(%rdi), %edx
184 4: callq __pthread_enable_asynccancel
190 addq $wakeup_seq-cond_lock, %rdi
191 movq $SYS_futex, %rax
192 movq %r10, %rsi /* movq $FUTEX_WAIT, %rsi */
196 callq __pthread_disable_asynccancel
204 cmpxchgl %esi, (%rdi)
206 cmpxchgl %esi, cond_lock(%rdi)
210 6: movl broadcast_seq(%rdi), %edx
212 movq woken_seq(%rdi), %rax
214 movq wakeup_seq(%rdi), %r12
236 /* Remove cancellation handler. */
237 11: movq 32+CLEANUP_PREV(%rsp), %rdx
238 movq %rdx, %fs:CLEANUP
241 callq __pthread_mutex_cond_lock
242 14: addq $FRAME_SIZE, %rsp
248 /* We return the result of the mutex_lock operation. */
251 /* Initial locking failed. */
255 addq $cond_lock, %rdi
257 callq __lll_mutex_lock_wait
260 /* Unlock in loop requires wakeup. */
263 addq $cond_lock, %rdi
265 callq __lll_mutex_unlock_wake
268 /* Locking in loop failed. */
271 addq $cond_lock, %rdi
273 callq __lll_mutex_lock_wait
275 subq $cond_lock, %rdi
279 /* Unlock after loop requires wakeup. */
282 addq $cond_lock, %rdi
284 callq __lll_mutex_unlock_wake
287 /* The initial unlocking of the mutex failed. */
299 addq $cond_lock, %rdi
301 callq __lll_mutex_unlock_wake
306 .size __pthread_cond_wait, .-__pthread_cond_wait
307 versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
311 .section .eh_frame,"a",@progbits
313 .long L(ENDCIE)-L(STARTCIE) # Length of the CIE.
316 .byte 1 # Version number.
318 .string "zR" # NUL-terminated augmentation
321 .ascii "\0" # NUL-terminated augmentation
324 .uleb128 1 # Code alignment factor.
325 .sleb128 -8 # Data alignment factor.
326 .byte 16 # Return address register
329 .uleb128 1 # Augmentation value length.
330 .byte 0x1b # Encoding: DW_EH_PE_pcrel
333 .byte 0x0c # DW_CFA_def_cfa
336 .byte 0x90 # DW_CFA_offset, column 0x8
341 .long .LENDFDE-.LSTARTFDE # Length of the FDE.
343 .long .LSTARTFDE-.LSTARTFRAME # CIE pointer.
345 .long .LSTARTCODE-. # PC-relative start address
348 .long .LSTARTCODE # Start address of the code.
350 .long .LENDCODE-.LSTARTCODE # Length of the code.
352 .uleb128 0 # No augmentation data.
354 .byte 0x40+.Lpush_r12-.LSTARTCODE # DW_CFA_advance_loc+N
355 .byte 14 # DW_CFA_def_cfa_offset
357 .byte 0x8c # DW_CFA_offset %r12
359 .byte 0x40+.Lsubq-.Lpush_r12 # DW_CFA_advance_loc+N
360 .byte 14 # DW_CFA_def_cfa_offset
361 .uleb128 16+FRAME_SIZE
362 .byte 2 # DW_CFA_advance_loc1
364 .byte 14 # DW_CFA_def_cfa_offset
366 .byte 0x40+.Lpop_r12-.Laddq # DW_CFA_advance_loc+N
367 .byte 14 # DW_CFA_def_cfa_offset
369 .byte 0xcc # DW_CFA_restore %r12
370 .byte 0x40+.LSbl1-.Lpop_r12 # DW_CFA_advance_loc+N
371 .byte 14 # DW_CFA_def_cfa_offset
373 .byte 0x8c # DW_CFA_offset %r12