pthread_cond_signal.S 3.7 KB

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