pthread_cond_signal.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* Copyright (C) 2002,2003,2004,2005,2007,2009 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  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 <tls.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 16
  28. __pthread_cond_signal:
  29. cfi_startproc
  30. pushl %ebx
  31. cfi_adjust_cfa_offset(4)
  32. cfi_rel_offset(%ebx, 0)
  33. pushl %edi
  34. cfi_adjust_cfa_offset(4)
  35. cfi_rel_offset(%edi, 0)
  36. cfi_remember_state
  37. movl 12(%esp), %edi
  38. /* Get internal lock. */
  39. movl $1, %edx
  40. xorl %eax, %eax
  41. LOCK
  42. #if cond_lock == 0
  43. cmpxchgl %edx, (%edi)
  44. #else
  45. cmpxchgl %edx, cond_lock(%edi)
  46. #endif
  47. jnz 1f
  48. 2: leal cond_futex(%edi), %ebx
  49. movl total_seq+4(%edi), %eax
  50. movl total_seq(%edi), %ecx
  51. cmpl wakeup_seq+4(%edi), %eax
  52. #if cond_lock != 0
  53. /* Must use leal to preserve the flags. */
  54. leal cond_lock(%edi), %edi
  55. #endif
  56. ja 3f
  57. jb 4f
  58. cmpl wakeup_seq-cond_futex(%ebx), %ecx
  59. jbe 4f
  60. /* Bump the wakeup number. */
  61. 3: addl $1, wakeup_seq-cond_futex(%ebx)
  62. adcl $0, wakeup_seq-cond_futex+4(%ebx)
  63. addl $1, (%ebx)
  64. /* Wake up one thread. */
  65. pushl %esi
  66. cfi_adjust_cfa_offset(4)
  67. cfi_rel_offset(%esi, 0)
  68. pushl %ebp
  69. cfi_adjust_cfa_offset(4)
  70. cfi_rel_offset(%ebp, 0)
  71. #if FUTEX_PRIVATE_FLAG > 255
  72. xorl %ecx, %ecx
  73. #endif
  74. cmpl $-1, dep_mutex-cond_futex(%ebx)
  75. sete %cl
  76. je 8f
  77. movl dep_mutex-cond_futex(%ebx), %edx
  78. /* Requeue to a non-robust PI mutex if the PI bit is set and
  79. the robust bit is not set. */
  80. movl MUTEX_KIND(%edx), %eax
  81. andl $(ROBUST_BIT|PI_BIT), %eax
  82. cmpl $PI_BIT, %eax
  83. je 9f
  84. 8: subl $1, %ecx
  85. #ifdef __ASSUME_PRIVATE_FUTEX
  86. andl $FUTEX_PRIVATE_FLAG, %ecx
  87. #else
  88. andl %gs:PRIVATE_FUTEX, %ecx
  89. #endif
  90. addl $FUTEX_WAKE_OP, %ecx
  91. movl $SYS_futex, %eax
  92. movl $1, %edx
  93. movl $1, %esi
  94. movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %ebp
  95. /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for
  96. sysenter.
  97. ENTER_KERNEL */
  98. int $0x80
  99. popl %ebp
  100. cfi_adjust_cfa_offset(-4)
  101. cfi_restore(%ebp)
  102. popl %esi
  103. cfi_adjust_cfa_offset(-4)
  104. cfi_restore(%esi)
  105. /* For any kind of error, we try again with WAKE.
  106. The general test also covers running on old kernels. */
  107. cmpl $-4095, %eax
  108. jae 7f
  109. 6: xorl %eax, %eax
  110. popl %edi
  111. cfi_adjust_cfa_offset(-4)
  112. cfi_restore(%edi)
  113. popl %ebx
  114. cfi_adjust_cfa_offset(-4)
  115. cfi_restore(%ebx)
  116. ret
  117. cfi_restore_state
  118. 9: movl $(FUTEX_CMP_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %ecx
  119. movl $SYS_futex, %eax
  120. movl $1, %edx
  121. xorl %esi, %esi
  122. movl dep_mutex-cond_futex(%ebx), %edi
  123. movl (%ebx), %ebp
  124. /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for
  125. sysenter.
  126. ENTER_KERNEL */
  127. int $0x80
  128. popl %ebp
  129. popl %esi
  130. leal -cond_futex(%ebx), %edi
  131. /* For any kind of error, we try again with WAKE.
  132. The general test also covers running on old kernels. */
  133. cmpl $-4095, %eax
  134. jb 4f
  135. 7:
  136. #ifdef __ASSUME_PRIVATE_FUTEX
  137. andl $FUTEX_PRIVATE_FLAG, %ecx
  138. #else
  139. andl %gs:PRIVATE_FUTEX, %ecx
  140. #endif
  141. orl $FUTEX_WAKE, %ecx
  142. xorl $(FUTEX_WAKE ^ FUTEX_WAKE_OP), %ecx
  143. movl $SYS_futex, %eax
  144. /* %edx should be 1 already from $FUTEX_WAKE_OP syscall.
  145. movl $1, %edx */
  146. ENTER_KERNEL
  147. /* Unlock. Note that at this point %edi always points to
  148. cond_lock. */
  149. 4: LOCK
  150. subl $1, (%edi)
  151. je 6b
  152. /* Unlock in loop requires wakeup. */
  153. 5: movl %edi, %eax
  154. #if (LLL_SHARED-LLL_PRIVATE) > 255
  155. xorl %ecx, %ecx
  156. #endif
  157. cmpl $-1, dep_mutex-cond_futex(%ebx)
  158. setne %cl
  159. subl $1, %ecx
  160. andl $(LLL_SHARED-LLL_PRIVATE), %ecx
  161. #if LLL_PRIVATE != 0
  162. addl $LLL_PRIVATE, %ecx
  163. #endif
  164. call __lll_unlock_wake
  165. jmp 6b
  166. /* Initial locking failed. */
  167. 1:
  168. #if cond_lock == 0
  169. movl %edi, %edx
  170. #else
  171. leal cond_lock(%edi), %edx
  172. #endif
  173. #if (LLL_SHARED-LLL_PRIVATE) > 255
  174. xorl %ecx, %ecx
  175. #endif
  176. cmpl $-1, dep_mutex(%edi)
  177. setne %cl
  178. subl $1, %ecx
  179. andl $(LLL_SHARED-LLL_PRIVATE), %ecx
  180. #if LLL_PRIVATE != 0
  181. addl $LLL_PRIVATE, %ecx
  182. #endif
  183. call __lll_lock_wait
  184. jmp 2b
  185. cfi_endproc
  186. .size __pthread_cond_signal, .-__pthread_cond_signal
  187. weak_alias(__pthread_cond_signal, pthread_cond_signal)