pthread_rwlock_unlock.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* Copyright (C) 2003, 2007 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <sysdep.h>
  16. #include <lowlevellock.h>
  17. #include <lowlevelrwlock.h>
  18. #include <bits/kernel-features.h>
  19. #include <tcb-offsets.h>
  20. #include "lowlevel-atomic.h"
  21. .text
  22. .globl __pthread_rwlock_unlock
  23. .type __pthread_rwlock_unlock,@function
  24. .protected __pthread_rwlock_unlock
  25. .align 5
  26. __pthread_rwlock_unlock:
  27. mov.l r12, @-r15
  28. mov.l r8, @-r15
  29. sts.l pr, @-r15
  30. mov r4, r8
  31. /* Get the lock. */
  32. mov #0, r3
  33. mov #1, r4
  34. #if MUTEX == 0
  35. CMPXCHG (r3, @r8, r4, r2)
  36. #else
  37. CMPXCHG (r3, @(MUTEX,r8), r4, r2)
  38. #endif
  39. bf 1f
  40. 2:
  41. mov.l @(WRITER,r8), r0
  42. tst r0, r0
  43. bf 5f
  44. mov.l @(NR_READERS,r8), r0
  45. add #-1, r0
  46. mov.l r0, @(NR_READERS,r8)
  47. tst r0, r0
  48. bf 6f
  49. 5:
  50. mov #0, r0
  51. mov.l r0, @(WRITER,r8)
  52. mov #1, r6
  53. mov r8, r4
  54. add #WRITERS_WAKEUP, r4
  55. mov.l @(WRITERS_QUEUED,r8), r0
  56. tst r0, r0
  57. bf 0f
  58. /* If also no readers waiting nothing to do. */
  59. mov.l @(READERS_QUEUED,r8), r0
  60. tst r0, r0
  61. bt 6f
  62. mov #-1, r6
  63. shlr r6 /* r6 = 0x7fffffff */
  64. mov r8, r4
  65. add #READERS_WAKEUP, r4
  66. 0:
  67. mov.l @r4, r0
  68. add #1, r0
  69. mov.l r0, @r4
  70. #if MUTEX == 0
  71. DEC (@r8, r2)
  72. #else
  73. DEC (@(MUTEX,r8), r2)
  74. #endif
  75. tst r2, r2
  76. bf 7f
  77. 8:
  78. #ifdef __ASSUME_PRIVATE_FUTEX
  79. mov #PSHARED, r0
  80. mov.b @(r0,r8), r5
  81. mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAKE), r0
  82. xor r0, r5
  83. extu.b r5, r5
  84. #else
  85. mov #PSHARED, r0
  86. mov.b @(r0,r8), r5
  87. extu.b r5, r5
  88. mov #FUTEX_WAKE, r0
  89. or r0, r5
  90. stc gbr, r1
  91. mov.w .Lpfoff, r2
  92. add r2, r1
  93. mov.l @r1, r0
  94. xor r0, r5
  95. #endif
  96. mov #SYS_futex, r3
  97. mov #0, r7
  98. extu.b r3, r3
  99. trapa #0x14
  100. SYSCALL_INST_PAD
  101. lds.l @r15+, pr
  102. mov.l @r15+, r8
  103. mov.l @r15+, r12
  104. rts
  105. mov #0, r0
  106. 6:
  107. #if MUTEX == 0
  108. DEC (@r8, r2)
  109. #else
  110. DEC (@(MUTEX,r8), r2)
  111. #endif
  112. tst r2, r2
  113. bf 3f
  114. 4:
  115. lds.l @r15+, pr
  116. mov.l @r15+, r8
  117. mov.l @r15+, r12
  118. rts
  119. mov #0, r0
  120. 1:
  121. mov r8, r5
  122. #if MUTEX != 0
  123. add #MUTEX, r5
  124. #endif
  125. mov #PSHARED, r0
  126. mov.b @(r0,r8), r6
  127. extu.b r6, r6
  128. mov.l .Lwait8, r1
  129. bsrf r1
  130. mov r2, r4
  131. .Lwait8b:
  132. bra 2b
  133. nop
  134. 3:
  135. mov r8, r4
  136. #if MUTEX != 0
  137. add #MUTEX, r4
  138. #endif
  139. mov #PSHARED, r0
  140. mov.b @(r0,r8), r5
  141. extu.b r5, r5
  142. mov.l .Lwake8, r1
  143. bsrf r1
  144. nop
  145. .Lwake8b:
  146. bra 4b
  147. nop
  148. 7:
  149. mov.l r4, @-r15
  150. mov.l r6, @-r15
  151. mov r8, r4
  152. #if MUTEX != 0
  153. add #MUTEX, r4
  154. #endif
  155. mov #PSHARED, r0
  156. mov.b @(r0,r8), r5
  157. extu.b r5, r5
  158. mov.l .Lwake9, r1
  159. bsrf r1
  160. nop
  161. .Lwake9b:
  162. mov.l @r15+, r6
  163. bra 8b
  164. mov.l @r15+, r4
  165. #ifndef __ASSUME_PRIVATE_FUTEX
  166. .Lpfoff:
  167. .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
  168. #endif
  169. .align 2
  170. .Lwait8:
  171. .long __lll_lock_wait-.Lwait8b
  172. .Lwake8:
  173. .long __lll_unlock_wake-.Lwake8b
  174. .Lwake9:
  175. .long __lll_unlock_wake-.Lwake9b
  176. .size __pthread_rwlock_unlock,.-__pthread_rwlock_unlock
  177. .globl pthread_rwlock_unlock
  178. pthread_rwlock_unlock = __pthread_rwlock_unlock
  179. .globl __pthread_rwlock_unlock_internal
  180. __pthread_rwlock_unlock_internal = __pthread_rwlock_unlock