semaphore.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Copyright (C) 2002-2026 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. # ifndef __USE_TIME64_REDIRECTS
  46. extern int sem_timedwait (sem_t *__restrict __sem,
  47. const struct timespec *__restrict __abstime)
  48. __nonnull ((1, 2));
  49. # else
  50. # ifdef __REDIRECT
  51. extern int __REDIRECT (sem_timedwait,
  52. (sem_t *__restrict __sem,
  53. const struct timespec *__restrict __abstime),
  54. __sem_timedwait64)
  55. __nonnull ((1, 2));
  56. # else
  57. # define sem_timedwait __sem_timedwait64
  58. # endif
  59. # endif
  60. #endif
  61. #ifdef __USE_GNU
  62. # ifndef __USE_TIME64_REDIRECTS
  63. extern int sem_clockwait (sem_t *__restrict __sem,
  64. clockid_t clock,
  65. const struct timespec *__restrict __abstime)
  66. __nonnull ((1, 3));
  67. # else
  68. # ifdef __REDIRECT
  69. extern int __REDIRECT (sem_clockwait,
  70. (sem_t *__restrict __sem,
  71. clockid_t clock,
  72. const struct timespec *__restrict __abstime),
  73. __sem_clockwait64)
  74. __nonnull ((1, 3));
  75. # else
  76. # define sem_clockwait __sem_clockwait64
  77. # endif
  78. # endif
  79. #endif
  80. /* Test whether SEM is posted. */
  81. extern int sem_trywait (sem_t *__sem) __THROWNL __nonnull ((1));
  82. /* Post SEM. */
  83. extern int sem_post (sem_t *__sem) __THROWNL __nonnull ((1));
  84. /* Get current value of SEM and store it in *SVAL. */
  85. extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
  86. __THROW __nonnull ((1, 2));
  87. __END_DECLS
  88. #endif /* semaphore.h */