]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
Add adaptive elision to rwlocks
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / x86_64 / pthread_rwlock_wrlock.S
CommitLineData
d4697bc9 1/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
da49194d
UD
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
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
da49194d
UD
18
19#include <sysdep.h>
e51deae7 20#include <lowlevellock.h>
da49194d 21#include <lowlevelrwlock.h>
326132db 22#include <pthread-errnos.h>
28635aca 23#include <kernel-features.h>
5acf7263 24#include <stap-probe.h>
da49194d 25
da49194d
UD
26 .text
27
28 .globl __pthread_rwlock_wrlock
29 .type __pthread_rwlock_wrlock,@function
30 .align 16
31__pthread_rwlock_wrlock:
1bc2b97e 32 cfi_startproc
5acf7263
RM
33
34 LIBC_PROBE (wrlock_entry, 1, %rdi)
35
da49194d
UD
36 xorq %r10, %r10
37
38 /* Get the lock. */
39 movl $1, %esi
3a226d33 40 xorl %eax, %eax
da49194d
UD
41 LOCK
42#if MUTEX == 0
3a226d33 43 cmpxchgl %esi, (%rdi)
da49194d 44#else
3a226d33 45 cmpxchgl %esi, MUTEX(%rdi)
da49194d 46#endif
3a226d33 47 jnz 1f
da49194d 48
4ad0bbf4
UD
492: movl WRITER(%rdi), %eax
50 testl %eax, %eax
da49194d
UD
51 jne 14f
52 cmpl $0, NR_READERS(%rdi)
53 je 5f
54
553: incl WRITERS_QUEUED(%rdi)
56 je 4f
57
58 movl WRITERS_WAKEUP(%rdi), %edx
59
60 LOCK
61#if MUTEX == 0
62 decl (%rdi)
63#else
64 decl MUTEX(%rdi)
65#endif
66 jne 10f
67
50f1dec5 6811:
28635aca 69#ifdef __ASSUME_PRIVATE_FUTEX
50f1dec5
UD
70 movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
71 xorl PSHARED(%rdi), %esi
ee618985 72#else
50f1dec5
UD
73# if FUTEX_WAIT == 0
74 movl PSHARED(%rdi), %esi
75# else
ee618985 76 movl $FUTEX_WAIT, %esi
50f1dec5
UD
77 orl PSHARED(%rdi), %esi
78# endif
79 xorl %fs:PRIVATE_FUTEX, %esi
ee618985 80#endif
50f1dec5 81 addq $WRITERS_WAKEUP, %rdi
ee618985 82 movl $SYS_futex, %eax
da49194d
UD
83 syscall
84
46a32546 85 subq $WRITERS_WAKEUP, %rdi
da49194d
UD
86
87 /* Reget the lock. */
88 movl $1, %esi
3a226d33 89 xorl %eax, %eax
da49194d
UD
90 LOCK
91#if MUTEX == 0
3a226d33 92 cmpxchgl %esi, (%rdi)
da49194d 93#else
3a226d33 94 cmpxchgl %esi, MUTEX(%rdi)
da49194d 95#endif
3a226d33 96 jnz 12f
da49194d
UD
97
9813: decl WRITERS_QUEUED(%rdi)
99 jmp 2b
100
ee618985 1015: xorl %edx, %edx
4ad0bbf4
UD
102 movl %fs:TID, %eax
103 movl %eax, WRITER(%rdi)
da49194d
UD
1049: LOCK
105#if MUTEX == 0
106 decl (%rdi)
107#else
46a32546 108 decl MUTEX(%rdi)
da49194d
UD
109#endif
110 jne 6f
1117:
112
92ed3daf 113 movq %rdx, %rax
da49194d
UD
114 retq
115
e51deae7 1161: movl PSHARED(%rdi), %esi
da49194d
UD
117#if MUTEX != 0
118 addq $MUTEX, %rdi
119#endif
e51deae7 120 callq __lll_lock_wait
da49194d
UD
121#if MUTEX != 0
122 subq $MUTEX, %rdi
123#endif
124 jmp 2b
125
4ad0bbf4 12614: cmpl %fs:TID, %eax
da49194d 127 jne 3b
ee618985 128 movl $EDEADLK, %edx
da49194d
UD
129 jmp 9b
130
e51deae7 1316: movl PSHARED(%rdi), %esi
da49194d
UD
132#if MUTEX != 0
133 addq $MUTEX, %rdi
134#endif
e51deae7 135 callq __lll_unlock_wake
da49194d
UD
136 jmp 7b
137
1384: decl WRITERS_QUEUED(%rdi)
92ed3daf 139 movl $EAGAIN, %edx
da49194d
UD
140 jmp 9b
141
e51deae7 14210: movl PSHARED(%rdi), %esi
da49194d
UD
143#if MUTEX != 0
144 addq $MUTEX, %rdi
145#endif
e51deae7 146 callq __lll_unlock_wake
da49194d
UD
147#if MUTEX != 0
148 subq $MUTEX, %rdi
149#endif
150 jmp 11b
151
e51deae7 15212: movl PSHARED(%rdi), %esi
da49194d
UD
153#if MUTEX != 0
154 addq $MUTEX, %rdi
155#endif
e51deae7 156 callq __lll_lock_wait
da49194d
UD
157#if MUTEX != 0
158 subq $MUTEX, %rdi
159#endif
160 jmp 13b
1bc2b97e 161 cfi_endproc
da49194d
UD
162 .size __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock
163
4d17e683
AS
164strong_alias (__pthread_rwlock_wrlock, pthread_rwlock_wrlock)
165hidden_def (__pthread_rwlock_wrlock)