1 /* Copyright (C) 2002, 2003, 2004, 2005 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 <shlib-compat.h>
22 #include <lowlevelcond.h>
23 #include <kernel-features.h>
34 #define FUTEX_WAKE_OP 5
36 #define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
43 /* int pthread_cond_signal (pthread_cond_t *cond) */
44 .globl __pthread_cond_signal
45 .type __pthread_cond_signal, @function
47 __pthread_cond_signal:
49 /* Get internal lock. */
57 cmpxchgl %esi, cond_lock(%rdi)
61 2: addq $cond_futex, %rdi
62 movq total_seq(%r8), %rcx
63 cmpq wakeup_seq(%r8), %rcx
66 /* Bump the wakeup number. */
67 addq $1, wakeup_seq(%r8)
70 /* Wake up one thread. */
71 movl $FUTEX_WAKE_OP, %esi
78 movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
83 /* For any kind of error, we try again with WAKE.
84 The general test also covers running on old kernels. */
91 7: movl $FUTEX_WAKE, %esi
93 /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
109 /* Initial locking failed. */
112 addq $cond_lock, %rdi
114 callq __lll_mutex_lock_wait
116 subq $cond_lock, %rdi
120 /* Unlock in loop requires wakeup. */
123 callq __lll_mutex_unlock_wake
125 .size __pthread_cond_signal, .-__pthread_cond_signal
126 versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal,