pthread_cond_signal.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* Copyright (C) 2003, 2004, 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-errnos.h>
  20. #include "lowlevel-atomic.h"
  21. .text
  22. /* int pthread_cond_signal (pthread_cond_t *cond) */
  23. .globl __pthread_cond_signal
  24. .type __pthread_cond_signal, @function
  25. .align 5
  26. __pthread_cond_signal:
  27. mov.l r8, @-r15
  28. sts.l pr, @-r15
  29. mov r4, r8
  30. /* Get internal lock. */
  31. mov #0, r3
  32. mov #1, r4
  33. #if cond_lock != 0
  34. CMPXCHG (r3, @(cond_lock,r8), r4, r2)
  35. #else
  36. CMPXCHG (r3, @r8, r4, r2)
  37. #endif
  38. bf 1f
  39. 2:
  40. mov.l @(total_seq+4,r8),r0
  41. mov.l @(total_seq,r8),r1
  42. mov.l @(wakeup_seq+4,r8), r2
  43. cmp/hi r2, r0
  44. bt 3f
  45. cmp/hi r0, r2
  46. bt 4f
  47. mov.l @(wakeup_seq,r8), r2
  48. cmp/hi r2, r1
  49. bf 4f
  50. 3:
  51. /* Bump the wakeup number. */
  52. mov #1, r2
  53. mov #0, r3
  54. clrt
  55. mov.l @(wakeup_seq,r8),r0
  56. mov.l @(wakeup_seq+4,r8),r1
  57. addc r2, r0
  58. addc r3, r1
  59. mov.l r0,@(wakeup_seq,r8)
  60. mov.l r1,@(wakeup_seq+4,r8)
  61. mov.l @(cond_futex,r8),r0
  62. add r2, r0
  63. mov.l r0,@(cond_futex,r8)
  64. /* Wake up one thread. */
  65. mov r8, r4
  66. add #cond_futex, r4
  67. mov.l @(dep_mutex,r8), r0
  68. cmp/eq #-1, r0
  69. bt/s 99f
  70. mov #FUTEX_WAKE_OP, r5
  71. #ifdef __ASSUME_PRIVATE_FUTEX
  72. mov #(FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG), r5
  73. extu.b r5, r5
  74. #else
  75. stc gbr, r1
  76. mov.w .Lpfoff, r2
  77. add r2, r1
  78. mov.l @r1, r5
  79. mov #FUTEX_WAKE_OP, r0
  80. or r0, r5
  81. #endif
  82. 99:
  83. mov #1, r6
  84. mov #0, r7
  85. mov r8, r0
  86. add #cond_lock, r0
  87. mov.l .Lfutexop, r1
  88. mov #SYS_futex, r3
  89. extu.b r3, r3
  90. trapa #0x14
  91. SYSCALL_INST_PAD
  92. /* For any kind of error, we try again with WAKE.
  93. The general test also covers running on old kernels. */
  94. mov r0, r1
  95. mov #-12, r2
  96. shad r2, r1
  97. not r1, r1
  98. tst r1, r1
  99. bt 7f
  100. 6:
  101. mov #0, r0
  102. lds.l @r15+, pr
  103. rts
  104. mov.l @r15+, r8
  105. #ifndef __ASSUME_PRIVATE_FUTEX
  106. .Lpfoff:
  107. .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
  108. #endif
  109. .align 2
  110. .Lfutexop:
  111. .long FUTEX_OP_CLEAR_WAKE_IF_GT_ONE
  112. 7:
  113. /* r5 should be either FUTEX_WAKE_OP or
  114. FUTEX_WAKE_OP|FUTEX_PRIVATE_FLAG from the previous syscall. */
  115. mov #(FUTEX_WAKE ^ FUTEX_WAKE_OP), r0
  116. xor r0, r5
  117. trapa #0x14
  118. SYSCALL_INST_PAD
  119. 4:
  120. /* Unlock. */
  121. #if cond_lock != 0
  122. DEC (@(cond_lock,r8), r2)
  123. #else
  124. DEC (@r8, r2)
  125. #endif
  126. tst r2, r2
  127. bt 6b
  128. 5:
  129. /* Unlock in loop requires wakeup. */
  130. mov r8, r4
  131. #if cond_lock != 0
  132. add #cond_lock, r4
  133. #endif
  134. mov.l @(dep_mutex,r8), r0
  135. cmp/eq #-1, r0
  136. bf/s 99f
  137. mov #LLL_PRIVATE, r5
  138. mov #LLL_SHARED, r5
  139. 99:
  140. mov.l .Lwake4, r1
  141. bsrf r1
  142. extu.b r5, r5
  143. .Lwake4b:
  144. bra 6b
  145. nop
  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 .Lwait4, r1
  160. bsrf r1
  161. mov r2, r4
  162. .Lwait4b:
  163. bra 2b
  164. nop
  165. .align 2
  166. .Lwait4:
  167. .long __lll_lock_wait-.Lwait4b
  168. .Lwake4:
  169. .long __lll_unlock_wake-.Lwake4b
  170. .size __pthread_cond_signal, .-__pthread_cond_signal
  171. weak_alias (__pthread_cond_signal, pthread_cond_signal)