]> git.ipfire.org Git - thirdparty/glibc.git/blob - nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
Update.
[thirdparty/glibc.git] / nptl / sysdeps / unix / sysv / linux / x86_64 / lowlevellock.S
1 /* Copyright (C) 2002, 2003 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
22 .text
23
24 #ifndef LOCK
25 # ifdef UP
26 # define LOCK
27 # else
28 # define LOCK lock
29 # endif
30 #endif
31
32 #define SYS_gettimeofday __NR_gettimeofday
33 #define SYS_futex 202
34 #define FUTEX_WAIT 0
35 #define FUTEX_WAKE 1
36
37 #define ETIMEDOUT 110
38
39
40 /* Modified: %rax, %rsi. */
41 .globl __lll_lock_wait
42 .type __lll_lock_wait,@function
43 .hidden __lll_lock_wait
44 .align 16
45 __lll_lock_wait:
46 pushq %r10
47 pushq %rdx
48
49 xorq %r10, %r10 /* No timeout. */
50
51 1:
52 leaq -1(%rsi), %rdx /* account for the preceeded xadd. */
53 movq %r10, %rsi /* movl $FUTEX_WAIT, %ecx */
54 movq $SYS_futex, %rax
55 syscall
56
57 orl $-1, %esi /* Load -1. */
58 LOCK
59 xaddl %esi, (%rdi)
60 jne,pn 1b
61
62 movl $-1, (%rdi)
63
64 popq %rdx
65 popq %r10
66 retq
67 .size __lll_lock_wait,.-__lll_lock_wait
68
69
70 #ifdef NOT_IN_libc
71 .globl lll_unlock_wake_cb
72 .type lll_unlock_wake_cb,@function
73 .hidden lll_unlock_wake_cb
74 .align 16
75 lll_unlock_wake_cb:
76 pushq %rsi
77 pushq %rdx
78
79 LOCK
80 addl $1, (%rdi)
81 jng 1f
82
83 popq %rdx
84 popq %rsi
85 retq
86 .size lll_unlock_wake_cb,.-lll_unlock_wake_cb
87 #endif
88
89
90 .globl __lll_unlock_wake
91 .type __lll_unlock_wake,@function
92 .hidden __lll_unlock_wake
93 .align 16
94 __lll_unlock_wake:
95 pushq %rsi
96 pushq %rdx
97
98 1: movq $FUTEX_WAKE, %rsi
99 movl $1, %edx /* Wake one thread. */
100 movq $SYS_futex, %rax
101 movl %edx, (%rdi) /* Stores '$1'. */
102 syscall
103
104 popq %rdx
105 popq %rsi
106 retq
107 .size __lll_unlock_wake,.-__lll_unlock_wake
108
109
110 #ifdef NOT_IN_libc
111 .globl __lll_timedwait_tid
112 .type __lll_timedwait_tid,@function
113 .hidden __lll_timedwait_tid
114 .align 16
115 __lll_timedwait_tid:
116 movq %rdi, %r8
117 movq %rsi, %r9
118
119 subq $16, %rsp
120
121 /* Get current time. */
122 2: movq %rsp, %rdi
123 xorq %rsi, %rsi
124 movq $SYS_gettimeofday, %rax
125 syscall
126
127 /* Compute relative timeout. */
128 movq 8(%rsp), %rax
129 movq $1000, %rdi
130 mul %rdi /* Milli seconds to nano seconds. */
131 movq (%r9), %rdi
132 movq 8(%r9), %rsi
133 subq (%rsp), %rdi
134 subq %rax, %rsi
135 jns 5f
136 addq $1000000000, %rsi
137 decq %rdi
138 5: testq %rdi, %rdi
139 js 6f /* Time is already up. */
140
141 movq %rdi, (%rsp) /* Store relative timeout. */
142 movq %rsi, 8(%rsp)
143
144 movl (%r8), %edx
145 testl %edx, %edx
146 jz 4f
147
148 movq %rsp, %r10
149 xorq %rsi, %rsi /* movl $FUTEX_WAIT, %ecx */
150 movq %r8, %rdi
151 movq $SYS_futex, %rax
152 syscall
153
154 cmpl $0, (%rdi)
155 jne 1f
156 4: xorl %eax, %eax
157
158 addq $16, %rsp
159 retq
160
161 1: cmpq $-ETIMEDOUT, %rax
162 jne 2b
163
164 6: movl $ETIMEDOUT, %eax
165 addq $16, %rsp
166 retq
167 .size __lll_timedwait_tid,.-__lll_timedwait_tid
168 #endif