pthread_rwlock_timedrdlock.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /* Copyright (C) 2003, 2007, 2008 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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sysdep.h>
  15. #include <lowlevellock.h>
  16. #include <lowlevelrwlock.h>
  17. #include <pthread-errnos.h>
  18. #include <tcb-offsets.h>
  19. #include <bits/kernel-features.h>
  20. #include "lowlevel-atomic.h"
  21. .text
  22. .globl pthread_rwlock_timedrdlock
  23. .type pthread_rwlock_timedrdlock,@function
  24. .align 5
  25. pthread_rwlock_timedrdlock:
  26. mov.l r12, @-r15
  27. mov.l r10, @-r15
  28. mov.l r9, @-r15
  29. mov.l r8, @-r15
  30. sts.l pr, @-r15
  31. add #-8, r15
  32. mov r4, r8
  33. mov r5, r9
  34. /* Get the lock. */
  35. mov #0, r3
  36. mov #1, r4
  37. #if MUTEX == 0
  38. CMPXCHG (r3, @r8, r4, r2)
  39. #else
  40. CMPXCHG (r3, @(MUTEX,r8), r4, r2)
  41. #endif
  42. bf 1f
  43. 2:
  44. mov.l @(WRITER,r8), r0
  45. tst r0, r0
  46. bf 14f
  47. mov.l @(WRITERS_QUEUED,r8), r0
  48. tst r0, r0
  49. bt 5f
  50. mov #FLAGS, r0
  51. mov.b @(r0,r8), r0
  52. tst r0, r0
  53. bt 5f
  54. 3:
  55. /* Check the value of the timeout parameter. */
  56. mov.l .L1g0, r1
  57. mov.l @(4,r9), r0
  58. cmp/hs r1, r0
  59. bt 19f
  60. mov.l @(READERS_QUEUED,r8), r0
  61. add #1, r0
  62. mov.l r0, @(READERS_QUEUED,r8)
  63. tst r0, r0
  64. bt 4f
  65. mov.l @(READERS_WAKEUP,r8), r10
  66. #if MUTEX == 0
  67. DEC (@r8, r2)
  68. #else
  69. DEC (@(MUTEX,r8), r2)
  70. #endif
  71. tst r2, r2
  72. bf 10f
  73. 11:
  74. /* Get current time. */
  75. mov r15, r4
  76. mov #0, r5
  77. mov #__NR_gettimeofday, r3
  78. trapa #0x12
  79. SYSCALL_INST_PAD
  80. mov.l @(4,r15), r0
  81. mov.w .L1k0, r1
  82. dmulu.l r0, r1 /* Milli seconds to nano seconds. */
  83. mov.l @r9, r2
  84. mov.l @(4,r9), r3
  85. mov.l @r15, r0
  86. sts macl, r1
  87. sub r0, r2
  88. clrt
  89. subc r1, r3
  90. bf 15f
  91. mov.l .L1g0, r1
  92. add r1, r3
  93. add #-1, r2
  94. 15:
  95. cmp/pz r2
  96. bf 16f /* Time is already up. */
  97. /* Store relative timeout. */
  98. mov.l r2, @r15
  99. mov.l r3, @(4,r15)
  100. /* Futex call. */
  101. mov r15, r7
  102. #ifdef __ASSUME_PRIVATE_FUTEX
  103. mov #PSHARED, r0
  104. mov.b @(r0,r8), r5
  105. mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAIT), r0
  106. xor r0, r5
  107. extu.b r5, r5
  108. #else
  109. mov #PSHARED, r0
  110. mov.b @(r0,r8), r5
  111. extu.b r5, r5
  112. # if FUTEX_WAIT != 0
  113. mov #FUTEX_WAIT, r0
  114. or r0, r5
  115. # endif
  116. stc gbr, r1
  117. mov.w .Lpfoff, r2
  118. add r2, r1
  119. mov.l @r1, r0
  120. xor r0, r5
  121. #endif
  122. mov r10, r6
  123. mov r8, r4
  124. add #READERS_WAKEUP, r4
  125. mov #SYS_futex, r3
  126. extu.b r3, r3
  127. trapa #0x14
  128. SYSCALL_INST_PAD
  129. mov r0, r3
  130. 17:
  131. /* Reget the lock. */
  132. mov #0, r5
  133. mov #1, r4
  134. #if MUTEX == 0
  135. CMPXCHG (r5, @r8, r4, r2)
  136. #else
  137. CMPXCHG (r5, @(MUTEX,r8), r4, r2)
  138. #endif
  139. bf 12f
  140. 13:
  141. mov.l @(READERS_QUEUED,r8), r0
  142. add #-1, r0
  143. mov.l r0, @(READERS_QUEUED,r8)
  144. mov #-ETIMEDOUT, r0
  145. cmp/eq r0, r3
  146. bf 2b
  147. 18:
  148. bra 9f
  149. mov #ETIMEDOUT, r3
  150. 5:
  151. mov #0, r3
  152. mov.l @(NR_READERS,r8), r0
  153. add #1, r0
  154. mov.l r0, @(NR_READERS,r8)
  155. tst r0, r0
  156. bt 8f
  157. 9:
  158. #if MUTEX == 0
  159. DEC (@r8, r2)
  160. #else
  161. DEC (@(MUTEX,r8), r2)
  162. #endif
  163. tst r2, r2
  164. bf 6f
  165. 7:
  166. add #8,r15
  167. lds.l @r15+, pr
  168. mov.l @r15+, r8
  169. mov.l @r15+, r9
  170. mov.l @r15+, r10
  171. mov.l @r15+, r12
  172. rts
  173. mov r3, r0
  174. #ifndef __ASSUME_PRIVATE_FUTEX
  175. .Lpfoff:
  176. .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
  177. #endif
  178. .align 2
  179. .L1k0:
  180. .long 1000
  181. .L1g0:
  182. .long 1000000000
  183. 1:
  184. mov r8, r5
  185. #if MUTEX != 0
  186. add #MUTEX, r5
  187. #endif
  188. mov #PSHARED, r0
  189. mov.b @(r0,r8), r6
  190. extu.b r6, r6
  191. mov.l .Lwait2, r1
  192. bsrf r1
  193. mov r2, r4
  194. .Lwait2b:
  195. bra 2b
  196. nop
  197. 14:
  198. stc gbr, r1
  199. mov.w .Ltidoff, r2
  200. add r2, r1
  201. mov.l @r1, r1
  202. cmp/eq r1, r0
  203. bf 3b
  204. /* Deadlock detected. */
  205. bra 9b
  206. mov #EDEADLK, r3
  207. .Ltidoff:
  208. .word TID - TLS_PRE_TCB_SIZE
  209. 6:
  210. mov r3, r10
  211. mov r8, r4
  212. #if MUTEX != 0
  213. add #MUTEX, r4
  214. #endif
  215. mov #PSHARED, r0
  216. mov.b @(r0,r8), r5
  217. extu.b r5, r5
  218. mov.l .Lwake2, r1
  219. bsrf r1
  220. nop
  221. .Lwake2b:
  222. bra 7b
  223. mov r10, r3
  224. 8:
  225. /* Overflow. */
  226. mov.l @(NR_READERS,r8), r1
  227. add #-1, r1
  228. mov.l r1, @(NR_READERS,r8)
  229. bra 9b
  230. mov #EAGAIN, r3
  231. 4:
  232. /* Overflow. */
  233. mov.l @(READERS_QUEUED,r8), r1
  234. add #-1, r1
  235. mov.l r1, @(READERS_QUEUED,r8)
  236. bra 9b
  237. mov #EAGAIN, r3
  238. 10:
  239. mov r8, r4
  240. #if MUTEX != 0
  241. add #MUTEX, r4
  242. #endif
  243. mov #PSHARED, r0
  244. mov.b @(r0,r8), r5
  245. extu.b r5, r5
  246. mov.l .Lwake3, r1
  247. bsrf r1
  248. nop
  249. .Lwake3b:
  250. bra 11b
  251. nop
  252. 12:
  253. mov r3, r10
  254. mov r8, r5
  255. #if MUTEX != 0
  256. add #MUTEX, r5
  257. #endif
  258. mov #PSHARED, r0
  259. mov.b @(r0,r8), r6
  260. extu.b r6, r6
  261. mov.l .Lwait3, r1
  262. bsrf r1
  263. mov r2, r4
  264. .Lwait3b:
  265. bra 13b
  266. mov r10, r3
  267. 16:
  268. bra 17b
  269. mov #-ETIMEDOUT, r3
  270. 19:
  271. bra 9b
  272. mov #EINVAL, r3
  273. .align 2
  274. .Lwait2:
  275. .long __lll_lock_wait-.Lwait2b
  276. .Lwake2:
  277. .long __lll_unlock_wake-.Lwake2b
  278. .Lwait3:
  279. .long __lll_lock_wait-.Lwait3b
  280. .Lwake3:
  281. .long __lll_unlock_wake-.Lwake3b
  282. .size pthread_rwlock_timedrdlock,.-pthread_rwlock_timedrdlock