1 /* Copyright (C) 2002-2005,2007,2009,2010 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 <lowlevellock.h>
23 #include <lowlevelcond.h>
24 #include <kernel-features.h>
25 #include <pthread-pi-defines.h>
26 #include <pthread-errnos.h>
31 /* int pthread_cond_signal (pthread_cond_t *cond) */
32 .globl __pthread_cond_signal
33 .type __pthread_cond_signal, @function
35 __pthread_cond_signal:
39 cfi_adjust_cfa_offset(4)
40 cfi_rel_offset(%ebx, 0)
42 cfi_adjust_cfa_offset(4)
43 cfi_rel_offset(%edi, 0)
48 /* Get internal lock. */
55 cmpxchgl %edx, cond_lock(%edi)
59 2: leal cond_futex(%edi), %ebx
60 movl total_seq+4(%edi), %eax
61 movl total_seq(%edi), %ecx
62 cmpl wakeup_seq+4(%edi), %eax
64 /* Must use leal to preserve the flags. */
65 leal cond_lock(%edi), %edi
69 cmpl wakeup_seq-cond_futex(%ebx), %ecx
72 /* Bump the wakeup number. */
73 3: addl $1, wakeup_seq-cond_futex(%ebx)
74 adcl $0, wakeup_seq-cond_futex+4(%ebx)
77 /* Wake up one thread. */
79 cfi_adjust_cfa_offset(4)
80 cfi_rel_offset(%esi, 0)
82 cfi_adjust_cfa_offset(4)
83 cfi_rel_offset(%ebp, 0)
85 #if FUTEX_PRIVATE_FLAG > 255
88 cmpl $-1, dep_mutex-cond_futex(%ebx)
92 movl dep_mutex-cond_futex(%ebx), %edx
93 /* Requeue to a non-robust PI mutex if the PI bit is set and
94 the robust bit is not set. */
95 movl MUTEX_KIND(%edx), %eax
96 andl $(ROBUST_BIT|PI_BIT), %eax
101 #ifdef __ASSUME_PRIVATE_FUTEX
102 andl $FUTEX_PRIVATE_FLAG, %ecx
104 andl %gs:PRIVATE_FUTEX, %ecx
106 addl $FUTEX_WAKE_OP, %ecx
107 movl $SYS_futex, %eax
110 movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %ebp
111 /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for
116 cfi_adjust_cfa_offset(-4)
119 cfi_adjust_cfa_offset(-4)
122 /* For any kind of error, we try again with WAKE.
123 The general test also covers running on old kernels. */
129 cfi_adjust_cfa_offset(-4)
132 cfi_adjust_cfa_offset(-4)
138 9: movl $(FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %ecx
139 movl $SYS_futex, %eax
142 movl dep_mutex-cond_futex(%ebx), %edi
144 /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for
151 leal -cond_futex(%ebx), %edi
153 /* For any kind of error, we try again with WAKE.
154 The general test also covers running on old kernels. */
159 #ifdef __ASSUME_PRIVATE_FUTEX
160 andl $FUTEX_PRIVATE_FLAG, %ecx
162 andl %gs:PRIVATE_FUTEX, %ecx
164 orl $FUTEX_WAKE, %ecx
166 movl $SYS_futex, %eax
167 /* %edx should be 1 already from $FUTEX_WAKE_OP syscall.
171 /* Unlock. Note that at this point %edi always points to
177 /* Unlock in loop requires wakeup. */
179 #if (LLL_SHARED-LLL_PRIVATE) > 255
182 cmpl $-1, dep_mutex-cond_futex(%ebx)
185 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
187 addl $LLL_PRIVATE, %ecx
189 call __lll_unlock_wake
192 /* Initial locking failed. */
197 leal cond_lock(%edi), %edx
199 #if (LLL_SHARED-LLL_PRIVATE) > 255
202 cmpl $-1, dep_mutex(%edi)
205 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
207 addl $LLL_PRIVATE, %ecx
213 .size __pthread_cond_signal, .-__pthread_cond_signal
214 versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal,