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