pthread_rwlock_unlock.S 2.7 KB

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