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_signal (pthread_cond_t *cond) */
31 .globl __pthread_cond_signal
32 .type __pthread_cond_signal, @function
34 __pthread_cond_signal:
38 cfi_adjust_cfa_offset(4)
39 cfi_rel_offset(%ebx, 0)
41 cfi_adjust_cfa_offset(4)
42 cfi_rel_offset(%edi, 0)
47 LIBC_PROBE (cond_signal, 1, %edi)
49 /* Get internal lock. */
56 cmpxchgl %edx, cond_lock(%edi)
60 2: leal cond_futex(%edi), %ebx
61 movl total_seq+4(%edi), %eax
62 movl total_seq(%edi), %ecx
63 cmpl wakeup_seq+4(%edi), %eax
65 /* Must use leal to preserve the flags. */
66 leal cond_lock(%edi), %edi
70 cmpl wakeup_seq-cond_futex(%ebx), %ecx
73 /* Bump the wakeup number. */
74 3: addl $1, wakeup_seq-cond_futex(%ebx)
75 adcl $0, wakeup_seq-cond_futex+4(%ebx)
78 /* Wake up one thread. */
80 cfi_adjust_cfa_offset(4)
81 cfi_rel_offset(%esi, 0)
83 cfi_adjust_cfa_offset(4)
84 cfi_rel_offset(%ebp, 0)
86 #if FUTEX_PRIVATE_FLAG > 255
89 cmpl $-1, dep_mutex-cond_futex(%ebx)
93 movl dep_mutex-cond_futex(%ebx), %edx
94 /* Requeue to a non-robust PI mutex if the PI bit is set and
95 the robust bit is not set. */
96 movl MUTEX_KIND(%edx), %eax
97 andl $(ROBUST_BIT|PI_BIT), %eax
102 #ifdef __ASSUME_PRIVATE_FUTEX
103 andl $FUTEX_PRIVATE_FLAG, %ecx
105 andl %gs:PRIVATE_FUTEX, %ecx
107 addl $FUTEX_WAKE_OP, %ecx
108 movl $SYS_futex, %eax
111 movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %ebp
112 /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for
117 cfi_adjust_cfa_offset(-4)
120 cfi_adjust_cfa_offset(-4)
123 /* For any kind of error, we try again with WAKE.
124 The general test also covers running on old kernels. */
130 cfi_adjust_cfa_offset(-4)
133 cfi_adjust_cfa_offset(-4)
139 9: movl $(FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %ecx
140 movl $SYS_futex, %eax
143 movl dep_mutex-cond_futex(%ebx), %edi
145 /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for
152 leal -cond_futex(%ebx), %edi
154 /* For any kind of error, we try again with WAKE.
155 The general test also covers running on old kernels. */
160 #ifdef __ASSUME_PRIVATE_FUTEX
161 andl $FUTEX_PRIVATE_FLAG, %ecx
163 andl %gs:PRIVATE_FUTEX, %ecx
165 orl $FUTEX_WAKE, %ecx
167 movl $SYS_futex, %eax
168 /* %edx should be 1 already from $FUTEX_WAKE_OP syscall.
172 /* Unlock. Note that at this point %edi always points to
178 /* Unlock in loop requires wakeup. */
180 #if (LLL_SHARED-LLL_PRIVATE) > 255
183 cmpl $-1, dep_mutex-cond_futex(%ebx)
186 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
188 addl $LLL_PRIVATE, %ecx
190 call __lll_unlock_wake
193 /* Initial locking failed. */
198 leal cond_lock(%edi), %edx
200 #if (LLL_SHARED-LLL_PRIVATE) > 255
203 cmpl $-1, dep_mutex(%edi)
206 andl $(LLL_SHARED-LLL_PRIVATE), %ecx
208 addl $LLL_PRIVATE, %ecx
214 .size __pthread_cond_signal, .-__pthread_cond_signal
215 versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal,