pthread_rwlock_timedwrlock.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 <pthread-errnos.h>
  19. #include <bits/kernel-features.h>
  20. #include <tls.h>
  21. .text
  22. .globl pthread_rwlock_timedwrlock
  23. .type pthread_rwlock_timedwrlock,@function
  24. .align 16
  25. pthread_rwlock_timedwrlock:
  26. cfi_startproc
  27. pushl %esi
  28. cfi_adjust_cfa_offset(4)
  29. pushl %edi
  30. cfi_adjust_cfa_offset(4)
  31. pushl %ebx
  32. cfi_adjust_cfa_offset(4)
  33. pushl %ebp
  34. cfi_adjust_cfa_offset(4)
  35. cfi_offset(%esi, -8)
  36. cfi_offset(%edi, -12)
  37. cfi_offset(%ebx, -16)
  38. cfi_offset(%ebp, -20)
  39. subl $8, %esp
  40. cfi_adjust_cfa_offset(8)
  41. movl 28(%esp), %ebp
  42. movl 32(%esp), %edi
  43. /* Get the lock. */
  44. movl $1, %edx
  45. xorl %eax, %eax
  46. LOCK
  47. #if MUTEX == 0
  48. cmpxchgl %edx, (%ebp)
  49. #else
  50. cmpxchgl %edx, MUTEX(%ebp)
  51. #endif
  52. jnz 1f
  53. 2: movl WRITER(%ebp), %eax
  54. testl %eax, %eax
  55. jne 14f
  56. cmpl $0, NR_READERS(%ebp)
  57. je 5f
  58. /* Check the value of the timeout parameter. */
  59. 3: cmpl $1000000000, 4(%edi)
  60. jae 19f
  61. addl $1, WRITERS_QUEUED(%ebp)
  62. je 4f
  63. movl WRITERS_WAKEUP(%ebp), %esi
  64. LOCK
  65. #if MUTEX == 0
  66. subl $1, (%ebp)
  67. #else
  68. subl $1, MUTEX(%ebp)
  69. #endif
  70. jne 10f
  71. /* Get current time. */
  72. 11: movl %esp, %ebx
  73. xorl %ecx, %ecx
  74. movl $__NR_gettimeofday, %eax
  75. ENTER_KERNEL
  76. /* Compute relative timeout. */
  77. movl 4(%esp), %eax
  78. movl $1000, %edx
  79. mul %edx /* Milli seconds to nano seconds. */
  80. movl (%edi), %ecx
  81. movl 4(%edi), %edx
  82. subl (%esp), %ecx
  83. subl %eax, %edx
  84. jns 15f
  85. addl $1000000000, %edx
  86. subl $1, %ecx
  87. 15: testl %ecx, %ecx
  88. js 16f /* Time is already up. */
  89. /* Futex call. */
  90. movl %ecx, (%esp) /* Store relative timeout. */
  91. movl %edx, 4(%esp)
  92. movl %esi, %edx
  93. #ifdef __ASSUME_PRIVATE_FUTEX
  94. movzbl PSHARED(%ebp), %ecx
  95. xorl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT, %ecx
  96. #else
  97. movzbl PSHARED(%ebp), %ecx
  98. # if FUTEX_WAIT != 0
  99. orl $FUTEX_WAIT, %ecx
  100. # endif
  101. xorl %gs:PRIVATE_FUTEX, %ecx
  102. #endif
  103. movl %esp, %esi
  104. leal WRITERS_WAKEUP(%ebp), %ebx
  105. movl $SYS_futex, %eax
  106. ENTER_KERNEL
  107. movl %eax, %esi
  108. 17:
  109. /* Reget the lock. */
  110. movl $1, %edx
  111. xorl %eax, %eax
  112. LOCK
  113. #if MUTEX == 0
  114. cmpxchgl %edx, (%ebp)
  115. #else
  116. cmpxchgl %edx, MUTEX(%ebp)
  117. #endif
  118. jnz 12f
  119. 13: subl $1, WRITERS_QUEUED(%ebp)
  120. cmpl $-ETIMEDOUT, %esi
  121. jne 2b
  122. 18: movl $ETIMEDOUT, %edx
  123. jmp 9f
  124. 5: xorl %edx, %edx
  125. movl %gs:TID, %eax
  126. movl %eax, WRITER(%ebp)
  127. 9: LOCK
  128. #if MUTEX == 0
  129. subl $1, (%ebp)
  130. #else
  131. subl $1, MUTEX(%ebp)
  132. #endif
  133. jne 6f
  134. 7: movl %edx, %eax
  135. addl $8, %esp
  136. cfi_adjust_cfa_offset(-8)
  137. popl %ebp
  138. cfi_adjust_cfa_offset(-4)
  139. cfi_restore(%ebp)
  140. popl %ebx
  141. cfi_adjust_cfa_offset(-4)
  142. cfi_restore(%ebx)
  143. popl %edi
  144. cfi_adjust_cfa_offset(-4)
  145. cfi_restore(%edi)
  146. popl %esi
  147. cfi_adjust_cfa_offset(-4)
  148. cfi_restore(%esi)
  149. ret
  150. cfi_adjust_cfa_offset(24)
  151. cfi_offset(%esi, -8)
  152. cfi_offset(%edi, -12)
  153. cfi_offset(%ebx, -16)
  154. cfi_offset(%ebp, -20)
  155. 1:
  156. #if MUTEX == 0
  157. movl %ebp, %edx
  158. #else
  159. leal MUTEX(%ebp), %edx
  160. #endif
  161. movzbl PSHARED(%ebp), %ecx
  162. call __lll_lock_wait
  163. jmp 2b
  164. 14: cmpl %gs:TID, %eax
  165. jne 3b
  166. 20: movl $EDEADLK, %edx
  167. jmp 9b
  168. 6:
  169. #if MUTEX == 0
  170. movl %ebp, %eax
  171. #else
  172. leal MUTEX(%ebp), %eax
  173. #endif
  174. movzbl PSHARED(%ebp), %ecx
  175. call __lll_unlock_wake
  176. jmp 7b
  177. /* Overflow. */
  178. 4: subl $1, WRITERS_QUEUED(%ebp)
  179. movl $EAGAIN, %edx
  180. jmp 9b
  181. 10:
  182. #if MUTEX == 0
  183. movl %ebp, %eax
  184. #else
  185. leal MUTEX(%ebp), %eax
  186. #endif
  187. movzbl PSHARED(%ebp), %ecx
  188. call __lll_unlock_wake
  189. jmp 11b
  190. 12:
  191. #if MUTEX == 0
  192. movl %ebp, %edx
  193. #else
  194. leal MUTEX(%ebp), %edx
  195. #endif
  196. movzbl PSHARED(%ebp), %ecx
  197. call __lll_lock_wait
  198. jmp 13b
  199. 16: movl $-ETIMEDOUT, %esi
  200. jmp 17b
  201. 19: movl $EINVAL, %edx
  202. jmp 9b
  203. cfi_endproc
  204. .size pthread_rwlock_timedwrlock,.-pthread_rwlock_timedwrlock