xref: /illumos-gate/usr/src/cmd/scadm/sparc/mpxu/common/xsem.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1*03831d35Sstevel /*
2*03831d35Sstevel  * CDDL HEADER START
3*03831d35Sstevel  *
4*03831d35Sstevel  * The contents of this file are subject to the terms of the
5*03831d35Sstevel  * Common Development and Distribution License, Version 1.0 only
6*03831d35Sstevel  * (the "License").  You may not use this file except in compliance
7*03831d35Sstevel  * with the License.
8*03831d35Sstevel  *
9*03831d35Sstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*03831d35Sstevel  * or http://www.opensolaris.org/os/licensing.
11*03831d35Sstevel  * See the License for the specific language governing permissions
12*03831d35Sstevel  * and limitations under the License.
13*03831d35Sstevel  *
14*03831d35Sstevel  * When distributing Covered Code, include this CDDL HEADER in each
15*03831d35Sstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*03831d35Sstevel  * If applicable, add the following below this CDDL HEADER, with the
17*03831d35Sstevel  * fields enclosed by brackets "[]" replaced with your own identifying
18*03831d35Sstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
19*03831d35Sstevel  *
20*03831d35Sstevel  * CDDL HEADER END
21*03831d35Sstevel  */
22*03831d35Sstevel /*
23*03831d35Sstevel  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*03831d35Sstevel  * Use is subject to license terms.
25*03831d35Sstevel  */
26*03831d35Sstevel 
27*03831d35Sstevel #ifndef	__XSEM_H__
28*03831d35Sstevel #define	__XSEM_H__
29*03831d35Sstevel 
30*03831d35Sstevel #ifdef	__cplusplus
31*03831d35Sstevel extern "C" {
32*03831d35Sstevel #endif
33*03831d35Sstevel 
34*03831d35Sstevel /*
35*03831d35Sstevel  * xsem.h: to provide a semaphore system (used by the smq routines)
36*03831d35Sstevel  *
37*03831d35Sstevel  * these routines come from the libxposix library.
38*03831d35Sstevel  */
39*03831d35Sstevel 
40*03831d35Sstevel #include <pthread.h>
41*03831d35Sstevel #include <time.h>
42*03831d35Sstevel 
43*03831d35Sstevel 
44*03831d35Sstevel /* DEFINES */
45*03831d35Sstevel #define	XSEM_ERROR	-1
46*03831d35Sstevel #define	XSEM_EBUSY	1
47*03831d35Sstevel #define	XSEM_ETIME	2
48*03831d35Sstevel 
49*03831d35Sstevel 
50*03831d35Sstevel /* STRUCTURES */
51*03831d35Sstevel typedef struct
52*03831d35Sstevel {
53*03831d35Sstevel 	pthread_mutex_t	semMutex;
54*03831d35Sstevel 	pthread_cond_t	semCV;
55*03831d35Sstevel 	int		semaphore;
56*03831d35Sstevel } xsem_t;
57*03831d35Sstevel 
58*03831d35Sstevel 
59*03831d35Sstevel /* PROTOTYPES */
60*03831d35Sstevel int	xsem_init(xsem_t *sem, int pshared, unsigned int value);
61*03831d35Sstevel void	xsem_destroy(xsem_t *sem);
62*03831d35Sstevel int	xsem_wait(xsem_t *sem);
63*03831d35Sstevel int	xsem_trywait(xsem_t *sem);
64*03831d35Sstevel int	xsem_post(xsem_t *sem);
65*03831d35Sstevel void	xsem_getvalue(xsem_t *sem, int *sval);
66*03831d35Sstevel 
67*03831d35Sstevel int	xsem_xwait(xsem_t *sem, int timeout, timestruc_t *time);
68*03831d35Sstevel 
69*03831d35Sstevel #ifdef	__cplusplus
70*03831d35Sstevel }
71*03831d35Sstevel #endif
72*03831d35Sstevel 
73*03831d35Sstevel #endif /* __XSEM_H__ */
74