pthread_cond_signal.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright (C) 2002, 2003, 2004, 2005 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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <sysdep.h>
  17. #include <lowlevelcond.h>
  18. #include <bits/kernel-features.h>
  19. #ifdef UP
  20. # define LOCK
  21. #else
  22. # define LOCK lock
  23. #endif
  24. #define FUTEX_WAIT 0
  25. #define FUTEX_WAKE 1
  26. #define FUTEX_REQUEUE 3
  27. #define EINVAL 22
  28. .text
  29. /* int pthread_cond_signal (pthread_cond_t *cond) */
  30. .globl __pthread_cond_signal
  31. .type __pthread_cond_signal, @function
  32. .align 16
  33. __pthread_cond_signal:
  34. /* Get internal lock. */
  35. movq %rdi, %r8
  36. movl $1, %esi
  37. xorl %eax, %eax
  38. LOCK
  39. #if cond_lock == 0
  40. cmpxchgl %esi, (%rdi)
  41. #else
  42. cmpxchgl %esi, cond_lock(%rdi)
  43. #endif
  44. jnz 1f
  45. 2: addq $cond_futex, %rdi
  46. movq total_seq(%r8), %rcx
  47. cmpq wakeup_seq(%r8), %rcx
  48. jbe 4f
  49. /* Bump the wakeup number. */
  50. addq $1, wakeup_seq(%r8)
  51. addl $1, (%rdi)
  52. /* Wake up one thread. */
  53. movl $FUTEX_WAKE, %esi
  54. movl $SYS_futex, %eax
  55. movl $1, %edx
  56. syscall
  57. /* Unlock. */
  58. 4: LOCK
  59. #if cond_lock == 0
  60. decl (%r8)
  61. #else
  62. decl cond_lock(%r8)
  63. #endif
  64. jne 5f
  65. 6: xorl %eax, %eax
  66. retq
  67. /* Initial locking failed. */
  68. 1:
  69. #if cond_lock != 0
  70. addq $cond_lock, %rdi
  71. #endif
  72. callq __lll_mutex_lock_wait
  73. #if cond_lock != 0
  74. subq $cond_lock, %rdi
  75. #endif
  76. jmp 2b
  77. /* Unlock in loop requires wakeup. */
  78. 5:
  79. movq %r8, %rdi
  80. callq __lll_mutex_unlock_wake
  81. jmp 6b
  82. .size __pthread_cond_signal, .-__pthread_cond_signal
  83. versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal,
  84. GLIBC_2_3_2)