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