pthread_rwlock_unlock.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* Copyright (C) 2002, 2003, 2007 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 <lowlevelrwlock.h>
  18. #include <bits/kernel-features.h>
  19. #include <tls.h>
  20. .text
  21. .globl __pthread_rwlock_unlock
  22. .type __pthread_rwlock_unlock,@function
  23. .protected __pthread_rwlock_unlock
  24. .align 16
  25. __pthread_rwlock_unlock:
  26. cfi_startproc
  27. pushl %ebx
  28. cfi_adjust_cfa_offset(4)
  29. pushl %edi
  30. cfi_adjust_cfa_offset(4)
  31. cfi_offset(%ebx, -8)
  32. cfi_offset(%edi, -12)
  33. movl 12(%esp), %edi
  34. /* Get the lock. */
  35. movl $1, %edx
  36. xorl %eax, %eax
  37. LOCK
  38. #if MUTEX == 0
  39. cmpxchgl %edx, (%edi)
  40. #else
  41. cmpxchgl %edx, MUTEX(%edi)
  42. #endif
  43. jnz 1f
  44. 2: cmpl $0, WRITER(%edi)
  45. jne 5f
  46. subl $1, NR_READERS(%edi)
  47. jnz 6f
  48. 5: movl $0, WRITER(%edi)
  49. movl $1, %edx
  50. leal WRITERS_WAKEUP(%edi), %ebx
  51. cmpl $0, WRITERS_QUEUED(%edi)
  52. jne 0f
  53. /* If also no readers waiting nothing to do. */
  54. cmpl $0, READERS_QUEUED(%edi)
  55. je 6f
  56. movl $0x7fffffff, %edx
  57. leal READERS_WAKEUP(%edi), %ebx
  58. 0: addl $1, (%ebx)
  59. LOCK
  60. #if MUTEX == 0
  61. subl $1, (%edi)
  62. #else
  63. subl $1, MUTEX(%edi)
  64. #endif
  65. jne 7f
  66. 8:
  67. #ifdef __ASSUME_PRIVATE_FUTEX
  68. movzbl PSHARED(%edi), %ecx
  69. xorl $FUTEX_PRIVATE_FLAG|FUTEX_WAKE, %ecx
  70. #else
  71. movzbl PSHARED(%edi), %ecx
  72. orl $FUTEX_WAKE, %ecx
  73. xorl %gs:PRIVATE_FUTEX, %ecx
  74. #endif
  75. movl $SYS_futex, %eax
  76. ENTER_KERNEL
  77. xorl %eax, %eax
  78. popl %edi
  79. cfi_adjust_cfa_offset(-4)
  80. cfi_restore(%edi)
  81. popl %ebx
  82. cfi_adjust_cfa_offset(-4)
  83. cfi_restore(%ebx)
  84. ret
  85. cfi_adjust_cfa_offset(8)
  86. cfi_offset(%ebx, -8)
  87. cfi_offset(%edi, -12)
  88. .align 16
  89. 6: LOCK
  90. #if MUTEX == 0
  91. subl $1, (%edi)
  92. #else
  93. subl $1, MUTEX(%edi)
  94. #endif
  95. jne 3f
  96. 4: xorl %eax, %eax
  97. popl %edi
  98. popl %ebx
  99. ret
  100. 1:
  101. #if MUTEX == 0
  102. movl %edi, %edx
  103. #else
  104. leal MUTEX(%edi), %edx
  105. #endif
  106. movzbl PSHARED(%edi), %ecx
  107. call __lll_lock_wait
  108. jmp 2b
  109. 3:
  110. #if MUTEX == 0
  111. movl %edi, %eax
  112. #else
  113. leal MUTEX(%edi), %eax
  114. #endif
  115. movzbl PSHARED(%edi), %ecx
  116. call __lll_unlock_wake
  117. jmp 4b
  118. 7:
  119. #if MUTEX == 0
  120. movl %edi, %eax
  121. #else
  122. leal MUTEX(%edi), %eax
  123. #endif
  124. movzbl PSHARED(%edi), %ecx
  125. call __lll_unlock_wake
  126. jmp 8b
  127. cfi_endproc
  128. .size __pthread_rwlock_unlock,.-__pthread_rwlock_unlock
  129. .globl pthread_rwlock_unlock
  130. pthread_rwlock_unlock = __pthread_rwlock_unlock
  131. .globl __pthread_rwlock_unlock_internal
  132. __pthread_rwlock_unlock_internal = __pthread_rwlock_unlock