pthread_rwlock_unlock.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Copyright (C) 2002, 2003, 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 <lowlevelrwlock.h>
  18. #define FUTEX_WAIT 0
  19. #define FUTEX_WAKE 1
  20. #ifndef UP
  21. # define LOCK lock
  22. #else
  23. # define LOCK
  24. #endif
  25. .text
  26. .globl __pthread_rwlock_unlock
  27. .type __pthread_rwlock_unlock,@function
  28. .align 16
  29. __pthread_rwlock_unlock:
  30. /* Get the lock. */
  31. movl $1, %esi
  32. xorl %eax, %eax
  33. LOCK
  34. #if MUTEX == 0
  35. cmpxchgl %esi, (%rdi)
  36. #else
  37. cmpxchgl %esi, MUTEX(%rdi)
  38. #endif
  39. jnz 1f
  40. 2: cmpl $0, WRITER(%rdi)
  41. jne 5f
  42. decl NR_READERS(%rdi)
  43. jnz 6f
  44. 5: movl $0, WRITER(%rdi)
  45. movl $1, %esi
  46. leaq WRITERS_WAKEUP(%rdi), %r10
  47. movq %rsi, %rdx
  48. cmpl $0, WRITERS_QUEUED(%rdi)
  49. jne 0f
  50. /* If also no readers waiting nothing to do. */
  51. cmpl $0, READERS_QUEUED(%rdi)
  52. je 6f
  53. movl $0x7fffffff, %edx
  54. leaq READERS_WAKEUP(%rdi), %r10
  55. 0: incl (%r10)
  56. LOCK
  57. #if MUTEX == 0
  58. decl (%rdi)
  59. #else
  60. decl MUTEX(%rdi)
  61. #endif
  62. jne 7f
  63. 8: movl $SYS_futex, %eax
  64. movq %r10, %rdi
  65. syscall
  66. xorl %eax, %eax
  67. retq
  68. .align 16
  69. 6: LOCK
  70. #if MUTEX == 0
  71. decl (%rdi)
  72. #else
  73. decl MUTEX(%rdi)
  74. #endif
  75. jne 3f
  76. 4: xorl %eax, %eax
  77. retq
  78. 1:
  79. #if MUTEX != 0
  80. addq $MUTEX, %rdi
  81. #endif
  82. callq __lll_mutex_lock_wait
  83. #if MUTEX != 0
  84. subq $MUTEX, %rdi
  85. #endif
  86. jmp 2b
  87. 3:
  88. #if MUTEX != 0
  89. addq $MUTEX, %rdi
  90. #endif
  91. callq __lll_mutex_unlock_wake
  92. jmp 4b
  93. 7:
  94. #if MUTEX != 0
  95. addq $MUTEX, %rdi
  96. #endif
  97. callq __lll_mutex_unlock_wake
  98. jmp 8b
  99. .size __pthread_rwlock_unlock,.-__pthread_rwlock_unlock
  100. .globl pthread_rwlock_unlock
  101. pthread_rwlock_unlock = __pthread_rwlock_unlock
  102. .globl __pthread_rwlock_unlock_internal
  103. __pthread_rwlock_unlock_internal = __pthread_rwlock_unlock