1 /* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
21 #include <lowlevellock.h>
22 #include <lowlevelcond.h>
23 #include <bits/kernel-features.h>
24 #include <pthread-pi-defines.h>
25 #include <pthread-errnos.h>
30 /* int pthread_cond_broadcast (pthread_cond_t *cond) */
31 .globl __pthread_cond_broadcast
32 .type __pthread_cond_broadcast, @function
33 .protected __pthread_cond_broadcast
35 __pthread_cond_broadcast:
37 /* Get internal lock. */
44 cmpxchgl %esi, cond_lock(%rdi)
48 2: addq $cond_futex, %rdi
49 movq total_seq-cond_futex(%rdi), %r9
50 cmpq wakeup_seq-cond_futex(%rdi), %r9
53 /* Cause all currently waiting threads to recognize they are
55 movq %r9, wakeup_seq-cond_futex(%rdi)
56 movq %r9, woken_seq-cond_futex(%rdi)
59 incl broadcast_seq-cond_futex(%rdi)
61 /* Get the address of the mutex used. */
62 movq dep_mutex-cond_futex(%rdi), %r8
66 decl cond_lock-cond_futex(%rdi)
72 /* Do not use requeue for pshared condvars. */
73 testl $PS_BIT, MUTEX_KIND(%r8)
76 /* Requeue to a PI mutex if the PI bit is set. */
77 movl MUTEX_KIND(%r8), %eax
78 andl $(ROBUST_BIT|PI_BIT), %eax
82 /* Wake up all threads. */
83 #ifdef __ASSUME_PRIVATE_FUTEX
84 movl $(FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG), %esi
86 movl %fs:PRIVATE_FUTEX, %esi
87 orl $FUTEX_CMP_REQUEUE, %esi
91 movl $0x7fffffff, %r10d
94 /* For any kind of error, which mainly is EAGAIN, we try again
95 with WAKE. The general test also covers running on old
103 /* Wake up all threads. */
104 81: movl $(FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
105 movl $SYS_futex, %eax
107 movl $0x7fffffff, %r10d
110 /* For any kind of error, which mainly is EAGAIN, we try again
111 with WAKE. The general test also covers running on old
120 decl cond_lock-cond_futex(%rdi)
126 /* Initial locking failed. */
129 addq $cond_lock, %rdi
131 cmpq $-1, dep_mutex-cond_lock(%rdi)
132 movl $LLL_PRIVATE, %eax
133 movl $LLL_SHARED, %esi
135 callq __lll_lock_wait
137 subq $cond_lock, %rdi
141 /* Unlock in loop requires wakeup. */
142 5: addq $cond_lock-cond_futex, %rdi
143 cmpq $-1, dep_mutex-cond_lock(%rdi)
144 movl $LLL_PRIVATE, %eax
145 movl $LLL_SHARED, %esi
147 callq __lll_unlock_wake
150 /* Unlock in loop requires wakeup. */
151 7: addq $cond_lock-cond_futex, %rdi
153 movl $LLL_PRIVATE, %eax
154 movl $LLL_SHARED, %esi
156 callq __lll_unlock_wake
157 subq $cond_lock-cond_futex, %rdi
160 9: /* The futex requeue functionality is not available. */
162 movl $0x7fffffff, %edx
163 #ifdef __ASSUME_PRIVATE_FUTEX
164 movl $FUTEX_WAKE, %eax
165 movl $(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
169 movl %fs:PRIVATE_FUTEX, %esi
171 orl $FUTEX_WAKE, %esi
173 movl $SYS_futex, %eax
176 .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
177 weak_alias(__pthread_cond_broadcast, pthread_cond_broadcast)