1 /* Copyright (C) 2002-2014 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 <lowlevellock.h>
21 #include <lowlevelrwlock.h>
22 #include <pthread-errnos.h>
23 #include <kernel-features.h>
27 .globl pthread_rwlock_timedwrlock
28 .type pthread_rwlock_timedwrlock,@function
30 pthread_rwlock_timedwrlock:
33 cfi_adjust_cfa_offset(8)
34 cfi_rel_offset(%r12, 0)
36 cfi_adjust_cfa_offset(8)
37 cfi_rel_offset(%r13, 0)
38 #ifdef __ASSUME_FUTEX_CLOCK_REALTIME
42 cfi_adjust_cfa_offset(8)
43 cfi_rel_offset(%r14, 0)
46 cfi_adjust_cfa_offset(16)
60 cmpxchgl %esi, MUTEX(%rdi)
64 2: movl WRITER(%r12), %eax
67 cmpl $0, NR_READERS(%r12)
70 /* Check the value of the timeout parameter. */
71 3: cmpq $1000000000, 8(%r13)
74 incl WRITERS_QUEUED(%r12)
77 movl WRITERS_WAKEUP(%r12), VALREG
88 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
90 cmpl $0, __have_futex_clock_realtime(%rip)
92 cmpl $0, __have_futex_clock_realtime
98 js 16f /* Time is already up. */
100 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, %esi
101 xorl PSHARED(%r12), %esi
103 movl $0xffffffff, %r9d
104 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
107 21: leaq WRITERS_WAKEUP(%r12), %rdi
108 movl $SYS_futex, %eax
112 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
115 /* Get current time. */
118 /* This call works because we directly jump to a system call entry
119 which preserves all the registers. */
120 call JUMPTARGET(__gettimeofday)
122 /* Compute relative timeout. */
125 mul %rdi /* Milli seconds to nano seconds. */
131 addq $1000000000, %rdi
134 js 16f /* Time is already up. */
137 movq %rcx, (%rsp) /* Store relative timeout. */
140 # ifdef __ASSUME_PRIVATE_FUTEX
141 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
142 xorl PSHARED(%r12), %esi
145 movl PSHARED(%r12), %esi
147 movl $FUTEX_WAIT, %esi
148 orl PSHARED(%r12), %esi
150 xorl %fs:PRIVATE_FUTEX, %esi
159 17: /* Reget the lock. */
164 cmpxchgl %esi, (%r12)
166 cmpxchgl %esi, MUTEX(%r12)
170 13: decl WRITERS_QUEUED(%r12)
171 cmpq $-ETIMEDOUT, %rdx
174 18: movl $ETIMEDOUT, %edx
180 movl %eax, WRITER(%r12)
191 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
193 cfi_adjust_cfa_offset(-16)
195 cfi_adjust_cfa_offset(-8)
199 cfi_adjust_cfa_offset(-8)
202 cfi_adjust_cfa_offset(-8)
206 #ifdef __ASSUME_PRIVATE_FUTEX
207 cfi_adjust_cfa_offset(16)
208 cfi_rel_offset(%r12, 8)
209 cfi_rel_offset(%r13, 0)
211 cfi_adjust_cfa_offset(40)
212 cfi_offset(%r12, -16)
213 cfi_offset(%r13, -24)
214 cfi_offset(%r14, -32)
216 1: movl PSHARED(%rdi), %esi
220 callq __lll_lock_wait
223 14: cmpl %fs:TID, %eax
225 20: movl $EDEADLK, %edx
228 6: movl PSHARED(%r12), %esi
232 leal MUTEX(%r12), %rdi
234 callq __lll_unlock_wake
238 4: decl WRITERS_QUEUED(%r12)
242 10: movl PSHARED(%r12), %esi
246 leaq MUTEX(%r12), %rdi
248 callq __lll_unlock_wake
251 12: movl PSHARED(%r12), %esi
255 leaq MUTEX(%r12), %rdi
257 callq __lll_lock_wait
260 16: movq $-ETIMEDOUT, %rdx
263 19: movl $EINVAL, %edx
266 .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock