]>
Commit | Line | Data |
---|---|---|
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> |
50f1dec5 | 23 | #include <kernel-features.h> |
5acf7263 | 24 | #include <stap-probe.h> |
da49194d | 25 | |
da49194d UD |
26 | .text |
27 | ||
28 | .globl __pthread_rwlock_rdlock | |
29 | .type __pthread_rwlock_rdlock,@function | |
30 | .align 16 | |
31 | __pthread_rwlock_rdlock: | |
1bc2b97e | 32 | cfi_startproc |
5acf7263 RM |
33 | |
34 | LIBC_PROBE (rdlock_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 |
49 | 2: movl WRITER(%rdi), %eax |
50 | testl %eax, %eax | |
da49194d UD |
51 | jne 14f |
52 | cmpl $0, WRITERS_QUEUED(%rdi) | |
53 | je 5f | |
54 | cmpl $0, FLAGS(%rdi) | |
55 | je 5f | |
56 | ||
57 | 3: incl READERS_QUEUED(%rdi) | |
58 | je 4f | |
59 | ||
60 | movl READERS_WAKEUP(%rdi), %edx | |
61 | ||
62 | LOCK | |
63 | #if MUTEX == 0 | |
46a32546 | 64 | decl (%rdi) |
da49194d | 65 | #else |
46a32546 | 66 | decl MUTEX(%rdi) |
da49194d UD |
67 | #endif |
68 | jne 10f | |
69 | ||
50f1dec5 | 70 | 11: |
28635aca | 71 | #ifdef __ASSUME_PRIVATE_FUTEX |
50f1dec5 UD |
72 | movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi |
73 | xorl PSHARED(%rdi), %esi | |
ee618985 | 74 | #else |
50f1dec5 UD |
75 | # if FUTEX_WAIT == 0 |
76 | movl PSHARED(%rdi), %esi | |
77 | # else | |
ee618985 | 78 | movl $FUTEX_WAIT, %esi |
50f1dec5 UD |
79 | orl PSHARED(%rdi), %esi |
80 | # endif | |
81 | xorl %fs:PRIVATE_FUTEX, %esi | |
ee618985 | 82 | #endif |
50f1dec5 | 83 | addq $READERS_WAKEUP, %rdi |
ee618985 | 84 | movl $SYS_futex, %eax |
da49194d UD |
85 | syscall |
86 | ||
46a32546 | 87 | subq $READERS_WAKEUP, %rdi |
da49194d UD |
88 | |
89 | /* Reget the lock. */ | |
90 | movl $1, %esi | |
3a226d33 | 91 | xorl %eax, %eax |
da49194d UD |
92 | LOCK |
93 | #if MUTEX == 0 | |
3a226d33 | 94 | cmpxchgl %esi, (%rdi) |
da49194d | 95 | #else |
3a226d33 | 96 | cmpxchgl %esi, MUTEX(%rdi) |
da49194d | 97 | #endif |
3a226d33 | 98 | jnz 12f |
da49194d UD |
99 | |
100 | 13: decl READERS_QUEUED(%rdi) | |
101 | jmp 2b | |
102 | ||
ee618985 | 103 | 5: xorl %edx, %edx |
da49194d UD |
104 | incl NR_READERS(%rdi) |
105 | je 8f | |
106 | 9: LOCK | |
107 | #if MUTEX == 0 | |
108 | decl (%rdi) | |
109 | #else | |
110 | decl MUTEX(%rdi) | |
111 | #endif | |
112 | jne 6f | |
113 | 7: | |
114 | ||
92ed3daf | 115 | movq %rdx, %rax |
da49194d UD |
116 | retq |
117 | ||
e51deae7 | 118 | 1: movl PSHARED(%rdi), %esi |
da49194d UD |
119 | #if MUTEX != 0 |
120 | addq $MUTEX, %rdi | |
121 | #endif | |
e51deae7 | 122 | callq __lll_lock_wait |
da49194d UD |
123 | #if MUTEX != 0 |
124 | subq $MUTEX, %rdi | |
125 | #endif | |
126 | jmp 2b | |
127 | ||
4ad0bbf4 | 128 | 14: cmpl %fs:TID, %eax |
da49194d UD |
129 | jne 3b |
130 | /* Deadlock detected. */ | |
ee618985 | 131 | movl $EDEADLK, %edx |
da49194d UD |
132 | jmp 9b |
133 | ||
e51deae7 | 134 | 6: movl PSHARED(%rdi), %esi |
da49194d UD |
135 | #if MUTEX != 0 |
136 | addq $MUTEX, %rdi | |
137 | #endif | |
e51deae7 | 138 | callq __lll_unlock_wake |
da49194d UD |
139 | #if MUTEX != 0 |
140 | subq $MUTEX, %rdi | |
141 | #endif | |
142 | jmp 7b | |
143 | ||
144 | /* Overflow. */ | |
145 | 8: decl NR_READERS(%rdi) | |
ee618985 | 146 | movl $EAGAIN, %edx |
da49194d UD |
147 | jmp 9b |
148 | ||
149 | /* Overflow. */ | |
150 | 4: decl READERS_QUEUED(%rdi) | |
ee618985 | 151 | movl $EAGAIN, %edx |
da49194d UD |
152 | jmp 9b |
153 | ||
e51deae7 | 154 | 10: movl PSHARED(%rdi), %esi |
da49194d UD |
155 | #if MUTEX != 0 |
156 | addq $MUTEX, %rdi | |
157 | #endif | |
e51deae7 | 158 | callq __lll_unlock_wake |
da49194d UD |
159 | #if MUTEX != 0 |
160 | subq $MUTEX, %rdi | |
161 | #endif | |
162 | jmp 11b | |
163 | ||
e51deae7 | 164 | 12: movl PSHARED(%rdi), %esi |
da49194d UD |
165 | #if MUTEX == 0 |
166 | addq $MUTEX, %rdi | |
167 | #endif | |
e51deae7 | 168 | callq __lll_lock_wait |
da49194d UD |
169 | #if MUTEX != 0 |
170 | subq $MUTEX, %rdi | |
171 | #endif | |
172 | jmp 13b | |
1bc2b97e | 173 | cfi_endproc |
da49194d UD |
174 | .size __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock |
175 | ||
4d17e683 AS |
176 | strong_alias (__pthread_rwlock_rdlock, pthread_rwlock_rdlock) |
177 | hidden_def (__pthread_rwlock_rdlock) |