Fix some uses of ret in libpthread
[glibc/nacl-glibc.git] / nptl / sysdeps / unix / sysv / linux / x86_64 / pthread_rwlock_rdlock.S
blob80fedd4ab11a741ecf189fa026eb5a015641c9ed
1 /* Copyright (C) 2002, 2003, 2005, 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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
21 #include <lowlevellock.h>
22 #include <lowlevelrwlock.h>
23 #include <pthread-errnos.h>
24 #include <kernel-features.h>
27         .text
29         .globl  __pthread_rwlock_rdlock
30         .type   __pthread_rwlock_rdlock,@function
31         .align  16
32 __pthread_rwlock_rdlock:
33         xorq    %r10, %r10
35         /* Get the lock.  */
36         movl    $1, %esi
37         xorl    %eax, %eax
38         LOCK
39 #if MUTEX == 0
40         cmpxchgl %esi, (%rdi)
41 #else
42         cmpxchgl %esi, MUTEX(%rdi)
43 #endif
44         jnz     1f
46 2:      movl    WRITER(%rdi), %eax
47         testl   %eax, %eax
48         jne     14f
49         cmpl    $0, WRITERS_QUEUED(%rdi)
50         je      5f
51         cmpl    $0, FLAGS(%rdi)
52         je      5f
54 3:      incl    READERS_QUEUED(%rdi)
55         je      4f
57         movl    READERS_WAKEUP(%rdi), %edx
59         LOCK
60 #if MUTEX == 0
61         decl    (%rdi)
62 #else
63         decl    MUTEX(%rdi)
64 #endif
65         jne     10f
67 11:
68 #ifdef __ASSUME_PRIVATE_FUTEX
69         movl    $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %esi
70         xorl    PSHARED(%rdi), %esi
71 #else
72 # if FUTEX_WAIT == 0
73         movl    PSHARED(%rdi), %esi
74 # else
75         movl    $FUTEX_WAIT, %esi
76         orl     PSHARED(%rdi), %esi
77 # endif
78         xorl    %fs:PRIVATE_FUTEX, %esi
79 #endif
80         addq    $READERS_WAKEUP, %rdi
81         movl    $SYS_futex, %eax
82         syscall
84         subq    $READERS_WAKEUP, %rdi
86         /* Reget the lock.  */
87         movl    $1, %esi
88         xorl    %eax, %eax
89         LOCK
90 #if MUTEX == 0
91         cmpxchgl %esi, (%rdi)
92 #else
93         cmpxchgl %esi, MUTEX(%rdi)
94 #endif
95         jnz     12f
97 13:     decl    READERS_QUEUED(%rdi)
98         jmp     2b
100 5:      xorl    %edx, %edx
101         incl    NR_READERS(%rdi)
102         je      8f
103 9:      LOCK
104 #if MUTEX == 0
105         decl    (%rdi)
106 #else
107         decl    MUTEX(%rdi)
108 #endif
109         jne     6f
112         movq    %rdx, %rax
113         retq
115 1:      movl    PSHARED(%rdi), %esi
116 #if MUTEX != 0
117         addq    $MUTEX, %rdi
118 #endif
119         callq   __lll_lock_wait
120 #if MUTEX != 0
121         subq    $MUTEX, %rdi
122 #endif
123         jmp     2b
125 14:     cmpl    %fs:TID, %eax
126         jne     3b
127         /* Deadlock detected.  */
128         movl    $EDEADLK, %edx
129         jmp     9b
131 6:      movl    PSHARED(%rdi), %esi
132 #if MUTEX != 0
133         addq    $MUTEX, %rdi
134 #endif
135         callq   __lll_unlock_wake
136 #if MUTEX != 0
137         subq    $MUTEX, %rdi
138 #endif
139         jmp     7b
141         /* Overflow.  */
142 8:      decl    NR_READERS(%rdi)
143         movl    $EAGAIN, %edx
144         jmp     9b
146         /* Overflow.  */
147 4:      decl    READERS_QUEUED(%rdi)
148         movl    $EAGAIN, %edx
149         jmp     9b
151 10:     movl    PSHARED(%rdi), %esi
152 #if MUTEX != 0
153         addq    $MUTEX, %rdi
154 #endif
155         callq   __lll_unlock_wake
156 #if MUTEX != 0
157         subq    $MUTEX, %rdi
158 #endif
159         jmp     11b
161 12:     movl    PSHARED(%rdi), %esi
162 #if MUTEX == 0
163         addq    $MUTEX, %rdi
164 #endif
165         callq   __lll_lock_wait
166 #if MUTEX != 0
167         subq    $MUTEX, %rdi
168 #endif
169         jmp     13b
170         .size   __pthread_rwlock_rdlock,.-__pthread_rwlock_rdlock
172         .globl  pthread_rwlock_rdlock
173 pthread_rwlock_rdlock = __pthread_rwlock_rdlock
175         .globl  __pthread_rwlock_rdlock_internal
176 __pthread_rwlock_rdlock_internal = __pthread_rwlock_rdlock