1 /* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <shlib-compat.h>
23 #include <lowlevellock.h>
24 #include <lowlevelcond.h>
25 #include <kernel-features.h>
26 #include <pthread-pi-defines.h>
27 #include <pthread-errnos.h>
32 /* int pthread_cond_broadcast (pthread_cond_t *cond) */
33 .globl __pthread_cond_broadcast
34 .type __pthread_cond_broadcast, @function
36 __pthread_cond_broadcast:
38 /* Get internal lock. */
45 cmpxchgl %esi, cond_lock(%rdi)
49 2: addq $cond_futex, %rdi
50 movq total_seq-cond_futex(%rdi), %r9
51 cmpq wakeup_seq-cond_futex(%rdi), %r9
54 /* Cause all currently waiting threads to recognize they are
56 movq %r9, wakeup_seq-cond_futex(%rdi)
57 movq %r9, woken_seq-cond_futex(%rdi)
60 incl broadcast_seq-cond_futex(%rdi)
62 /* Get the address of the mutex used. */
63 movq dep_mutex-cond_futex(%rdi), %r8
67 decl cond_lock-cond_futex(%rdi)
73 /* XXX: The kernel so far doesn't support requeue to PI futex. */
74 /* XXX: The kernel only supports FUTEX_CMP_REQUEUE to the same
75 type of futex (private resp. shared). */
76 testl $(PI_BIT | PS_BIT), MUTEX_KIND(%r8)
79 /* Wake up all threads. */
80 #ifdef __ASSUME_PRIVATE_FUTEX
81 movl $(FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG), %esi
83 movl %fs:PRIVATE_FUTEX, %esi
84 orl $FUTEX_CMP_REQUEUE, %esi
88 movl $0x7fffffff, %r10d
91 /* For any kind of error, which mainly is EAGAIN, we try again
92 with WAKE. The general test also covers running on old
103 decl cond_lock-cond_futex(%rdi)
109 /* Initial locking failed. */
112 addq $cond_lock, %rdi
114 cmpq $-1, dep_mutex-cond_lock(%rdi)
115 movl $LLL_PRIVATE, %eax
116 movl $LLL_SHARED, %esi
118 callq __lll_lock_wait
120 subq $cond_lock, %rdi
124 /* Unlock in loop requires wakeup. */
125 5: addq $cond_lock-cond_futex, %rdi
126 cmpq $-1, dep_mutex-cond_lock(%rdi)
127 movl $LLL_PRIVATE, %eax
128 movl $LLL_SHARED, %esi
130 callq __lll_unlock_wake
133 /* Unlock in loop requires wakeup. */
134 7: addq $cond_lock-cond_futex, %rdi
136 movl $LLL_PRIVATE, %eax
137 movl $LLL_SHARED, %esi
139 callq __lll_unlock_wake
140 subq $cond_lock-cond_futex, %rdi
143 9: /* The futex requeue functionality is not available. */
145 movl $0x7fffffff, %edx
146 #ifdef __ASSUME_PRIVATE_FUTEX
147 movl $FUTEX_WAKE, %eax
148 movl $(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
152 movl %fs:PRIVATE_FUTEX, %esi
154 orl $FUTEX_WAKE, %esi
156 movl $SYS_futex, %eax
159 .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
160 versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,