1 /* Copyright (C) 2002-2015 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>
26 #include <stap-probe.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:
36 LIBC_PROBE (cond_broadcast, 1, %rdi)
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 mov dep_mutex-cond_futex(%rdi), %R8_LP
67 decl cond_lock-cond_futex(%rdi)
73 /* Do not use requeue for pshared condvars. */
74 testl $PS_BIT, MUTEX_KIND(%r8)
77 /* Requeue to a PI mutex if the PI bit is set. */
78 movl MUTEX_KIND(%r8), %eax
79 andl $(ROBUST_BIT|PI_BIT), %eax
83 /* Wake up all threads. */
84 #ifdef __ASSUME_PRIVATE_FUTEX
85 movl $(FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG), %esi
87 movl %fs:PRIVATE_FUTEX, %esi
88 orl $FUTEX_CMP_REQUEUE, %esi
92 movl $0x7fffffff, %r10d
95 /* For any kind of error, which mainly is EAGAIN, we try again
96 with WAKE. The general test also covers running on old
104 /* Wake up all threads. */
105 81: movl $(FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
106 movl $SYS_futex, %eax
108 movl $0x7fffffff, %r10d
111 /* For any kind of error, which mainly is EAGAIN, we try again
112 with WAKE. The general test also covers running on old
121 decl cond_lock-cond_futex(%rdi)
127 /* Initial locking failed. */
130 addq $cond_lock, %rdi
132 LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
133 movl $LLL_PRIVATE, %eax
134 movl $LLL_SHARED, %esi
136 callq __lll_lock_wait
138 subq $cond_lock, %rdi
142 /* Unlock in loop requires wakeup. */
143 5: addq $cond_lock-cond_futex, %rdi
144 LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
145 movl $LLL_PRIVATE, %eax
146 movl $LLL_SHARED, %esi
148 callq __lll_unlock_wake
151 /* Unlock in loop requires wakeup. */
152 7: addq $cond_lock-cond_futex, %rdi
154 movl $LLL_PRIVATE, %eax
155 movl $LLL_SHARED, %esi
157 callq __lll_unlock_wake
158 subq $cond_lock-cond_futex, %rdi
161 9: /* The futex requeue functionality is not available. */
163 movl $0x7fffffff, %edx
164 #ifdef __ASSUME_PRIVATE_FUTEX
165 movl $FUTEX_WAKE, %eax
166 movl $(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
170 movl %fs:PRIVATE_FUTEX, %esi
172 orl $FUTEX_WAKE, %esi
174 movl $SYS_futex, %eax
177 .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
178 versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,