pthread_rwlock_timedwrlock.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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_timedwrlock
  23. .type pthread_rwlock_timedwrlock,@function
  24. .align 5
  25. pthread_rwlock_timedwrlock:
  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 @(NR_READERS,r8), r0
  48. tst r0, r0
  49. bt 5f
  50. 3:
  51. /* Check the value of the timeout parameter. */
  52. mov.l .L1g1, r1
  53. mov.l @(4,r9), r0
  54. cmp/hs r1, r0
  55. bt 19f
  56. mov.l @(WRITERS_QUEUED,r8), r0
  57. add #1, r0
  58. mov.l r0, @(WRITERS_QUEUED,r8)
  59. tst r0, r0
  60. bt 4f
  61. mov.l @(WRITERS_WAKEUP,r8), r10
  62. #if MUTEX == 0
  63. DEC (@r8, r2)
  64. #else
  65. DEC (@(MUTEX,r8), r2)
  66. #endif
  67. tst r2, r2
  68. bf 10f
  69. 11:
  70. /* Get current time. */
  71. mov r15, r4
  72. mov #0, r5
  73. mov #__NR_gettimeofday, r3
  74. trapa #0x12
  75. SYSCALL_INST_PAD
  76. mov.l @(4,r15), r0
  77. mov.w .L1k1, r1
  78. dmulu.l r0, r1 /* Milli seconds to nano seconds. */
  79. mov.l @r9, r2
  80. mov.l @(4,r9), r3
  81. mov.l @r15, r0
  82. sts macl, r1
  83. sub r0, r2
  84. clrt
  85. subc r1, r3
  86. bf 15f
  87. mov.l .L1g1, r1
  88. add r1, r3
  89. add #-1, r2
  90. 15:
  91. cmp/pz r2
  92. bf 16f /* Time is already up. */
  93. /* Store relative timeout. */
  94. mov.l r2, @r15
  95. mov.l r3, @(4,r15)
  96. /* Futex call. */
  97. mov r15, r7
  98. #ifdef __ASSUME_PRIVATE_FUTEX
  99. mov #PSHARED, r0
  100. mov.b @(r0,r8), r5
  101. mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAIT), r0
  102. xor r0, r5
  103. extu.b r5, r5
  104. #else
  105. mov #PSHARED, r0
  106. mov.b @(r0,r8), r5
  107. extu.b r5, r5
  108. # if FUTEX_WAIT != 0
  109. mov #FUTEX_WAIT, r0
  110. or r0, r5
  111. # endif
  112. stc gbr, r1
  113. mov.w .Lpfoff, r2
  114. add r2, r1
  115. mov.l @r1, r0
  116. xor r0, r5
  117. #endif
  118. mov r10, r6
  119. mov r8, r4
  120. add #WRITERS_WAKEUP, r4
  121. mov #SYS_futex, r3
  122. extu.b r3, r3
  123. trapa #0x14
  124. SYSCALL_INST_PAD
  125. mov r0, r3
  126. 17:
  127. /* Reget the lock. */
  128. mov #0, r5
  129. mov #1, r4
  130. #if MUTEX == 0
  131. CMPXCHG (r5, @r8, r4, r2)
  132. #else
  133. CMPXCHG (r5, @(MUTEX,r8), r4, r2)
  134. #endif
  135. bf 12f
  136. 13:
  137. mov.l @(WRITERS_QUEUED,r8), r0
  138. add #-1, r0
  139. mov.l r0, @(WRITERS_QUEUED,r8)
  140. mov #-ETIMEDOUT, r0
  141. cmp/eq r0, r3
  142. bf 2b
  143. 18:
  144. bra 9f
  145. mov #ETIMEDOUT, r3
  146. 19:
  147. bra 9f
  148. mov #EINVAL, r3
  149. 5:
  150. mov #0, r3
  151. stc gbr, r0
  152. mov.w .Ltidoff, r1
  153. mov.l @(r0,r1), r0
  154. mov.l r0, @(WRITER,r8)
  155. 9:
  156. #if MUTEX == 0
  157. DEC (@r8, r2)
  158. #else
  159. DEC (@(MUTEX,r8), r2)
  160. #endif
  161. tst r2, r2
  162. bf 6f
  163. 7:
  164. add #8,r15
  165. lds.l @r15+, pr
  166. mov.l @r15+, r8
  167. mov.l @r15+, r9
  168. mov.l @r15+, r10
  169. mov.l @r15+, r12
  170. rts
  171. mov r3, r0
  172. #ifndef __ASSUME_PRIVATE_FUTEX
  173. .Lpfoff:
  174. .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
  175. #endif
  176. .L1k1:
  177. .word 1000
  178. .align 2
  179. .L1g1:
  180. .long 1000000000
  181. 1:
  182. mov r8, r5
  183. #if MUTEX != 0
  184. add #MUTEX, r5
  185. #endif
  186. mov #PSHARED, r0
  187. mov.b @(r0,r8), r6
  188. extu.b r6, r6
  189. mov.l .Lwait6, r1
  190. bsrf r1
  191. mov r2, r4
  192. .Lwait6b:
  193. bra 2b
  194. nop
  195. 14:
  196. stc gbr, r1
  197. mov.w .Ltidoff, r2
  198. add r2, r1
  199. mov.l @r1, r1
  200. cmp/eq r1, r0
  201. bf 3b
  202. bra 9b
  203. mov #EDEADLK, r3
  204. 6:
  205. mov r3, r10
  206. mov r8, r4
  207. #if MUTEX != 0
  208. add #MUTEX, r4
  209. #endif
  210. mov #PSHARED, r0
  211. mov.b @(r0,r8), r5
  212. extu.b r5, r5
  213. mov.l .Lwake6, r1
  214. bsrf r1
  215. nop
  216. .Lwake6b:
  217. bra 7b
  218. mov r10, r3
  219. .Ltidoff:
  220. .word TID - TLS_PRE_TCB_SIZE
  221. 4:
  222. /* Overflow. */
  223. mov.l @(WRITERS_QUEUED,r8), r1
  224. add #-1, r1
  225. mov.l r1, @(WRITERS_QUEUED,r8)
  226. bra 9b
  227. mov #EAGAIN, r3
  228. 10:
  229. mov r8, r4
  230. #if MUTEX != 0
  231. add #MUTEX, r4
  232. #endif
  233. mov #PSHARED, r0
  234. mov.b @(r0,r8), r5
  235. extu.b r5, r5
  236. mov.l .Lwake7, r1
  237. bsrf r1
  238. nop
  239. .Lwake7b:
  240. bra 11b
  241. nop
  242. 12:
  243. mov r3, r10
  244. mov r8, r5
  245. #if MUTEX != 0
  246. add #MUTEX, r5
  247. #endif
  248. mov #PSHARED, r0
  249. mov.b @(r0,r8), r6
  250. extu.b r6, r6
  251. mov.l .Lwait7, r1
  252. bsrf r1
  253. mov r2, r4
  254. .Lwait7b:
  255. bra 13b
  256. mov r10, r3
  257. 16:
  258. bra 17b
  259. mov #-ETIMEDOUT, r3
  260. .align 2
  261. .Lwait6:
  262. .long __lll_lock_wait-.Lwait6b
  263. .Lwake6:
  264. .long __lll_unlock_wake-.Lwake6b
  265. .Lwait7:
  266. .long __lll_lock_wait-.Lwait7b
  267. .Lwake7:
  268. .long __lll_unlock_wake-.Lwake7b
  269. .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock