semaphore.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (C) 2002-2020 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. <https://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 __nonnull ((1));
  28. /* Free resources associated with semaphore object SEM. */
  29. extern int sem_destroy (sem_t *__sem) __THROW __nonnull ((1));
  30. /* Open a named semaphore NAME with open flags OFLAG. */
  31. extern sem_t *sem_open (const char *__name, int __oflag, ...)
  32. __THROW __nonnull ((1));
  33. /* Close descriptor for named semaphore SEM. */
  34. extern int sem_close (sem_t *__sem) __THROW __nonnull ((1));
  35. /* Remove named semaphore NAME. */
  36. extern int sem_unlink (const char *__name) __THROW __nonnull ((1));
  37. /* Wait for SEM being posted.
  38. This function is a cancellation point and therefore not marked with
  39. __THROW. */
  40. extern int sem_wait (sem_t *__sem) __nonnull ((1));
  41. #ifdef __USE_XOPEN2K
  42. /* Similar to `sem_wait' but wait only until ABSTIME.
  43. This function is a cancellation point and therefore not marked with
  44. __THROW. */
  45. extern int sem_timedwait (sem_t *__restrict __sem,
  46. const struct timespec *__restrict __abstime)
  47. __nonnull ((1, 2));
  48. #endif
  49. #ifdef __USE_GNU
  50. extern int sem_clockwait (sem_t *__restrict __sem,
  51. clockid_t clock,
  52. const struct timespec *__restrict __abstime)
  53. __nonnull ((1, 3));
  54. #endif
  55. /* Test whether SEM is posted. */
  56. extern int sem_trywait (sem_t *__sem) __THROWNL __nonnull ((1));
  57. /* Post SEM. */
  58. extern int sem_post (sem_t *__sem) __THROWNL __nonnull ((1));
  59. /* Get current value of SEM and store it in *SVAL. */
  60. extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
  61. __THROW __nonnull ((1, 2));
  62. __END_DECLS
  63. #endif /* semaphore.h */