]> git.ipfire.org Git - thirdparty/glibc.git/blob - nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_wrlock.S
6ea17f755cea5b229cc198f5827543341ce91bdd
[thirdparty/glibc.git] / nptl / sysdeps / unix / sysv / linux / i386 / i486 / pthread_rwlock_wrlock.S
1 /* Copyright (C) 2002-2013 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, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <sysdep.h>
20 #include <lowlevellock.h>
21 #include <lowlevelrwlock.h>
22 #include <pthread-errnos.h>
23 #include <kernel-features.h>
24
25 #include <stap-probe.h>
26
27 .text
28
29 .globl __pthread_rwlock_wrlock
30 .type __pthread_rwlock_wrlock,@function
31 .align 16
32 __pthread_rwlock_wrlock:
33 cfi_startproc
34 pushl %esi
35 cfi_adjust_cfa_offset(4)
36 pushl %ebx
37 cfi_adjust_cfa_offset(4)
38 cfi_offset(%esi, -8)
39 cfi_offset(%ebx, -12)
40
41 xorl %esi, %esi
42 movl 12(%esp), %ebx
43
44 LIBC_PROBE (wrlock_entry, 1, %ebx)
45
46 /* Get the lock. */
47 movl $1, %edx
48 xorl %eax, %eax
49 LOCK
50 #if MUTEX == 0
51 cmpxchgl %edx, (%ebx)
52 #else
53 cmpxchgl %edx, MUTEX(%ebx)
54 #endif
55 jnz 1f
56
57 2: movl WRITER(%ebx), %eax
58 testl %eax, %eax
59 jne 14f
60 cmpl $0, NR_READERS(%ebx)
61 je 5f
62
63 3: addl $1, WRITERS_QUEUED(%ebx)
64 je 4f
65
66 movl WRITERS_WAKEUP(%ebx), %edx
67
68 LOCK
69 #if MUTEX == 0
70 subl $1, (%ebx)
71 #else
72 subl $1, MUTEX(%ebx)
73 #endif
74 jne 10f
75
76 11:
77 #ifdef __ASSUME_PRIVATE_FUTEX
78 movzbl PSHARED(%ebx), %ecx
79 xorl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %ecx
80 #else
81 movzbl PSHARED(%ebx), %ecx
82 # if FUTEX_WAIT != 0
83 orl $FUTEX_WAIT, %ecx
84 # endif
85 xorl %gs:PRIVATE_FUTEX, %ecx
86 #endif
87 addl $WRITERS_WAKEUP, %ebx
88 movl $SYS_futex, %eax
89 ENTER_KERNEL
90
91 subl $WRITERS_WAKEUP, %ebx
92
93 /* Reget the lock. */
94 movl $1, %edx
95 xorl %eax, %eax
96 LOCK
97 #if MUTEX == 0
98 cmpxchgl %edx, (%ebx)
99 #else
100 cmpxchgl %edx, MUTEX(%ebx)
101 #endif
102 jnz 12f
103
104 13: subl $1, WRITERS_QUEUED(%ebx)
105 jmp 2b
106
107 5: xorl %edx, %edx
108 movl %gs:TID, %eax
109 movl %eax, WRITER(%ebx)
110 9: LOCK
111 #if MUTEX == 0
112 subl $1, (%ebx)
113 #else
114 subl $1, MUTEX(%ebx)
115 #endif
116 jne 6f
117 7:
118
119 movl %edx, %eax
120 popl %ebx
121 cfi_adjust_cfa_offset(-4)
122 cfi_restore(%ebx)
123 popl %esi
124 cfi_adjust_cfa_offset(-4)
125 cfi_restore(%esi)
126 ret
127
128 cfi_adjust_cfa_offset(8)
129 cfi_offset(%esi, -8)
130 cfi_offset(%ebx, -12)
131 1:
132 #if MUTEX == 0
133 movl %ebx, %edx
134 #else
135 leal MUTEX(%ebx), %edx
136 #endif
137 movzbl PSHARED(%ebx), %ecx
138 call __lll_lock_wait
139 jmp 2b
140
141 14: cmpl %gs:TID , %eax
142 jne 3b
143 movl $EDEADLK, %edx
144 jmp 9b
145
146 6:
147 #if MUTEX == 0
148 movl %ebx, %eax
149 #else
150 leal MUTEX(%ebx), %eax
151 #endif
152 movzbl PSHARED(%ebx), %ecx
153 call __lll_unlock_wake
154 jmp 7b
155
156 4: subl $1, WRITERS_QUEUED(%ebx)
157 movl $EAGAIN, %edx
158 jmp 9b
159
160 10:
161 #if MUTEX == 0
162 movl %ebx, %eax
163 #else
164 leal MUTEX(%ebx), %eax
165 #endif
166 movzbl PSHARED(%ebx), %ecx
167 call __lll_unlock_wake
168 jmp 11b
169
170 12:
171 #if MUTEX == 0
172 movl %ebx, %edx
173 #else
174 leal MUTEX(%ebx), %edx
175 #endif
176 movzbl PSHARED(%ebx), %ecx
177 call __lll_lock_wait
178 jmp 13b
179 cfi_endproc
180 .size __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock
181
182 strong_alias (__pthread_rwlock_wrlock, pthread_rwlock_wrlock)
183 hidden_def (__pthread_rwlock_wrlock)