Replace FSF snail mail address with URLs.
[glibc.git] / nptl / sysdeps / unix / sysv / linux / i386 / i486 / pthread_rwlock_wrlock.S
blob3994b06c03818f1aee63ff7cc884a613338d9cac
1 /* Copyright (C) 2002, 2003, 2007 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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.
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.
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/>.  */
19 #include <sysdep.h>
20 #include <lowlevellock.h>
21 #include <lowlevelrwlock.h>
22 #include <pthread-errnos.h>
23 #include <kernel-features.h>
26         .text
28         .globl  __pthread_rwlock_wrlock
29         .type   __pthread_rwlock_wrlock,@function
30         .align  16
31 __pthread_rwlock_wrlock:
32         cfi_startproc
33         pushl   %esi
34         cfi_adjust_cfa_offset(4)
35         pushl   %ebx
36         cfi_adjust_cfa_offset(4)
37         cfi_offset(%esi, -8)
38         cfi_offset(%ebx, -12)
40         xorl    %esi, %esi
41         movl    12(%esp), %ebx
43         /* Get the lock.  */
44         movl    $1, %edx
45         xorl    %eax, %eax
46         LOCK
47 #if MUTEX == 0
48         cmpxchgl %edx, (%ebx)
49 #else
50         cmpxchgl %edx, MUTEX(%ebx)
51 #endif
52         jnz     1f
54 2:      movl    WRITER(%ebx), %eax
55         testl   %eax, %eax
56         jne     14f
57         cmpl    $0, NR_READERS(%ebx)
58         je      5f
60 3:      addl    $1, WRITERS_QUEUED(%ebx)
61         je      4f
63         movl    WRITERS_WAKEUP(%ebx), %edx
65         LOCK
66 #if MUTEX == 0
67         subl    $1, (%ebx)
68 #else
69         subl    $1, MUTEX(%ebx)
70 #endif
71         jne     10f
73 11:
74 #ifdef __ASSUME_PRIVATE_FUTEX
75         movzbl  PSHARED(%ebx), %ecx
76         xorl    $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %ecx
77 #else
78         movzbl  PSHARED(%ebx), %ecx
79 # if FUTEX_WAIT != 0
80         orl     $FUTEX_WAIT, %ecx
81 # endif
82         xorl    %gs:PRIVATE_FUTEX, %ecx
83 #endif
84         addl    $WRITERS_WAKEUP, %ebx
85         movl    $SYS_futex, %eax
86         ENTER_KERNEL
88         subl    $WRITERS_WAKEUP, %ebx
90         /* Reget the lock.  */
91         movl    $1, %edx
92         xorl    %eax, %eax
93         LOCK
94 #if MUTEX == 0
95         cmpxchgl %edx, (%ebx)
96 #else
97         cmpxchgl %edx, MUTEX(%ebx)
98 #endif
99         jnz     12f
101 13:     subl    $1, WRITERS_QUEUED(%ebx)
102         jmp     2b
104 5:      xorl    %edx, %edx
105         movl    %gs:TID, %eax
106         movl    %eax, WRITER(%ebx)
107 9:      LOCK
108 #if MUTEX == 0
109         subl    $1, (%ebx)
110 #else
111         subl    $1, MUTEX(%ebx)
112 #endif
113         jne     6f
116         movl    %edx, %eax
117         popl    %ebx
118         cfi_adjust_cfa_offset(-4)
119         cfi_restore(%ebx)
120         popl    %esi
121         cfi_adjust_cfa_offset(-4)
122         cfi_restore(%esi)
123         ret
125         cfi_adjust_cfa_offset(8)
126         cfi_offset(%esi, -8)
127         cfi_offset(%ebx, -12)
129 #if MUTEX == 0
130         movl    %ebx, %edx
131 #else
132         leal    MUTEX(%ebx), %edx
133 #endif
134         movzbl  PSHARED(%ebx), %ecx
135         call    __lll_lock_wait
136         jmp     2b
138 14:     cmpl    %gs:TID , %eax
139         jne     3b
140         movl    $EDEADLK, %edx
141         jmp     9b
144 #if MUTEX == 0
145         movl    %ebx, %eax
146 #else
147         leal    MUTEX(%ebx), %eax
148 #endif
149         movzbl  PSHARED(%ebx), %ecx
150         call    __lll_unlock_wake
151         jmp     7b
153 4:      subl    $1, WRITERS_QUEUED(%ebx)
154         movl    $EAGAIN, %edx
155         jmp     9b
158 #if MUTEX == 0
159         movl    %ebx, %eax
160 #else
161         leal    MUTEX(%ebx), %eax
162 #endif
163         movzbl  PSHARED(%ebx), %ecx
164         call    __lll_unlock_wake
165         jmp     11b
168 #if MUTEX == 0
169         movl    %ebx, %edx
170 #else
171         leal    MUTEX(%ebx), %edx
172 #endif
173         movzbl  PSHARED(%ebx), %ecx
174         call    __lll_lock_wait
175         jmp     13b
176         cfi_endproc
177         .size   __pthread_rwlock_wrlock,.-__pthread_rwlock_wrlock
179         .globl  pthread_rwlock_wrlock
180 pthread_rwlock_wrlock = __pthread_rwlock_wrlock
182         .globl  __pthread_rwlock_wrlock_internal
183 __pthread_rwlock_wrlock_internal = __pthread_rwlock_wrlock