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 <shlib-compat.h>
21 #include <lowlevellock.h>
22 #include <lowlevelcond.h>
23 #include <kernel-features.h>
24 #include <pthread-pi-defines.h>
25 #include <pthread-errnos.h>
29 /* int pthread_cond_broadcast (pthread_cond_t *cond) */
30 .globl __pthread_cond_broadcast
31 .type __pthread_cond_broadcast, @function
33 __pthread_cond_broadcast:
36 cfi_adjust_cfa_offset(4)
37 cfi_rel_offset(%ebx, 0)
39 cfi_adjust_cfa_offset(4)
40 cfi_rel_offset(%esi, 0)
42 cfi_adjust_cfa_offset(4)
43 cfi_rel_offset(%edi, 0)
45 cfi_adjust_cfa_offset(4)
46 cfi_rel_offset(%ebp, 0)
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 /* Do not use requeue for pshared condvars. */
94 testl $PS_BIT, MUTEX_KIND(%edi)
97 /* Requeue to a non-robust PI mutex if the PI bit is set and
98 the robust bit is not set. */
99 movl MUTEX_KIND(%edi), %eax
100 andl $(ROBUST_BIT|PI_BIT), %eax
104 /* Wake up all threads. */
105 #ifdef __ASSUME_PRIVATE_FUTEX
106 movl $(FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG), %ecx
108 movl %gs:PRIVATE_FUTEX, %ecx
109 orl $FUTEX_CMP_REQUEUE, %ecx
111 movl $SYS_futex, %eax
112 movl $0x7fffffff, %esi
114 /* Get the address of the futex involved. */
115 # if MUTEX_FUTEX != 0
116 addl $MUTEX_FUTEX, %edi
118 /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for sysenter.
122 /* For any kind of error, which mainly is EAGAIN, we try again
123 with WAKE. The general test also covers running on old
125 cmpl $0xfffff001, %eax
130 cfi_adjust_cfa_offset(-4)
133 cfi_adjust_cfa_offset(-4)
136 cfi_adjust_cfa_offset(-4)
139 cfi_adjust_cfa_offset(-4)
145 81: movl $(FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %ecx
146 movl $SYS_futex, %eax
147 movl $0x7fffffff, %esi
149 /* Get the address of the futex involved. */
150 # if MUTEX_FUTEX != 0
151 addl $MUTEX_FUTEX, %edi
155 /* For any kind of error, which mainly is EAGAIN, we try again
156 with WAKE. The general test also covers running on old
158 cmpl $0xfffff001, %eax
162 /* Initial locking failed. */
167 leal cond_lock(%ebx), %edx
169 #if (LLL_SHARED-LLL_PRIVATE) > 255
172 cmpl $-1, dep_mutex(%ebx)
175 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
177 addl $LLL_PRIVATE, %ecx
185 subl $1, cond_lock-cond_futex(%ebx)
188 /* Unlock in loop requires wakeup. */
189 5: leal cond_lock-cond_futex(%ebx), %eax
190 #if (LLL_SHARED-LLL_PRIVATE) > 255
193 cmpl $-1, dep_mutex-cond_futex(%ebx)
196 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
198 addl $LLL_PRIVATE, %ecx
200 call __lll_unlock_wake
203 /* Unlock in loop requires wakeup. */
204 7: leal cond_lock-cond_futex(%ebx), %eax
205 #if (LLL_SHARED-LLL_PRIVATE) > 255
208 cmpl $-1, dep_mutex-cond_futex(%ebx)
211 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
213 addl $LLL_PRIVATE, %ecx
215 call __lll_unlock_wake
218 9: /* The futex requeue functionality is not available. */
219 movl $0x7fffffff, %edx
220 #if FUTEX_PRIVATE_FLAG > 255
223 cmpl $-1, dep_mutex-cond_futex(%ebx)
226 #ifdef __ASSUME_PRIVATE_FUTEX
227 andl $FUTEX_PRIVATE_FLAG, %ecx
229 andl %gs:PRIVATE_FUTEX, %ecx
231 addl $FUTEX_WAKE, %ecx
232 movl $SYS_futex, %eax
236 .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
237 versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,