semaphore.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (C) 2002-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _SEMAPHORE_H
  15. #define _SEMAPHORE_H 1
  16. #include <features.h>
  17. #include <sys/types.h>
  18. #ifdef __USE_XOPEN2K
  19. # include <bits/types/struct_timespec.h>
  20. #endif
  21. /* Get the definition for sem_t. */
  22. #include <bits/semaphore.h>
  23. __BEGIN_DECLS
  24. /* Initialize semaphore object SEM to VALUE. If PSHARED then share it
  25. with other processes. */
  26. extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value)
  27. __THROW;
  28. /* Free resources associated with semaphore object SEM. */
  29. extern int sem_destroy (sem_t *__sem) __THROW;
  30. /* Open a named semaphore NAME with open flags OFLAG. */
  31. extern sem_t *sem_open (const char *__name, int __oflag, ...) __THROW;
  32. /* Close descriptor for named semaphore SEM. */
  33. extern int sem_close (sem_t *__sem) __THROW;
  34. /* Remove named semaphore NAME. */
  35. extern int sem_unlink (const char *__name) __THROW;
  36. /* Wait for SEM being posted.
  37. This function is a cancellation point and therefore not marked with
  38. __THROW. */
  39. extern int sem_wait (sem_t *__sem);
  40. #ifdef __USE_XOPEN2K
  41. /* Similar to `sem_wait' but wait only until ABSTIME.
  42. This function is a cancellation point and therefore not marked with
  43. __THROW. */
  44. extern int sem_timedwait (sem_t *__restrict __sem,
  45. const struct timespec *__restrict __abstime);
  46. #endif
  47. /* Test whether SEM is posted. */
  48. extern int sem_trywait (sem_t *__sem) __THROWNL;
  49. /* Post SEM. */
  50. extern int sem_post (sem_t *__sem) __THROWNL;
  51. /* Get current value of SEM and store it in *SVAL. */
  52. extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
  53. __THROW;
  54. __END_DECLS
  55. #endif /* semaphore.h */