sem_post.S 1.8 KB

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