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:
43 /* Get internal lock. */
50 cmpxchgl %edx, cond_lock(%ebx)
54 2: addl $cond_futex, %ebx
55 movl total_seq+4-cond_futex(%ebx), %eax
56 movl total_seq-cond_futex(%ebx), %ebp
57 cmpl wakeup_seq+4-cond_futex(%ebx), %eax
60 cmpl wakeup_seq-cond_futex(%ebx), %ebp
63 /* Cause all currently waiting threads to recognize they are
65 3: movl %ebp, wakeup_seq-cond_futex(%ebx)
66 movl %eax, wakeup_seq-cond_futex+4(%ebx)
67 movl %ebp, woken_seq-cond_futex(%ebx)
68 movl %eax, woken_seq-cond_futex+4(%ebx)
70 addl $1, broadcast_seq-cond_futex(%ebx)
73 /* Get the address of the mutex used. */
74 movl dep_mutex-cond_futex(%ebx), %edi
78 subl $1, cond_lock-cond_futex(%ebx)
81 /* Don't use requeue for pshared condvars. */
85 /* XXX: The kernel so far doesn't support requeue to PI futex. */
86 /* XXX: The kernel only supports FUTEX_CMP_REQUEUE to the same
87 type of futex (private resp. shared). */
88 testl $(PI_BIT | PS_BIT), MUTEX_KIND(%edi)
91 /* Wake up all threads. */
92 #ifdef __ASSUME_PRIVATE_FUTEX
93 movl $(FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG), %ecx
95 movl %gs:PRIVATE_FUTEX, %ecx
96 orl $FUTEX_CMP_REQUEUE, %ecx
99 movl $0x7fffffff, %esi
101 /* Get the address of the futex involved. */
102 # if MUTEX_FUTEX != 0
103 addl $MUTEX_FUTEX, %edi
105 /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for sysenter.
109 /* For any kind of error, which mainly is EAGAIN, we try again
110 with WAKE. The general test also covers running on old
112 cmpl $0xfffff001, %eax
125 subl $1, cond_lock-cond_futex(%ebx)
135 /* Initial locking failed. */
140 leal cond_lock(%ebx), %edx
142 #if (LLL_SHARED-LLL_PRIVATE) > 255
145 cmpl $-1, dep_mutex(%ebx)
148 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
150 addl $LLL_PRIVATE, %ecx
155 /* Unlock in loop requires waekup. */
156 5: leal cond_lock-cond_futex(%ebx), %eax
157 #if (LLL_SHARED-LLL_PRIVATE) > 255
160 cmpl $-1, dep_mutex-cond_futex(%ebx)
163 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
165 addl $LLL_PRIVATE, %ecx
167 call __lll_unlock_wake
170 /* Unlock in loop requires waekup. */
171 7: leal cond_lock-cond_futex(%ebx), %eax
172 #if (LLL_SHARED-LLL_PRIVATE) > 255
175 cmpl $-1, dep_mutex-cond_futex(%ebx)
178 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
180 addl $LLL_PRIVATE, %ecx
182 call __lll_unlock_wake
185 9: /* The futex requeue functionality is not available. */
186 movl $0x7fffffff, %edx
187 #if FUTEX_PRIVATE_FLAG > 255
190 cmpl $-1, dep_mutex-cond_futex(%ebx)
193 #ifdef __ASSUME_PRIVATE_FUTEX
194 andl $FUTEX_PRIVATE_FLAG, %ecx
196 andl %gs:PRIVATE_FUTEX, %ecx
198 addl $FUTEX_WAKE, %ecx
199 movl $SYS_futex, %eax
202 .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
203 versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,