pthread_rwlock_wrlock.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 <pthread-errnos.h>
  19. #include <tcb-offsets.h>
  20. #include <bits/kernel-features.h>
  21. #include "lowlevel-atomic.h"
  22. .text
  23. .globl __pthread_rwlock_wrlock
  24. .type __pthread_rwlock_wrlock,@function
  25. .protected __pthread_rwlock_wrlock
  26. .align 5
  27. __pthread_rwlock_wrlock:
  28. mov.l r12, @-r15
  29. mov.l r9, @-r15
  30. mov.l r8, @-r15
  31. sts.l pr, @-r15
  32. mov r4, r8
  33. /* Get the lock. */
  34. mov #0, r3
  35. mov #1, r4
  36. #if MUTEX == 0
  37. CMPXCHG (r3, @r8, r4, r2)
  38. #else
  39. CMPXCHG (r3, @(MUTEX,r8), r4, r2)
  40. #endif
  41. bf 1f
  42. 2:
  43. mov.l @(WRITER,r8), r0
  44. tst r0, r0
  45. bf 14f
  46. mov.l @(NR_READERS,r8), r0
  47. tst r0, r0
  48. bt 5f
  49. 3:
  50. mov.l @(WRITERS_QUEUED,r8), r0
  51. add #1, r0
  52. mov.l r0, @(WRITERS_QUEUED,r8)
  53. tst r0, r0
  54. bt 4f
  55. mov.l @(WRITERS_WAKEUP,r8), r9
  56. #if MUTEX == 0
  57. DEC (@r8, r2)
  58. #else
  59. DEC (@(MUTEX,r8), r2)
  60. #endif
  61. tst r2, r2
  62. bf 10f
  63. 11:
  64. mov r8, r4
  65. add #WRITERS_WAKEUP, r4
  66. #ifdef __ASSUME_PRIVATE_FUTEX
  67. mov #PSHARED, r0
  68. mov.b @(r0,r8), r5
  69. mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAIT), r0
  70. xor r0, r5
  71. extu.b r5, r5
  72. #else
  73. mov #PSHARED, r0
  74. mov.b @(r0,r8), r5
  75. extu.b r5, r5
  76. # if FUTEX_WAIT != 0
  77. mov #FUTEX_WAIT, r0
  78. or r0, r5
  79. # endif
  80. stc gbr, r1
  81. mov.w .Lpfoff, r2
  82. add r2, r1
  83. mov.l @r1, r0
  84. xor r0, r5
  85. #endif
  86. mov r9, r6
  87. mov #0, r7
  88. mov #SYS_futex, r3
  89. extu.b r3, r3
  90. trapa #0x14
  91. SYSCALL_INST_PAD
  92. /* Reget the lock. */
  93. mov #0, r3
  94. mov #1, r4
  95. #if MUTEX == 0
  96. CMPXCHG (r3, @r8, r4, r2)
  97. #else
  98. CMPXCHG (r3, @(MUTEX,r8), r4, r2)
  99. #endif
  100. bf 12f
  101. 13:
  102. mov.l @(WRITERS_QUEUED,r8), r0
  103. add #-1, r0
  104. bra 2b
  105. mov.l r0, @(WRITERS_QUEUED,r8)
  106. 5:
  107. mov #0, r3
  108. stc gbr, r0
  109. mov.w .Ltidoff, r1
  110. mov.l @(r0,r1), r0
  111. mov.l r0, @(WRITER,r8)
  112. 9:
  113. #if MUTEX == 0
  114. DEC (@r8, r2)
  115. #else
  116. DEC (@(MUTEX,r8), r2)
  117. #endif
  118. tst r2, r2
  119. bf 6f
  120. 7:
  121. lds.l @r15+, pr
  122. mov.l @r15+, r8
  123. mov.l @r15+, r9
  124. mov.l @r15+, r12
  125. rts
  126. mov r3, r0
  127. 1:
  128. mov r8, r5
  129. #if MUTEX != 0
  130. add #MUTEX, r5
  131. #endif
  132. mov #PSHARED, r0
  133. mov.b @(r0,r8), r6
  134. extu.b r6, r6
  135. mov.l .Lwait4, r1
  136. bsrf r1
  137. mov r2, r4
  138. .Lwait4b:
  139. bra 2b
  140. nop
  141. 14:
  142. stc gbr, r1
  143. mov.w .Ltidoff, r2
  144. add r2, r1
  145. mov.l @r1, r1
  146. cmp/eq r1, r0
  147. bf 3b
  148. bra 9b
  149. mov #EDEADLK, r3
  150. 6:
  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 .Lwake4, r1
  159. bsrf r1
  160. nop
  161. .Lwake4b:
  162. bra 7b
  163. mov #0, r3
  164. #ifndef __ASSUME_PRIVATE_FUTEX
  165. .Lpfoff:
  166. .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
  167. #endif
  168. .Ltidoff:
  169. .word TID - TLS_PRE_TCB_SIZE
  170. 4:
  171. mov.l @(WRITERS_QUEUED,r8), r1
  172. add #-1, r1
  173. mov.l r1, @(WRITERS_QUEUED,r8)
  174. bra 9b
  175. mov #EAGAIN, r3
  176. 10:
  177. mov r8, r4
  178. #if MUTEX != 0
  179. add #MUTEX, r4
  180. #endif
  181. mov #PSHARED, r0
  182. mov.b @(r0,r8), r5
  183. extu.b r5, r5
  184. mov.l .Lwake5, r1
  185. bsrf r1
  186. nop
  187. .Lwake5b:
  188. bra 11b
  189. nop
  190. 12:
  191. mov r8, r5
  192. #if MUTEX != 0
  193. add #MUTEX, r5
  194. #endif
  195. mov #PSHARED, r0
  196. mov.b @(r0,r8), r6
  197. extu.b r6, r6
  198. mov.l .Lwait5, r1
  199. bsrf r1
  200. mov r2, r4
  201. .Lwait5b:
  202. bra 13b
  203. nop
  204. .align 2
  205. .Lwait4:
  206. .long __lll_lock_wait-.Lwait4b
  207. .Lwake4:
  208. .long __lll_unlock_wake-.Lwake4b
  209. .Lwait5:
  210. .long __lll_lock_wait-.Lwait5b
  211. .Lwake5:
  212. .long __lll_unlock_wake-.Lwake5b
  213. .globl pthread_rwlock_wrlock
  214. pthread_rwlock_wrlock = __pthread_rwlock_wrlock
  215. .globl __pthread_rwlock_wrlock_internal
  216. __pthread_rwlock_wrlock_internal = __pthread_rwlock_wrlock