pthread_cond_broadcast.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* Copyright (C) 2003, 2004 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 <lowlevelcond.h>
  17. #include <bits/kernel-features.h>
  18. #include "lowlevel-atomic.h"
  19. #define FUTEX_WAIT 0
  20. #define FUTEX_WAKE 1
  21. #define FUTEX_REQUEUE 3
  22. #define FUTEX_CMP_REQUEUE 4
  23. #define EINVAL 22
  24. .text
  25. /* int pthread_cond_broadcast (pthread_cond_t *cond) */
  26. .globl __pthread_cond_broadcast
  27. .type __pthread_cond_broadcast, @function
  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. /* Wake up all threads. */
  86. mov #FUTEX_CMP_REQUEUE, r5
  87. mov #1, r6
  88. mov #-1, r7
  89. shlr r7 /* r7 = 0x7fffffff */
  90. mov r9, r0
  91. # if MUTEX_FUTEX != 0
  92. add #MUTEX_FUTEX, r0
  93. # endif
  94. mov r10, r1
  95. mov #SYS_futex, r3
  96. extu.b r3, r3
  97. trapa #0x16
  98. SYSCALL_INST_PAD
  99. /* For any kind of error, which mainly is EAGAIN, we try again
  100. with WAKE. The general test also covers running on old
  101. kernels. */
  102. mov r0, r1
  103. mov #-12, r2
  104. shad r2, r1
  105. not r1, r1
  106. tst r1, r1
  107. mov r8, r4
  108. bt/s 9f
  109. add #cond_futex, r4
  110. 10:
  111. mov #0, r0
  112. lds.l @r15+, pr
  113. mov.l @r15+, r8
  114. mov.l @r15+, r9
  115. rts
  116. mov.l @r15+, r10
  117. 4:
  118. /* Unlock. */
  119. #if cond_lock != 0
  120. DEC (@(cond_lock,r8), r2)
  121. #else
  122. DEC (@r8, r2)
  123. #endif
  124. tst r2, r2
  125. bf 5f
  126. 6:
  127. mov #0, r0
  128. lds.l @r15+, pr
  129. mov.l @r15+, r8
  130. mov.l @r15+, r9
  131. rts
  132. mov.l @r15+, r10
  133. 1:
  134. /* Initial locking failed. */
  135. mov r8, r5
  136. #if cond_lock != 0
  137. add #cond_lock, r5
  138. #endif
  139. mov.l .Lmwait5, r1
  140. bsrf r1
  141. mov r2, r4
  142. .Lmwait5b:
  143. bra 2b
  144. nop
  145. 5:
  146. /* Unlock in loop requires wakeup. */
  147. mov r8, r4
  148. #if cond_lock != 0
  149. add #cond_lock, r4
  150. #endif
  151. mov.l .Lmwake5, r1
  152. bsrf r1
  153. nop
  154. .Lmwake5b:
  155. bra 6b
  156. nop
  157. 7:
  158. /* Unlock in loop requires wakeup. */
  159. mov r8, r4
  160. #if cond_lock != 0
  161. add #cond_lock, r4
  162. #endif
  163. mov.l .Lmwake6, r1
  164. bsrf r1
  165. nop
  166. .Lmwake6b:
  167. bra 8b
  168. nop
  169. 9:
  170. mov #FUTEX_WAKE, r5
  171. mov #-1, r6
  172. shlr r6 /* r6 = 0x7fffffff */
  173. mov #0, r7
  174. mov #SYS_futex, r3
  175. extu.b r3, r3
  176. trapa #0x14
  177. SYSCALL_INST_PAD
  178. bra 10b
  179. nop
  180. .align 2
  181. .Lmwait5:
  182. .long __lll_mutex_lock_wait-.Lmwait5b
  183. .Lmwake5:
  184. .long __lll_mutex_unlock_wake-.Lmwake5b
  185. .Lmwake6:
  186. .long __lll_mutex_unlock_wake-.Lmwake6b
  187. .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
  188. weak_alias (__pthread_cond_broadcast, pthread_cond_broadcast)