pthread_cond_broadcast.S 4.9 KB

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