sem_post.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Copyright (C) 2002, 2003, 2005, 2007, 2008 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 <pthread-errnos.h>
  17. #include <structsem.h>
  18. #include <lowlevellock.h>
  19. .text
  20. .globl sem_post
  21. .type sem_post,@function
  22. .align 16
  23. sem_post:
  24. cfi_startproc
  25. pushl %ebx
  26. cfi_adjust_cfa_offset(4)
  27. cfi_offset(%ebx, -8)
  28. movl 8(%esp), %ebx
  29. #if VALUE == 0
  30. movl (%ebx), %eax
  31. #else
  32. movl VALUE(%ebx), %eax
  33. #endif
  34. 0: cmpl $SEM_VALUE_MAX, %eax
  35. je 3f
  36. leal 1(%eax), %edx
  37. LOCK
  38. #if VALUE == 0
  39. cmpxchgl %edx, (%ebx)
  40. #else
  41. cmpxchgl %edx, VALUE(%ebx)
  42. #endif
  43. jnz 0b
  44. cmpl $0, NWAITERS(%ebx)
  45. je 2f
  46. movl $FUTEX_WAKE, %ecx
  47. orl PRIVATE(%ebx), %ecx
  48. movl $1, %edx
  49. movl $SYS_futex, %eax
  50. ENTER_KERNEL
  51. testl %eax, %eax
  52. js 1f
  53. 2: xorl %eax, %eax
  54. popl %ebx
  55. cfi_adjust_cfa_offset(-4)
  56. cfi_restore(%ebx)
  57. ret
  58. cfi_adjust_cfa_offset(4)
  59. cfi_offset(%ebx, -8)
  60. 1:
  61. #ifdef __PIC__
  62. call __x86.get_pc_thunk.bx
  63. #else
  64. movl $4f, %ebx
  65. 4:
  66. #endif
  67. addl $_GLOBAL_OFFSET_TABLE_, %ebx
  68. #if USE___THREAD
  69. # ifdef NO_TLS_DIRECT_SEG_REFS
  70. movl errno@gotntpoff(%ebx), %edx
  71. addl %gs:0, %edx
  72. movl $EINVAL, (%edx)
  73. # else
  74. movl errno@gotntpoff(%ebx), %edx
  75. movl $EINVAL, %gs:(%edx)
  76. # endif
  77. #else
  78. call __errno_location@plt
  79. movl $EINVAL, (%eax)
  80. #endif
  81. orl $-1, %eax
  82. popl %ebx
  83. ret
  84. 3:
  85. #ifdef __PIC__
  86. call __x86.get_pc_thunk.bx
  87. #else
  88. movl $5f, %ebx
  89. 5:
  90. #endif
  91. addl $_GLOBAL_OFFSET_TABLE_, %ebx
  92. #if USE___THREAD
  93. # ifdef NO_TLS_DIRECT_SEG_REFS
  94. movl errno@gotntpoff(%ebx), %edx
  95. addl %gs:0, %edx
  96. movl $EOVERFLOW, (%edx)
  97. # else
  98. movl errno@gotntpoff(%ebx), %edx
  99. movl $EOVERFLOW, %gs:(%edx)
  100. # endif
  101. #else
  102. call __errno_location@plt
  103. movl $EOVERFLOW, (%eax)
  104. #endif
  105. orl $-1, %eax
  106. popl %ebx
  107. cfi_adjust_cfa_offset(-4)
  108. cfi_restore(%ebx)
  109. ret
  110. cfi_endproc
  111. .size sem_post,.-sem_post
  112. #ifdef __PIC__
  113. .section .gnu.linkonce.t.__x86.get_pc_thunk.bx,"ax",@progbits
  114. .globl __x86.get_pc_thunk.bx
  115. .hidden __x86.get_pc_thunk.bx
  116. .type __x86.get_pc_thunk.bx,@function
  117. __x86.get_pc_thunk.bx:
  118. movl (%esp), %ebx;
  119. ret
  120. .size __x86.get_pc_thunk.bx,.-__x86.get_pc_thunk.bx
  121. #endif