pthread_cond_broadcast.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* Copyright (C) 2003, 2004, 2006, 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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sysdep.h>
  15. #include <lowlevellock.h>
  16. #include <lowlevelcond.h>
  17. #include <bits/kernel-features.h>
  18. #include <pthread-pi-defines.h>
  19. #include <pthread-errnos.h>
  20. #include <tcb-offsets.h>
  21. #include "lowlevel-atomic.h"
  22. .text
  23. /* int pthread_cond_broadcast (pthread_cond_t *cond) */
  24. .globl __pthread_cond_broadcast
  25. .type __pthread_cond_broadcast, @function
  26. .protected __pthread_cond_broadcast
  27. .align 5
  28. __pthread_cond_broadcast:
  29. mov.l r10, @-r15
  30. mov.l r9, @-r15
  31. mov.l r8, @-r15
  32. sts.l pr, @-r15
  33. mov r4, r8
  34. /* Get internal lock. */
  35. mov #0, r3
  36. mov #1, r4
  37. #if cond_lock != 0
  38. CMPXCHG (r3, @(cond_lock,r8), r4, r2)
  39. #else
  40. CMPXCHG (r3, @r8, r4, r2)
  41. #endif
  42. bf 1f
  43. 2:
  44. mov.l @(total_seq+4,r8),r0
  45. mov.l @(total_seq,r8),r1
  46. mov.l @(wakeup_seq+4,r8), r2
  47. cmp/hi r2, r0
  48. bt 3f
  49. cmp/hi r0, r2
  50. bt 4f
  51. mov.l @(wakeup_seq,r8), r2
  52. cmp/hi r2, r1
  53. bf 4f
  54. 3:
  55. /* Cause all currently waiting threads to recognize they are
  56. woken up. */
  57. mov.l r1, @(wakeup_seq,r8)
  58. mov.l r0, @(wakeup_seq+4,r8)
  59. mov.l r1, @(woken_seq,r8)
  60. mov.l r0, @(woken_seq+4,r8)
  61. mov.l @(broadcast_seq,r8), r2
  62. add #1, r2
  63. mov.l r2, @(broadcast_seq,r8)
  64. add r1, r1
  65. mov r1, r10
  66. mov.l r10, @(cond_futex,r8)
  67. /* Get the address of the mutex used. */
  68. mov.l @(dep_mutex,r8), r9
  69. /* Unlock. */
  70. #if cond_lock != 0
  71. DEC (@(cond_lock,r8), r2)
  72. #else
  73. DEC (@r8, r2)
  74. #endif
  75. tst r2, r2
  76. bf 7f
  77. 8:
  78. /* Don't use requeue for pshared condvars. */
  79. mov #-1, r0
  80. cmp/eq r0, r9
  81. mov r8, r4
  82. bt/s 9f
  83. add #cond_futex, r4
  84. /* XXX: The kernel only supports FUTEX_CMP_REQUEUE to the same
  85. type of futex (private resp. shared). */
  86. mov.l @(MUTEX_KIND,r9), r0
  87. tst #(PI_BIT|PS_BIT), r0
  88. bf 9f
  89. /* Wake up all threads. */
  90. #ifdef __ASSUME_PRIVATE_FUTEX
  91. mov #(FUTEX_CMP_REQUEUE|FUTEX_PRIVATE_FLAG), r5
  92. extu.b r5, r5
  93. #else
  94. stc gbr, r1
  95. mov.w .Lpfoff, r2
  96. add r2, r1
  97. mov.l @r1, r5
  98. mov #FUTEX_CMP_REQUEUE, r0
  99. or r0, r5
  100. #endif
  101. mov #1, r6
  102. mov #-1, r7
  103. shlr r7 /* r7 = 0x7fffffff */
  104. mov r9, r0
  105. # if MUTEX_FUTEX != 0
  106. add #MUTEX_FUTEX, r0
  107. # endif
  108. mov r10, r1
  109. mov #SYS_futex, r3
  110. extu.b r3, r3
  111. trapa #0x16
  112. SYSCALL_INST_PAD
  113. /* For any kind of error, which mainly is EAGAIN, we try again
  114. with WAKE. The general test also covers running on old
  115. kernels. */
  116. mov r0, r1
  117. mov #-12, r2
  118. shad r2, r1
  119. not r1, r1
  120. tst r1, r1
  121. mov r8, r4
  122. bt/s 9f
  123. add #cond_futex, r4
  124. 10:
  125. mov #0, r0
  126. lds.l @r15+, pr
  127. mov.l @r15+, r8
  128. mov.l @r15+, r9
  129. rts
  130. mov.l @r15+, r10
  131. 4:
  132. /* Unlock. */
  133. #if cond_lock != 0
  134. DEC (@(cond_lock,r8), r2)
  135. #else
  136. DEC (@r8, r2)
  137. #endif
  138. tst r2, r2
  139. bf 5f
  140. 6:
  141. mov #0, r0
  142. lds.l @r15+, pr
  143. mov.l @r15+, r8
  144. mov.l @r15+, r9
  145. rts
  146. mov.l @r15+, r10
  147. 1:
  148. /* Initial locking failed. */
  149. mov r8, r5
  150. #if cond_lock != 0
  151. add #cond_lock, r5
  152. #endif
  153. mov.l @(dep_mutex,r8), r0
  154. cmp/eq #-1, r0
  155. bf/s 99f
  156. mov #LLL_PRIVATE, r6
  157. mov #LLL_SHARED, r6
  158. 99:
  159. extu.b r6, r6
  160. mov.l .Lwait5, r1
  161. bsrf r1
  162. mov r2, r4
  163. .Lwait5b:
  164. bra 2b
  165. nop
  166. 5:
  167. /* Unlock in loop requires wakeup. */
  168. mov r8, r4
  169. #if cond_lock != 0
  170. add #cond_lock, r4
  171. #endif
  172. mov.l @(dep_mutex,r8), r0
  173. cmp/eq #-1, r0
  174. bf/s 99f
  175. mov #LLL_PRIVATE, r5
  176. mov #LLL_SHARED, r5
  177. 99:
  178. mov.l .Lwake5, r1
  179. bsrf r1
  180. extu.b r5, r5
  181. .Lwake5b:
  182. bra 6b
  183. nop
  184. 7:
  185. /* Unlock in loop requires wakeup. */
  186. mov r8, r4
  187. #if cond_lock != 0
  188. add #cond_lock, r4
  189. #endif
  190. mov #-1, r0
  191. cmp/eq r0, r9
  192. bf/s 99f
  193. mov #LLL_PRIVATE, r5
  194. mov #LLL_SHARED, r5
  195. 99:
  196. mov.l .Lwake6, r1
  197. bsrf r1
  198. extu.b r5, r5
  199. .Lwake6b:
  200. bra 8b
  201. nop
  202. 9:
  203. mov #-1, r0
  204. cmp/eq r0, r9
  205. bt/s 99f
  206. mov #FUTEX_WAKE, r5
  207. #ifdef __ASSUME_PRIVATE_FUTEX
  208. mov #(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), r5
  209. extu.b r5, r5
  210. #else
  211. stc gbr, r1
  212. mov.w .Lpfoff, r2
  213. add r2, r1
  214. mov.l @r1, r5
  215. mov #FUTEX_WAKE, r0
  216. or r0, r5
  217. #endif
  218. 99:
  219. mov #-1, r6
  220. shlr r6 /* r6 = 0x7fffffff */
  221. mov #0, r7
  222. mov #SYS_futex, r3
  223. extu.b r3, r3
  224. trapa #0x14
  225. SYSCALL_INST_PAD
  226. bra 10b
  227. nop
  228. #ifndef __ASSUME_PRIVATE_FUTEX
  229. .Lpfoff:
  230. .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
  231. #endif
  232. .align 2
  233. .Lwait5:
  234. .long __lll_lock_wait-.Lwait5b
  235. .Lwake5:
  236. .long __lll_unlock_wake-.Lwake5b
  237. .Lwake6:
  238. .long __lll_unlock_wake-.Lwake6b
  239. .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
  240. weak_alias (__pthread_cond_broadcast, pthread_cond_broadcast)