1 /* Copyright (C) 2002-2005, 2007, 2009 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 <lowlevellock.h>
22 #include <lowlevelcond.h>
23 #include <pthread-pi-defines.h>
24 #include <bits/kernel-features.h>
25 #include <pthread-errnos.h>
30 /* int pthread_cond_signal (pthread_cond_t *cond) */
31 .globl __pthread_cond_signal
32 .type __pthread_cond_signal, @function
33 .protected __pthread_cond_signal
35 __pthread_cond_signal:
37 /* Get internal lock. */
45 cmpxchgl %esi, cond_lock(%rdi)
49 2: addq $cond_futex, %rdi
50 movq total_seq(%r8), %rcx
51 cmpq wakeup_seq(%r8), %rcx
54 /* Bump the wakeup number. */
55 addq $1, wakeup_seq(%r8)
58 /* Wake up one thread. */
59 cmpq $-1, dep_mutex(%r8)
60 movl $FUTEX_WAKE_OP, %esi
65 /* Get the address of the mutex used. */
66 movq dep_mutex(%r8), %rcx
67 movl MUTEX_KIND(%rcx), %r11d
68 andl $(ROBUST_BIT|PI_BIT), %r11d
72 #ifdef __ASSUME_PRIVATE_FUTEX
73 movl $(FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG), %esi
75 orl %fs:PRIVATE_FUTEX, %esi
82 movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
87 /* For any kind of error, we try again with WAKE.
88 The general test also covers running on old kernels. */
95 /* Wake up one thread and requeue none in the PI Mutex case. */
96 9: movl $(FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
99 movl (%rdi), %r9d // XXX Can this be right?
102 leaq -cond_futex(%rdi), %r8
104 /* For any kind of error, we try again with WAKE.
105 The general test also covers running on old kernels. */
110 #ifdef __ASSUME_PRIVATE_FUTEX
111 andl $FUTEX_PRIVATE_FLAG, %esi
113 andl %fs:PRIVATE_FUTEX, %esi
115 orl $FUTEX_WAKE, %esi
116 movl $SYS_futex, %eax
117 /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
133 /* Initial locking failed. */
136 addq $cond_lock, %rdi
138 cmpq $-1, dep_mutex-cond_lock(%rdi)
139 movl $LLL_PRIVATE, %eax
140 movl $LLL_SHARED, %esi
142 callq __lll_lock_wait
144 subq $cond_lock, %rdi
148 /* Unlock in loop requires wakeup. */
152 addq $cond_lock, %rdi
154 cmpq $-1, dep_mutex-cond_lock(%rdi)
155 movl $LLL_PRIVATE, %eax
156 movl $LLL_SHARED, %esi
158 callq __lll_unlock_wake
160 .size __pthread_cond_signal, .-__pthread_cond_signal
161 weak_alias(__pthread_cond_signal, pthread_cond_signal)