1 /* Copyright (C) 2002-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 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.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
19 #define _SEMAPHORE_H 1
22 #include <sys/types.h>
24 # include <bits/types/struct_timespec.h>
27 /* Get the definition for sem_t. */
28 #include <bits/semaphore.h>
33 /* Initialize semaphore object SEM to VALUE. If PSHARED then share it
34 with other processes. */
35 extern int sem_init (sem_t
*__sem
, int __pshared
, unsigned int __value
)
36 __THROW
__nonnull ((1));
38 /* Free resources associated with semaphore object SEM. */
39 extern int sem_destroy (sem_t
*__sem
) __THROW
__nonnull ((1));
41 /* Open a named semaphore NAME with open flags OFLAG. */
42 extern sem_t
*sem_open (const char *__name
, int __oflag
, ...)
43 __THROW
__nonnull ((1));
45 /* Close descriptor for named semaphore SEM. */
46 extern int sem_close (sem_t
*__sem
) __THROW
__nonnull ((1));
48 /* Remove named semaphore NAME. */
49 extern int sem_unlink (const char *__name
) __THROW
__nonnull ((1));
51 /* Wait for SEM being posted.
53 This function is a cancellation point and therefore not marked with
55 extern int sem_wait (sem_t
*__sem
) __nonnull ((1));
58 /* Similar to `sem_wait' but wait only until ABSTIME.
60 This function is a cancellation point and therefore not marked with
62 # ifndef __USE_TIME_BITS64
63 extern int sem_timedwait (sem_t
*__restrict __sem
,
64 const struct timespec
*__restrict __abstime
)
68 extern int __REDIRECT (sem_timedwait
,
69 (sem_t
*__restrict __sem
,
70 const struct timespec
*__restrict __abstime
),
74 # define sem_timedwait __sem_timedwait64
80 # ifndef __USE_TIME_BITS64
81 extern int sem_clockwait (sem_t
*__restrict __sem
,
83 const struct timespec
*__restrict __abstime
)
87 extern int __REDIRECT (sem_clockwait
,
88 (sem_t
*__restrict __sem
,
90 const struct timespec
*__restrict __abstime
),
94 # define sem_clockwait __sem_clockwait64
99 /* Test whether SEM is posted. */
100 extern int sem_trywait (sem_t
*__sem
) __THROWNL
__nonnull ((1));
103 extern int sem_post (sem_t
*__sem
) __THROWNL
__nonnull ((1));
105 /* Get current value of SEM and store it in *SVAL. */
106 extern int sem_getvalue (sem_t
*__restrict __sem
, int *__restrict __sval
)
107 __THROW
__nonnull ((1, 2));
112 #endif /* semaphore.h */