pthread_cond_broadcast.S 4.9 KB

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