sem_post.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <errno.h>
  18. #include <sysdep.h>
  19. #include <lowlevellock.h>
  20. #include <internaltypes.h>
  21. #include <semaphore.h>
  22. int
  23. sem_post (sem_t *sem)
  24. {
  25. struct sparc_new_sem *isem = (struct sparc_new_sem *) sem;
  26. int nr;
  27. if (__atomic_is_v9)
  28. nr = atomic_increment_val (&isem->value);
  29. else
  30. {
  31. __sparc32_atomic_do_lock24 (&isem->lock);
  32. nr = ++(isem->value);
  33. __sparc32_atomic_do_unlock24 (&isem->lock);
  34. }
  35. atomic_full_barrier ();
  36. if (isem->nwaiters > 0)
  37. {
  38. int err = lll_futex_wake (&isem->value, 1,
  39. isem->private ^ FUTEX_PRIVATE_FLAG);
  40. if (__builtin_expect (err, 0) < 0)
  41. {
  42. __set_errno (-err);
  43. return -1;
  44. }
  45. }
  46. return 0;
  47. }