1 /* Copyright (C) 2002,2003,2004,2006,2007,2009 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/>. */
20 #include <lowlevellock.h>
21 #include <lowlevelcond.h>
22 #include <bits/kernel-features.h>
23 #include <pthread-pi-defines.h>
24 #include <pthread-errnos.h>
29 /* int pthread_cond_broadcast (pthread_cond_t *cond) */
30 .globl __pthread_cond_broadcast
31 .type __pthread_cond_broadcast, @function
32 .protected __pthread_cond_broadcast
34 __pthread_cond_broadcast:
37 cfi_adjust_cfa_offset(4)
38 cfi_rel_offset(%ebx, 0)
40 cfi_adjust_cfa_offset(4)
41 cfi_rel_offset(%esi, 0)
43 cfi_adjust_cfa_offset(4)
44 cfi_rel_offset(%edi, 0)
46 cfi_adjust_cfa_offset(4)
47 cfi_rel_offset(%ebp, 0)
52 /* Get internal lock. */
59 cmpxchgl %edx, cond_lock(%ebx)
63 2: addl $cond_futex, %ebx
64 movl total_seq+4-cond_futex(%ebx), %eax
65 movl total_seq-cond_futex(%ebx), %ebp
66 cmpl wakeup_seq+4-cond_futex(%ebx), %eax
69 cmpl wakeup_seq-cond_futex(%ebx), %ebp
72 /* Cause all currently waiting threads to recognize they are
74 3: movl %ebp, wakeup_seq-cond_futex(%ebx)
75 movl %eax, wakeup_seq-cond_futex+4(%ebx)
76 movl %ebp, woken_seq-cond_futex(%ebx)
77 movl %eax, woken_seq-cond_futex+4(%ebx)
79 addl $1, broadcast_seq-cond_futex(%ebx)
82 /* Get the address of the mutex used. */
83 movl dep_mutex-cond_futex(%ebx), %edi
87 subl $1, cond_lock-cond_futex(%ebx)
90 /* Don't use requeue for pshared condvars. */
94 /* Do not use requeue for pshared condvars. */
95 testl $PS_BIT, MUTEX_KIND(%edi)
98 /* Requeue to a non-robust PI mutex if the PI bit is set and
99 the robust bit is not set. */
100 movl MUTEX_KIND(%edi), %eax
101 andl $(ROBUST_BIT|PI_BIT), %eax
105 /* Wake up all threads. */
106 #ifdef __ASSUME_PRIVATE_FUTEX
107 movl $(FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG), %ecx
109 movl %gs:PRIVATE_FUTEX, %ecx
110 orl $FUTEX_CMP_REQUEUE, %ecx
112 movl $SYS_futex, %eax
113 movl $0x7fffffff, %esi
115 /* Get the address of the futex involved. */
116 # if MUTEX_FUTEX != 0
117 addl $MUTEX_FUTEX, %edi
119 /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for sysenter.
123 /* For any kind of error, which mainly is EAGAIN, we try again
124 with WAKE. The general test also covers running on old
126 cmpl $0xfffff001, %eax
131 cfi_adjust_cfa_offset(-4)
134 cfi_adjust_cfa_offset(-4)
137 cfi_adjust_cfa_offset(-4)
140 cfi_adjust_cfa_offset(-4)
146 81: movl $(FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %ecx
147 movl $SYS_futex, %eax
148 movl $0x7fffffff, %esi
150 /* Get the address of the futex involved. */
151 # if MUTEX_FUTEX != 0
152 addl $MUTEX_FUTEX, %edi
156 /* For any kind of error, which mainly is EAGAIN, we try again
157 with WAKE. The general test also covers running on old
159 cmpl $0xfffff001, %eax
163 /* Initial locking failed. */
168 leal cond_lock(%ebx), %edx
170 #if (LLL_SHARED-LLL_PRIVATE) > 255
173 cmpl $-1, dep_mutex(%ebx)
176 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
178 addl $LLL_PRIVATE, %ecx
186 subl $1, cond_lock-cond_futex(%ebx)
189 /* Unlock in loop requires wakeup. */
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 wakeup. */
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 weak_alias(__pthread_cond_broadcast, pthread_cond_broadcast)