xref: /titanic_50/usr/src/uts/common/sys/condvar.h (revision 9584cebb1c69707f4c67306b661c2ed47d8676f1)
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  * Copyright (c) 2012 by Delphix. All rights reserved.
28  */
29 
30 /*
31  * condvar.h:
32  *
33  * definitions for thread synchronization primitives: condition variables
34  * This is the public part of the interface to condition variables. The
35  * private (implementation-specific) part is in <arch>/sys/condvar_impl.h.
36  */
37 
38 #ifndef _SYS_CONDVAR_H
39 #define	_SYS_CONDVAR_H
40 
41 #ifndef	_ASM
42 #include <sys/types.h>
43 #include <sys/time.h>
44 #ifdef _KERNEL
45 #include <sys/mutex.h>
46 #endif	/* _KERNEL */
47 #endif	/* _ASM */
48 
49 #ifdef	__cplusplus
50 extern "C" {
51 #endif
52 
53 #ifndef	_ASM
54 
55 /*
56  * Condtion variables.
57  */
58 
59 typedef struct _kcondvar {
60 	ushort_t	_opaque;
61 } kcondvar_t;
62 
63 typedef	enum {
64 	CV_DEFAULT,
65 	CV_DRIVER
66 } kcv_type_t;
67 
68 #if defined(_KERNEL)
69 
70 /*
71  * Time resolution values used in cv_reltimedwait() and cv_reltimedwait_sig()
72  * to specify how accurately a relative timeout must expire - if it can be
73  * anticipated or deferred.
74  */
75 typedef enum {
76 	TR_NANOSEC,
77 	TR_MICROSEC,
78 	TR_MILLISEC,
79 	TR_SEC,
80 	TR_CLOCK_TICK,
81 	TR_COUNT
82 } time_res_t;
83 
84 extern time_res_t time_res[];
85 
86 #define	TIME_RES_VALID(tr)	(tr >= TR_NANOSEC && tr < TR_COUNT)
87 
88 /*
89  * condition variable function prototypes
90  */
91 
92 extern	void	cv_init(kcondvar_t *, char *, kcv_type_t, void *);
93 extern  void	cv_destroy(kcondvar_t *);
94 extern	void	cv_wait(kcondvar_t *, kmutex_t *);
95 extern	void	cv_wait_stop(kcondvar_t *, kmutex_t *, int);
96 extern	clock_t	cv_timedwait(kcondvar_t *, kmutex_t *, clock_t);
97 extern	clock_t	cv_timedwait_hires(kcondvar_t *, kmutex_t *, hrtime_t, hrtime_t,
98     int);
99 extern	clock_t	cv_reltimedwait(kcondvar_t *, kmutex_t *, clock_t, time_res_t);
100 extern	int	cv_wait_sig(kcondvar_t *, kmutex_t *);
101 extern	clock_t	cv_timedwait_sig(kcondvar_t *, kmutex_t *, clock_t);
102 extern	int	cv_timedwait_sig_hrtime(kcondvar_t *, kmutex_t *, hrtime_t);
103 extern	clock_t	cv_reltimedwait_sig(kcondvar_t *, kmutex_t *, clock_t,
104     time_res_t);
105 extern	int	cv_wait_sig_swap(kcondvar_t *, kmutex_t *);
106 extern	int	cv_wait_sig_swap_core(kcondvar_t *, kmutex_t *, int *);
107 extern	void	cv_signal(kcondvar_t *);
108 extern	void	cv_broadcast(kcondvar_t *);
109 extern	int	cv_waituntil_sig(kcondvar_t *, kmutex_t *, timestruc_t *, int);
110 
111 #endif	/* defined(_KERNEL) */
112 
113 #endif	/* _ASM */
114 
115 #ifdef	__cplusplus
116 }
117 #endif
118 
119 #endif	/* _SYS_CONDVAR_H */
120