xref: /illumos-gate/usr/src/head/semaphore.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SEMAPHORE_H
28 #define	_SEMAPHORE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
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 #if	defined(__STDC__)
56 int	sem_init(sem_t *, int, unsigned int);
57 int	sem_destroy(sem_t *);
58 sem_t	*sem_open(const char *, int, ...);
59 int	sem_close(sem_t *);
60 int	sem_unlink(const char *);
61 int	sem_wait(sem_t *);
62 /*
63  * Inclusion of <time.h> breaks X/Open and POSIX namespace.
64  * The timespec structure while allowed in XPG6 and POSIX.1003d-1999,
65  * is not permitted in prior POSIX or X/Open specifications even
66  * though functions beginning with sem_* are allowed.
67  */
68 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
69 struct timespec;
70 int	sem_timedwait(sem_t *_RESTRICT_KYWD,
71 		const struct timespec *_RESTRICT_KYWD);
72 int	sem_reltimedwait_np(sem_t *_RESTRICT_KYWD,
73 		const struct timespec *_RESTRICT_KYWD);
74 #endif	/* !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
75 int	sem_trywait(sem_t *);
76 int	sem_post(sem_t *);
77 int	sem_getvalue(sem_t *_RESTRICT_KYWD, int *_RESTRICT_KYWD);
78 #else
79 int	sem_init();
80 int	sem_destroy();
81 sem_t	*sem_open();
82 int	sem_close();
83 int	sem_unlink();
84 int	sem_wait();
85 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
86 int	sem_timedwait();
87 int	sem_reltimedwait_np();
88 #endif	/* #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
89 int	sem_trywait();
90 int	sem_post();
91 int	sem_getvalue();
92 #endif	/* __STDC__ */
93 
94 #ifdef	__cplusplus
95 }
96 #endif
97 
98 #endif	/* _SEMAPHORE_H */
99