xref: /titanic_50/usr/src/uts/common/sys/condvar.h (revision b494511a9cf72b1fc4eb13a0e593f55c624ab829)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * condvar.h:
28  *
29  * definitions for thread synchronization primitives: condition variables
30  * This is the public part of the interface to condition variables. The
31  * private (implementation-specific) part is in <arch>/sys/condvar_impl.h.
32  */
33 
34 #ifndef _SYS_CONDVAR_H
35 #define	_SYS_CONDVAR_H
36 
37 #ifndef	_ASM
38 #include <sys/types.h>
39 #include <sys/time.h>
40 #ifdef _KERNEL
41 #include <sys/mutex.h>
42 #endif	/* _KERNEL */
43 #endif	/* _ASM */
44 
45 #ifdef	__cplusplus
46 extern "C" {
47 #endif
48 
49 #ifndef	_ASM
50 
51 /*
52  * Condtion variables.
53  */
54 
55 typedef struct _kcondvar {
56 	ushort_t	_opaque;
57 } kcondvar_t;
58 
59 typedef	enum {
60 	CV_DEFAULT,
61 	CV_DRIVER
62 } kcv_type_t;
63 
64 #if defined(_KERNEL)
65 
66 /*
67  * Time resolution values used in cv_reltimedwait() and cv_reltimedwait_sig()
68  * to specify how accurately a relative timeout must expire - if it can be
69  * anticipated or deferred.
70  */
71 typedef enum {
72 	TR_NANOSEC,
73 	TR_MICROSEC,
74 	TR_MILLISEC,
75 	TR_SEC,
76 	TR_CLOCK_TICK,
77 	TR_COUNT
78 } time_res_t;
79 
80 extern time_res_t time_res[];
81 
82 #define	TIME_RES_VALID(tr)	(tr >= TR_NANOSEC && tr < TR_COUNT)
83 
84 /*
85  * condition variable function prototypes
86  */
87 
88 extern	void	cv_init(kcondvar_t *, char *, kcv_type_t, void *);
89 extern  void	cv_destroy(kcondvar_t *);
90 extern	void	cv_wait(kcondvar_t *, kmutex_t *);
91 extern	void	cv_wait_stop(kcondvar_t *, kmutex_t *, int);
92 extern	clock_t	cv_timedwait(kcondvar_t *, kmutex_t *, clock_t);
93 extern	clock_t	cv_reltimedwait(kcondvar_t *, kmutex_t *, clock_t, time_res_t);
94 extern	int	cv_wait_sig(kcondvar_t *, kmutex_t *);
95 extern	clock_t	cv_timedwait_sig(kcondvar_t *, kmutex_t *, clock_t);
96 extern	clock_t	cv_reltimedwait_sig(kcondvar_t *, kmutex_t *, clock_t,
97     time_res_t);
98 extern	int	cv_wait_sig_swap(kcondvar_t *, kmutex_t *);
99 extern	int	cv_wait_sig_swap_core(kcondvar_t *, kmutex_t *, int *);
100 extern	void	cv_signal(kcondvar_t *);
101 extern	void	cv_broadcast(kcondvar_t *);
102 extern	int	cv_waituntil_sig(kcondvar_t *, kmutex_t *, timestruc_t *, int);
103 
104 #endif	/* defined(_KERNEL) */
105 
106 #endif	/* _ASM */
107 
108 #ifdef	__cplusplus
109 }
110 #endif
111 
112 #endif	/* _SYS_CONDVAR_H */
113