xref: /titanic_52/usr/src/uts/common/sys/condvar.h (revision cd1c8b85eb30b568e9816221430c479ace7a559d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5d3d50737SRafael Vanoni  * Common Development and Distribution License (the "License").
6d3d50737SRafael Vanoni  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22d3d50737SRafael Vanoni  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
26*cd1c8b85SMatthew Ahrens /*
27*cd1c8b85SMatthew Ahrens  * Copyright (c) 2012 by Delphix. All rights reserved.
28*cd1c8b85SMatthew Ahrens  */
29fe234e7cSMatt Amdur 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * condvar.h:
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * definitions for thread synchronization primitives: condition variables
347c478bd9Sstevel@tonic-gate  * This is the public part of the interface to condition variables. The
357c478bd9Sstevel@tonic-gate  * private (implementation-specific) part is in <arch>/sys/condvar_impl.h.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifndef _SYS_CONDVAR_H
397c478bd9Sstevel@tonic-gate #define	_SYS_CONDVAR_H
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifndef	_ASM
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate #include <sys/time.h>
447c478bd9Sstevel@tonic-gate #ifdef _KERNEL
457c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
467c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
477c478bd9Sstevel@tonic-gate #endif	/* _ASM */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
507c478bd9Sstevel@tonic-gate extern "C" {
517c478bd9Sstevel@tonic-gate #endif
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #ifndef	_ASM
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Condtion variables.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate typedef struct _kcondvar {
607c478bd9Sstevel@tonic-gate 	ushort_t	_opaque;
617c478bd9Sstevel@tonic-gate } kcondvar_t;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate typedef	enum {
647c478bd9Sstevel@tonic-gate 	CV_DEFAULT,
657c478bd9Sstevel@tonic-gate 	CV_DRIVER
667c478bd9Sstevel@tonic-gate } kcv_type_t;
677c478bd9Sstevel@tonic-gate 
689ed8ca5fSRafael Vanoni #if defined(_KERNEL)
699ed8ca5fSRafael Vanoni 
70d3d50737SRafael Vanoni /*
71d3d50737SRafael Vanoni  * Time resolution values used in cv_reltimedwait() and cv_reltimedwait_sig()
72d3d50737SRafael Vanoni  * to specify how accurately a relative timeout must expire - if it can be
73d3d50737SRafael Vanoni  * anticipated or deferred.
74d3d50737SRafael Vanoni  */
759ed8ca5fSRafael Vanoni typedef enum {
76d3d50737SRafael Vanoni 	TR_NANOSEC,
77d3d50737SRafael Vanoni 	TR_MICROSEC,
78d3d50737SRafael Vanoni 	TR_MILLISEC,
79d3d50737SRafael Vanoni 	TR_SEC,
80d3d50737SRafael Vanoni 	TR_CLOCK_TICK,
81d3d50737SRafael Vanoni 	TR_COUNT
829ed8ca5fSRafael Vanoni } time_res_t;
83d3d50737SRafael Vanoni 
84d3d50737SRafael Vanoni extern time_res_t time_res[];
85d3d50737SRafael Vanoni 
86d3d50737SRafael Vanoni #define	TIME_RES_VALID(tr)	(tr >= TR_NANOSEC && tr < TR_COUNT)
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * condition variable function prototypes
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate extern	void	cv_init(kcondvar_t *, char *, kcv_type_t, void *);
937c478bd9Sstevel@tonic-gate extern  void	cv_destroy(kcondvar_t *);
947c478bd9Sstevel@tonic-gate extern	void	cv_wait(kcondvar_t *, kmutex_t *);
957c478bd9Sstevel@tonic-gate extern	void	cv_wait_stop(kcondvar_t *, kmutex_t *, int);
967c478bd9Sstevel@tonic-gate extern	clock_t	cv_timedwait(kcondvar_t *, kmutex_t *, clock_t);
97d3d50737SRafael Vanoni extern	clock_t	cv_reltimedwait(kcondvar_t *, kmutex_t *, clock_t, time_res_t);
987c478bd9Sstevel@tonic-gate extern	int	cv_wait_sig(kcondvar_t *, kmutex_t *);
997c478bd9Sstevel@tonic-gate extern	clock_t	cv_timedwait_sig(kcondvar_t *, kmutex_t *, clock_t);
100*cd1c8b85SMatthew Ahrens extern	int	cv_timedwait_sig_hrtime(kcondvar_t *, kmutex_t *, hrtime_t);
101d3d50737SRafael Vanoni extern	clock_t	cv_reltimedwait_sig(kcondvar_t *, kmutex_t *, clock_t,
102d3d50737SRafael Vanoni     time_res_t);
1037c478bd9Sstevel@tonic-gate extern	int	cv_wait_sig_swap(kcondvar_t *, kmutex_t *);
1047c478bd9Sstevel@tonic-gate extern	int	cv_wait_sig_swap_core(kcondvar_t *, kmutex_t *, int *);
1057c478bd9Sstevel@tonic-gate extern	void	cv_signal(kcondvar_t *);
1067c478bd9Sstevel@tonic-gate extern	void	cv_broadcast(kcondvar_t *);
1073348528fSdm120769 extern	int	cv_waituntil_sig(kcondvar_t *, kmutex_t *, timestruc_t *, int);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #endif	/* _ASM */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate #endif
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #endif	/* _SYS_CONDVAR_H */
118