1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 *
25 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28
29 #ifndef _SEMAPHORE_H
30 #define _SEMAPHORE_H
31
32 #include <sys/feature_tests.h>
33
34 #include <sys/types.h>
35 #include <sys/fcntl.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 typedef struct {
42 /* this structure must be the same as sema_t in <synch.h> */
43 uint32_t sem_count; /* semaphore count */
44 uint16_t sem_type;
45 uint16_t sem_magic;
46 upad64_t sem_pad1[3]; /* reserved for a mutex_t */
47 upad64_t sem_pad2[2]; /* reserved for a cond_t */
48 } sem_t;
49
50 #define SEM_FAILED ((sem_t *)(-1))
51
52 /*
53 * function prototypes
54 */
55 int sem_init(sem_t *, int, unsigned int);
56 int sem_destroy(sem_t *);
57 sem_t *sem_open(const char *, int, ...);
58 int sem_close(sem_t *);
59 int sem_unlink(const char *);
60 int sem_wait(sem_t *);
61 /*
62 * Inclusion of <time.h> breaks X/Open and POSIX namespace.
63 * The timespec structure while allowed in XPG6 and POSIX.1003d-1999,
64 * is not permitted in prior POSIX or X/Open specifications even
65 * though functions beginning with sem_* are allowed.
66 */
67 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
68 struct timespec;
69 int sem_timedwait(sem_t *_RESTRICT_KYWD,
70 const struct timespec *_RESTRICT_KYWD);
71 int sem_reltimedwait_np(sem_t *_RESTRICT_KYWD,
72 const struct timespec *_RESTRICT_KYWD);
73 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
74 int sem_trywait(sem_t *);
75 int sem_post(sem_t *);
76 int sem_getvalue(sem_t *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
77
78 #ifdef __cplusplus
79 }
80 #endif
81
82 #endif /* _SEMAPHORE_H */