1 /* Copyright (C) 2002, 2003, 2004, 2006, 2007 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>
30 /* int pthread_cond_broadcast (pthread_cond_t *cond) */
31 .globl __pthread_cond_broadcast
32 .type __pthread_cond_broadcast, @function
34 __pthread_cond_broadcast:
37 cfi_adjust_cfa_offset(4)
39 cfi_adjust_cfa_offset(4)
41 cfi_adjust_cfa_offset(4)
43 cfi_adjust_cfa_offset(4)
51 /* Get internal lock. */
58 cmpxchgl %edx, cond_lock(%ebx)
62 2: addl $cond_futex, %ebx
63 movl total_seq+4-cond_futex(%ebx), %eax
64 movl total_seq-cond_futex(%ebx), %ebp
65 cmpl wakeup_seq+4-cond_futex(%ebx), %eax
68 cmpl wakeup_seq-cond_futex(%ebx), %ebp
71 /* Cause all currently waiting threads to recognize they are
73 3: movl %ebp, wakeup_seq-cond_futex(%ebx)
74 movl %eax, wakeup_seq-cond_futex+4(%ebx)
75 movl %ebp, woken_seq-cond_futex(%ebx)
76 movl %eax, woken_seq-cond_futex+4(%ebx)
78 addl $1, broadcast_seq-cond_futex(%ebx)
81 /* Get the address of the mutex used. */
82 movl dep_mutex-cond_futex(%ebx), %edi
86 subl $1, cond_lock-cond_futex(%ebx)
89 /* Don't use requeue for pshared condvars. */
93 /* XXX: The kernel so far doesn't support requeue to PI futex. */
94 /* XXX: The kernel only supports FUTEX_CMP_REQUEUE to the same
95 type of futex (private resp. shared). */
96 testl $(PI_BIT | PS_BIT), MUTEX_KIND(%edi)
99 /* Wake up all threads. */
100 #ifdef __ASSUME_PRIVATE_FUTEX
101 movl $(FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG), %ecx
103 movl %gs:PRIVATE_FUTEX, %ecx
104 orl $FUTEX_CMP_REQUEUE, %ecx
106 movl $SYS_futex, %eax
107 movl $0x7fffffff, %esi
109 /* Get the address of the futex involved. */
110 # if MUTEX_FUTEX != 0
111 addl $MUTEX_FUTEX, %edi
113 /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for sysenter.
117 /* For any kind of error, which mainly is EAGAIN, we try again
118 with WAKE. The general test also covers running on old
120 cmpl $0xfffff001, %eax
125 cfi_adjust_cfa_offset(-4)
128 cfi_adjust_cfa_offset(-4)
131 cfi_adjust_cfa_offset(-4)
134 cfi_adjust_cfa_offset(-4)
136 popl %ecx; nacljmp %ecx
138 cfi_adjust_cfa_offset(16)
140 cfi_offset(%esi, -12)
141 cfi_offset(%edi, -16)
142 cfi_offset(%ebp, -20)
146 subl $1, cond_lock-cond_futex(%ebx)
151 cfi_adjust_cfa_offset(-4)
154 cfi_adjust_cfa_offset(-4)
157 cfi_adjust_cfa_offset(-4)
160 cfi_adjust_cfa_offset(-4)
162 popl %ecx; nacljmp %ecx
164 cfi_adjust_cfa_offset(16)
166 cfi_offset(%esi, -12)
167 cfi_offset(%edi, -16)
168 cfi_offset(%ebp, -20)
169 /* Initial locking failed. */
174 leal cond_lock(%ebx), %edx
176 #if (LLL_SHARED-LLL_PRIVATE) > 255
179 cmpl $-1, dep_mutex(%ebx)
182 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
184 addl $LLL_PRIVATE, %ecx
189 /* Unlock in loop requires waekup. */
190 5: leal cond_lock-cond_futex(%ebx), %eax
191 #if (LLL_SHARED-LLL_PRIVATE) > 255
194 cmpl $-1, dep_mutex-cond_futex(%ebx)
197 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
199 addl $LLL_PRIVATE, %ecx
201 call __lll_unlock_wake
204 /* Unlock in loop requires waekup. */
205 7: leal cond_lock-cond_futex(%ebx), %eax
206 #if (LLL_SHARED-LLL_PRIVATE) > 255
209 cmpl $-1, dep_mutex-cond_futex(%ebx)
212 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
214 addl $LLL_PRIVATE, %ecx
216 call __lll_unlock_wake
219 9: /* The futex requeue functionality is not available. */
220 movl $0x7fffffff, %edx
221 #if FUTEX_PRIVATE_FLAG > 255
224 cmpl $-1, dep_mutex-cond_futex(%ebx)
227 #ifdef __ASSUME_PRIVATE_FUTEX
228 andl $FUTEX_PRIVATE_FLAG, %ecx
230 andl %gs:PRIVATE_FUTEX, %ecx
232 addl $FUTEX_WAKE, %ecx
233 movl $SYS_futex, %eax
237 .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
238 versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,