sem_post.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* sem_post -- post to a POSIX semaphore. SPARC version.
  2. Copyright (C) 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <errno.h>
  17. #include <sysdep.h>
  18. #include <lowlevellock.h>
  19. #include <internaltypes.h>
  20. #include <semaphore.h>
  21. int
  22. sem_post (sem_t *sem)
  23. {
  24. struct sparc_new_sem *isem = (struct sparc_new_sem *) sem;
  25. int nr;
  26. if (__atomic_is_v9)
  27. nr = atomic_increment_val (&isem->value);
  28. else
  29. {
  30. __sparc32_atomic_do_lock24 (&isem->lock);
  31. nr = ++(isem->value);
  32. __sparc32_atomic_do_unlock24 (&isem->lock);
  33. }
  34. atomic_full_barrier ();
  35. if (isem->nwaiters > 0)
  36. {
  37. int err = lll_futex_wake (&isem->value, 1,
  38. isem->private ^ FUTEX_PRIVATE_FLAG);
  39. if (__builtin_expect (err, 0) < 0)
  40. {
  41. __set_errno (-err);
  42. return -1;
  43. }
  44. }
  45. return 0;
  46. }