Update copyright notices with scripts/update-copyrights
[glibc.git] / nptl / sysdeps / unix / sysv / linux / i386 / i486 / pthread_rwlock_unlock.S
blob738c06778077e7b7c3831d71073ef3b9a93709d0
1 /* Copyright (C) 2002-2014 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 <kernel-features.h>
25         .text
27         .globl  __pthread_rwlock_unlock
28         .type   __pthread_rwlock_unlock,@function
29         .align  16
30 __pthread_rwlock_unlock:
31         cfi_startproc
32         pushl   %ebx
33         cfi_adjust_cfa_offset(4)
34         pushl   %edi
35         cfi_adjust_cfa_offset(4)
36         cfi_offset(%ebx, -8)
37         cfi_offset(%edi, -12)
39         movl    12(%esp), %edi
41         /* Get the lock.  */
42         movl    $1, %edx
43         xorl    %eax, %eax
44         LOCK
45 #if MUTEX == 0
46         cmpxchgl %edx, (%edi)
47 #else
48         cmpxchgl %edx, MUTEX(%edi)
49 #endif
50         jnz     1f
52 2:      cmpl    $0, WRITER(%edi)
53         jne     5f
54         subl    $1, NR_READERS(%edi)
55         jnz     6f
57 5:      movl    $0, WRITER(%edi)
59         movl    $1, %edx
60         leal    WRITERS_WAKEUP(%edi), %ebx
61         cmpl    $0, WRITERS_QUEUED(%edi)
62         jne     0f
64         /* If also no readers waiting nothing to do.  */
65         cmpl    $0, READERS_QUEUED(%edi)
66         je      6f
68         movl    $0x7fffffff, %edx
69         leal    READERS_WAKEUP(%edi), %ebx
71 0:      addl    $1, (%ebx)
72         LOCK
73 #if MUTEX == 0
74         subl    $1, (%edi)
75 #else
76         subl    $1, MUTEX(%edi)
77 #endif
78         jne     7f
81 #ifdef __ASSUME_PRIVATE_FUTEX
82         movzbl  PSHARED(%edi), %ecx
83         xorl    $FUTEX_PRIVATE_FLAG|FUTEX_WAKE, %ecx
84 #else
85         movzbl  PSHARED(%edi), %ecx
86         orl     $FUTEX_WAKE, %ecx
87         xorl    %gs:PRIVATE_FUTEX, %ecx
88 #endif
89         movl    $SYS_futex, %eax
90         ENTER_KERNEL
92         xorl    %eax, %eax
93         popl    %edi
94         cfi_adjust_cfa_offset(-4)
95         cfi_restore(%edi)
96         popl    %ebx
97         cfi_adjust_cfa_offset(-4)
98         cfi_restore(%ebx)
99         ret
101         cfi_adjust_cfa_offset(8)
102         cfi_offset(%ebx, -8)
103         cfi_offset(%edi, -12)
104         .align  16
105 6:      LOCK
106 #if MUTEX == 0
107         subl    $1, (%edi)
108 #else
109         subl    $1, MUTEX(%edi)
110 #endif
111         jne     3f
113 4:      xorl    %eax, %eax
114         popl    %edi
115         popl    %ebx
116         ret
119 #if MUTEX == 0
120         movl    %edi, %edx
121 #else
122         leal    MUTEX(%edi), %edx
123 #endif
124         movzbl  PSHARED(%edi), %ecx
125         call    __lll_lock_wait
126         jmp     2b
129 #if MUTEX == 0
130         movl    %edi, %eax
131 #else
132         leal    MUTEX(%edi), %eax
133 #endif
134         movzbl  PSHARED(%edi), %ecx
135         call    __lll_unlock_wake
136         jmp     4b
139 #if MUTEX == 0
140         movl    %edi, %eax
141 #else
142         leal    MUTEX(%edi), %eax
143 #endif
144         movzbl  PSHARED(%edi), %ecx
145         call    __lll_unlock_wake
146         jmp     8b
147         cfi_endproc
148         .size   __pthread_rwlock_unlock,.-__pthread_rwlock_unlock
150 strong_alias (__pthread_rwlock_unlock, pthread_rwlock_unlock)
151 hidden_def (__pthread_rwlock_unlock)