Update copyright notices with scripts/update-copyrights
[glibc.git] / nptl / sysdeps / unix / sysv / linux / sh / pthread_rwlock_unlock.S
blobdb99ee4696b932de1ca897cfc1a7a1438cb5cc57
1 /* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
18 #include <sysdep.h>
19 #include <lowlevellock.h>
20 #include <lowlevelrwlock.h>
21 #include <kernel-features.h>
22 #include "lowlevel-atomic.h"
25         .text
27         .globl  __pthread_rwlock_unlock
28         .type   __pthread_rwlock_unlock,@function
29         .align  5
30         cfi_startproc
31 __pthread_rwlock_unlock:
32         mov.l   r12, @-r15
33         cfi_adjust_cfa_offset (4)
34         cfi_rel_offset (r12, 0)
35         mov.l   r8, @-r15
36         cfi_adjust_cfa_offset (4)
37         cfi_rel_offset (r8, 0)
38         sts.l   pr, @-r15
39         cfi_adjust_cfa_offset (4)
40         cfi_rel_offset (pr, 0)
41         mov     r4, r8
43         /* Get the lock.  */
44         mov     #0, r3
45         mov     #1, r4
46 #if MUTEX == 0
47         CMPXCHG (r3, @r8, r4, r2)
48 #else
49         CMPXCHG (r3, @(MUTEX,r8), r4, r2)
50 #endif
51         bf      1f
53         mov.l   @(WRITER,r8), r0
54         tst     r0, r0
55         bf      5f
56         mov.l   @(NR_READERS,r8), r0
57         add     #-1, r0
58         mov.l   r0, @(NR_READERS,r8)
59         tst     r0, r0
60         bf      6f
62         mov     #0, r0
63         mov.l   r0, @(WRITER,r8)
64         mov     #1, r6
65         mov     r8, r4
66         add     #WRITERS_WAKEUP, r4
67         mov.l   @(WRITERS_QUEUED,r8), r0
68         tst     r0, r0
69         bf      0f
71         /* If also no readers waiting nothing to do.  */
72         mov.l   @(READERS_QUEUED,r8), r0
73         tst     r0, r0
74         bt      6f
76         mov     #-1, r6
77         shlr    r6              /* r6 = 0x7fffffff */
78         mov     r8, r4
79         add     #READERS_WAKEUP, r4
82         mov.l   @r4, r0
83         add     #1, r0
84         mov.l   r0, @r4
85 #if MUTEX == 0
86         DEC (@r8, r2)
87 #else
88         DEC (@(MUTEX,r8), r2)
89 #endif
90         tst     r2, r2
91         bf      7f
94 #ifdef __ASSUME_PRIVATE_FUTEX
95         mov     #PSHARED, r0
96         mov.b   @(r0,r8), r5
97         mov     #(FUTEX_PRIVATE_FLAG|FUTEX_WAKE), r0
98         xor     r0, r5
99         extu.b  r5, r5
100 #else
101         mov     #PSHARED, r0
102         mov.b   @(r0,r8), r5
103         extu.b  r5, r5
104         mov     #FUTEX_WAKE, r0
105         or      r0, r5
106         stc     gbr, r1
107         mov.w   .Lpfoff, r2
108         add     r2, r1
109         mov.l   @r1, r0
110         xor     r0, r5
111 #endif
112         mov     #SYS_futex, r3
113         mov     #0, r7
114         extu.b  r3, r3
115         trapa   #0x14
116         SYSCALL_INST_PAD
118         cfi_remember_state
119         lds.l   @r15+, pr
120         cfi_adjust_cfa_offset (-4)
121         cfi_restore (pr)
122         mov.l   @r15+, r8
123         cfi_adjust_cfa_offset (-4)
124         cfi_restore (r8)
125         mov.l   @r15+, r12
126         cfi_adjust_cfa_offset (-4)
127         cfi_restore (r12)
128         rts
129          mov    #0, r0
130         cfi_restore_state
132 #if MUTEX == 0
133         DEC (@r8, r2)
134 #else
135         DEC (@(MUTEX,r8), r2)
136 #endif
137         tst     r2, r2
138         bf      3f
140         cfi_remember_state
141         lds.l   @r15+, pr
142         cfi_adjust_cfa_offset (-4)
143         cfi_restore (pr)
144         mov.l   @r15+, r8
145         cfi_adjust_cfa_offset (-4)
146         cfi_restore (r8)
147         mov.l   @r15+, r12
148         cfi_adjust_cfa_offset (-4)
149         cfi_restore (r12)
150         rts
151          mov    #0, r0
152         cfi_restore_state
155         mov     r8, r5
156 #if MUTEX != 0
157         add     #MUTEX, r5
158 #endif
159         mov     #PSHARED, r0
160         mov.b   @(r0,r8), r6
161         extu.b  r6, r6
162         mov.l   .Lwait8, r1
163         bsrf    r1
164          mov    r2, r4
165 .Lwait8b:
166         bra     2b
167          nop
169         mov     r8, r4
170 #if MUTEX != 0
171         add     #MUTEX, r4
172 #endif
173         mov     #PSHARED, r0
174         mov.b   @(r0,r8), r5
175         extu.b  r5, r5
176         mov.l   .Lwake8, r1
177         bsrf    r1
178          nop
179 .Lwake8b:
180         bra     4b
181          nop
184         mov.l   r4, @-r15
185         cfi_adjust_cfa_offset (4)
186         mov.l   r6, @-r15
187         cfi_adjust_cfa_offset (4)
188         mov     r8, r4
189 #if MUTEX != 0
190         add     #MUTEX, r4
191 #endif
192         mov     #PSHARED, r0
193         mov.b   @(r0,r8), r5
194         extu.b  r5, r5
195         mov.l   .Lwake9, r1
196         bsrf    r1
197          nop
198 .Lwake9b:
200         mov.l   @r15+, r6
201         cfi_adjust_cfa_offset (-4)
202         bra     8b
203          mov.l  @r15+, r4
205         cfi_endproc
207 #ifndef __ASSUME_PRIVATE_FUTEX
208 .Lpfoff:
209         .word   PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
210 #endif
211         .align  2
212 .Lwait8:
213         .long   __lll_lock_wait-.Lwait8b
214 .Lwake8:
215         .long   __lll_unlock_wake-.Lwake8b
216 .Lwake9:
217         .long   __lll_unlock_wake-.Lwake9b
218         .size   __pthread_rwlock_unlock,.-__pthread_rwlock_unlock
220 strong_alias (__pthread_rwlock_unlock, pthread_rwlock_unlock)
221 hidden_def (__pthread_rwlock_unlock)