Updated to fedora-glibc-20070731T1624
[glibc.git] / nptl / sysdeps / unix / sysv / linux / sh / pthread_rwlock_unlock.S
blobdf4df60d7fc148eff3e7b181981b9d8df95d9230
1 /* Copyright (C) 2003, 2007 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, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
19 #include <sysdep.h>
20 #include <lowlevelrwlock.h>
21 #include <kernel-features.h>
22 #include "lowlevel-atomic.h"
24 #define SYS_futex               240
25 #define FUTEX_WAIT              0
26 #define FUTEX_WAKE              1
27 #define FUTEX_PRIVATE_FLAG      128
30         .text
32         .globl  __pthread_rwlock_unlock
33         .type   __pthread_rwlock_unlock,@function
34         .align  5
35 __pthread_rwlock_unlock:
36         mov.l   r12, @-r15
37         mov.l   r8, @-r15
38         sts.l   pr, @-r15
39         mov     r4, r8
41         /* Get the lock.  */
42         mov     #0, r3
43         mov     #1, r4
44 #if MUTEX == 0
45         CMPXCHG (r3, @r8, r4, r2)
46 #else
47         CMPXCHG (r3, @(MUTEX,r8), r4, r2)
48 #endif
49         bf      1f
51         mov.l   @(WRITER,r8), r0
52         tst     r0, r0
53         bf      5f
54         mov.l   @(NR_READERS,r8), r0
55         add     #-1, r0
56         mov.l   r0, @(NR_READERS,r8)
57         tst     r0, r0
58         bf      6f
60         mov     #0, r0
61         mov.l   r0, @(WRITER,r8)
62         mov     #1, r6
63         mov     r8, r4
64         add     #WRITERS_WAKEUP, r4
65         mov.l   @(WRITERS_QUEUED,r8), r0
66         tst     r0, r0
67         bf      0f
69         /* If also no readers waiting nothing to do.  */
70         mov.l   @(READERS_QUEUED,r8), r0
71         tst     r0, r0
72         bt      6f
74         mov     #-1, r6
75         shlr    r6              /* r6 = 0x7fffffff */
76         mov     r8, r4
77         add     #READERS_WAKEUP, r4
80         mov.l   @r4, r0
81         add     #1, r0
82         mov.l   r0, @r4
83 #if MUTEX == 0
84         DEC (@r8, r2)
85 #else
86         DEC (@(MUTEX,r8), r2)
87 #endif
88         tst     r2, r2
89         bf      7f
92 #if __ASSUME_PRIVATE_FUTEX
93         mov     #PSHARED, r0
94         mov.b   @(r0,r8), r5
95         mov     #(FUTEX_PRIVATE_FLAG|FUTEX_WAKE), r0
96         xor     r0, r5
97         extu.b  r5, r5
98 #else
99         mov     #PSHARED, r0
100         mov.b   @(r0,r8), r5
101         extu.b  r5, r5
102         mov     #FUTEX_WAKE, r0
103         or      r0, r5
104         stc     gbr, r1
105         mov.w   .Lpfoff, r2
106         add     r2, r1
107         mov.l   @r1, r0
108         xor     r0, r5
109 #endif
110         mov     #SYS_futex, r3
111         mov     #0, r7
112         extu.b  r3, r3
113         trapa   #0x14
114         SYSCALL_INST_PAD
116         lds.l   @r15+, pr
117         mov.l   @r15+, r8
118         mov.l   @r15+, r12
119         rts
120          mov    #0, r0
122 #if MUTEX == 0
123         DEC (@r8, r2)
124 #else
125         DEC (@(MUTEX,r8), r2)
126 #endif
127         tst     r2, r2
128         bf      3f
130         lds.l   @r15+, pr
131         mov.l   @r15+, r8
132         mov.l   @r15+, r12
133         rts
134          mov    #0, r0
137         mov     r8, r5
138 #if MUTEX != 0
139         add     #MUTEX, r5
140 #endif
141         mov     r2, r4
142         mov.l   .Lwait8, r1
143         bsrf    r1
144          nop
145 .Lwait8b:
146         bra     2b
147          nop
149         mov     r8, r4
150 #if MUTEX != 0
151         add     #MUTEX, r4
152 #endif
153         mov.l   .Lwake8, r1
154         bsrf    r1
155          nop
156 .Lwake8b:
157         bra     4b
158          nop
161         mov.l   r4, @-r15
162         mov.l   r6, @-r15
163         mov     r8, r4
164 #if MUTEX != 0
165         add     #MUTEX, r4
166 #endif
167         mov.l   .Lwake9, r1
168         bsrf    r1
169          nop
170 .Lwake9b:
172         mov.l   @r15+, r6
173         bra     8b
174          mov.l  @r15+, r4
176 #if !__ASSUME_PRIVATE_FUTEX
177 .Lpfoff:
178         .word   PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
179 #endif
180         .align  2
181 .Lwait8:        
182         .long   __lll_mutex_lock_wait-.Lwait8b
183 .Lwake8:
184         .long   __lll_mutex_unlock_wake-.Lwake8b
185 .Lwake9:
186         .long   __lll_mutex_unlock_wake-.Lwake9b
187         .size   __pthread_rwlock_unlock,.-__pthread_rwlock_unlock
189         .globl  pthread_rwlock_unlock
190 pthread_rwlock_unlock = __pthread_rwlock_unlock
192         .globl  __pthread_rwlock_unlock_internal
193 __pthread_rwlock_unlock_internal = __pthread_rwlock_unlock