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