pthread_rwlock_unlock.S 2.6 KB

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