sem_post.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <lowlevellock.h>
  17. #include <pthread-errnos.h>
  18. #include <structsem.h>
  19. .text
  20. .globl sem_post
  21. .type sem_post,@function
  22. .align 16
  23. sem_post:
  24. #if VALUE == 0
  25. movl (%rdi), %eax
  26. #else
  27. movl VALUE(%rdi), %eax
  28. #endif
  29. 0: cmpl $SEM_VALUE_MAX, %eax
  30. je 3f
  31. leal 1(%rax), %esi
  32. LOCK
  33. #if VALUE == 0
  34. cmpxchgl %esi, (%rdi)
  35. #else
  36. cmpxchgl %esi, VALUE(%rdi)
  37. #endif
  38. jnz 0b
  39. cmpq $0, NWAITERS(%rdi)
  40. je 2f
  41. movl $SYS_futex, %eax
  42. movl $FUTEX_WAKE, %esi
  43. orl PRIVATE(%rdi), %esi
  44. movl $1, %edx
  45. syscall
  46. testq %rax, %rax
  47. js 1f
  48. 2: xorl %eax, %eax
  49. retq
  50. 1:
  51. #if USE___THREAD
  52. movl $EINVAL, %eax
  53. #else
  54. callq __errno_location@plt
  55. movl $EINVAL, %edx
  56. #endif
  57. jmp 4f
  58. 3:
  59. #if USE___THREAD
  60. movl $EOVERFLOW, %eax
  61. #else
  62. callq __errno_location@plt
  63. movl $EOVERFLOW, %edx
  64. #endif
  65. 4:
  66. #if USE___THREAD
  67. movq errno@gottpoff(%rip), %rdx
  68. movl %eax, %fs:(%rdx)
  69. #else
  70. movl %edx, (%rax)
  71. #endif
  72. orl $-1, %eax
  73. retq
  74. .size sem_post,.-sem_post