]> git.ipfire.org Git - thirdparty/glibc.git/blob - nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
2.5-18.1
[thirdparty/glibc.git] / nptl / sysdeps / unix / sysv / linux / x86_64 / pthread_cond_signal.S
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.
4
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.
9
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.
14
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
18 02111-1307 USA. */
19
20 #include <sysdep.h>
21 #include <shlib-compat.h>
22 #include <lowlevelcond.h>
23 #include <kernel-features.h>
24
25 #ifdef UP
26 # define LOCK
27 #else
28 # define LOCK lock
29 #endif
30
31 #define SYS_futex 202
32 #define FUTEX_WAIT 0
33 #define FUTEX_WAKE 1
34 #define FUTEX_WAKE_OP 5
35
36 #define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
37
38 #define EINVAL 22
39
40
41 .text
42
43 /* int pthread_cond_signal (pthread_cond_t *cond) */
44 .globl __pthread_cond_signal
45 .type __pthread_cond_signal, @function
46 .align 16
47 __pthread_cond_signal:
48
49 /* Get internal lock. */
50 movq %rdi, %r8
51 movl $1, %esi
52 xorl %eax, %eax
53 LOCK
54 #if cond_lock == 0
55 cmpxchgl %esi, (%rdi)
56 #else
57 cmpxchgl %esi, cond_lock(%rdi)
58 #endif
59 jnz 1f
60
61 2: addq $cond_futex, %rdi
62 movq total_seq(%r8), %rcx
63 cmpq wakeup_seq(%r8), %rcx
64 jbe 4f
65
66 /* Bump the wakeup number. */
67 addq $1, wakeup_seq(%r8)
68 addl $1, (%rdi)
69
70 /* Wake up one thread. */
71 movl $FUTEX_WAKE_OP, %esi
72 movl $SYS_futex, %eax
73 movl $1, %edx
74 movl $1, %r10d
75 #if cond_lock != 0
76 addq $cond_lock, %r8
77 #endif
78 movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
79 syscall
80 #if cond_lock != 0
81 subq $cond_lock, %r8
82 #endif
83 /* For any kind of error, we try again with WAKE.
84 The general test also covers running on old kernels. */
85 cmpq $-4095, %rax
86 jae 7f
87
88 xorl %eax, %eax
89 retq
90
91 7: movl $FUTEX_WAKE, %esi
92 movl $SYS_futex, %eax
93 /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
94 movl $1, %edx */
95 syscall
96
97 /* Unlock. */
98 4: LOCK
99 #if cond_lock == 0
100 decl (%r8)
101 #else
102 decl cond_lock(%r8)
103 #endif
104 jne 5f
105
106 6: xorl %eax, %eax
107 retq
108
109 /* Initial locking failed. */
110 1:
111 #if cond_lock != 0
112 addq $cond_lock, %rdi
113 #endif
114 callq __lll_mutex_lock_wait
115 #if cond_lock != 0
116 subq $cond_lock, %rdi
117 #endif
118 jmp 2b
119
120 /* Unlock in loop requires wakeup. */
121 5:
122 movq %r8, %rdi
123 callq __lll_mutex_unlock_wake
124 jmp 6b
125 .size __pthread_cond_signal, .-__pthread_cond_signal
126 versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal,
127 GLIBC_2_3_2)