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*fe234e7cSMatt Amdur /* Copyright (c) 2011 by Delphix. All rights reserved. */ 27*fe234e7cSMatt Amdur 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * condvar.h: 307c478bd9Sstevel@tonic-gate * 317c478bd9Sstevel@tonic-gate * definitions for thread synchronization primitives: condition variables 327c478bd9Sstevel@tonic-gate * This is the public part of the interface to condition variables. The 337c478bd9Sstevel@tonic-gate * private (implementation-specific) part is in <arch>/sys/condvar_impl.h. 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifndef _SYS_CONDVAR_H 377c478bd9Sstevel@tonic-gate #define _SYS_CONDVAR_H 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifndef _ASM 407c478bd9Sstevel@tonic-gate #include <sys/types.h> 417c478bd9Sstevel@tonic-gate #include <sys/time.h> 427c478bd9Sstevel@tonic-gate #ifdef _KERNEL 437c478bd9Sstevel@tonic-gate #include <sys/mutex.h> 447c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 457c478bd9Sstevel@tonic-gate #endif /* _ASM */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #ifdef __cplusplus 487c478bd9Sstevel@tonic-gate extern "C" { 497c478bd9Sstevel@tonic-gate #endif 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #ifndef _ASM 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * Condtion variables. 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate typedef struct _kcondvar { 587c478bd9Sstevel@tonic-gate ushort_t _opaque; 597c478bd9Sstevel@tonic-gate } kcondvar_t; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate typedef enum { 627c478bd9Sstevel@tonic-gate CV_DEFAULT, 637c478bd9Sstevel@tonic-gate CV_DRIVER 647c478bd9Sstevel@tonic-gate } kcv_type_t; 657c478bd9Sstevel@tonic-gate 669ed8ca5fSRafael Vanoni #if defined(_KERNEL) 679ed8ca5fSRafael Vanoni 68d3d50737SRafael Vanoni /* 69d3d50737SRafael Vanoni * Time resolution values used in cv_reltimedwait() and cv_reltimedwait_sig() 70d3d50737SRafael Vanoni * to specify how accurately a relative timeout must expire - if it can be 71d3d50737SRafael Vanoni * anticipated or deferred. 72d3d50737SRafael Vanoni */ 739ed8ca5fSRafael Vanoni typedef enum { 74d3d50737SRafael Vanoni TR_NANOSEC, 75d3d50737SRafael Vanoni TR_MICROSEC, 76d3d50737SRafael Vanoni TR_MILLISEC, 77d3d50737SRafael Vanoni TR_SEC, 78d3d50737SRafael Vanoni TR_CLOCK_TICK, 79d3d50737SRafael Vanoni TR_COUNT 809ed8ca5fSRafael Vanoni } time_res_t; 81d3d50737SRafael Vanoni 82d3d50737SRafael Vanoni extern time_res_t time_res[]; 83d3d50737SRafael Vanoni 84d3d50737SRafael Vanoni #define TIME_RES_VALID(tr) (tr >= TR_NANOSEC && tr < TR_COUNT) 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * condition variable function prototypes 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate extern void cv_init(kcondvar_t *, char *, kcv_type_t, void *); 917c478bd9Sstevel@tonic-gate extern void cv_destroy(kcondvar_t *); 927c478bd9Sstevel@tonic-gate extern void cv_wait(kcondvar_t *, kmutex_t *); 937c478bd9Sstevel@tonic-gate extern void cv_wait_stop(kcondvar_t *, kmutex_t *, int); 947c478bd9Sstevel@tonic-gate extern clock_t cv_timedwait(kcondvar_t *, kmutex_t *, clock_t); 95d3d50737SRafael Vanoni extern clock_t cv_reltimedwait(kcondvar_t *, kmutex_t *, clock_t, time_res_t); 967c478bd9Sstevel@tonic-gate extern int cv_wait_sig(kcondvar_t *, kmutex_t *); 977c478bd9Sstevel@tonic-gate extern clock_t cv_timedwait_sig(kcondvar_t *, kmutex_t *, clock_t); 98d3d50737SRafael Vanoni extern clock_t cv_reltimedwait_sig(kcondvar_t *, kmutex_t *, clock_t, 99d3d50737SRafael Vanoni time_res_t); 100*fe234e7cSMatt Amdur extern clock_t cv_relwaituntil_sig(kcondvar_t *, kmutex_t *, clock_t *, 101*fe234e7cSMatt Amdur time_res_t); 1027c478bd9Sstevel@tonic-gate extern int cv_wait_sig_swap(kcondvar_t *, kmutex_t *); 1037c478bd9Sstevel@tonic-gate extern int cv_wait_sig_swap_core(kcondvar_t *, kmutex_t *, int *); 1047c478bd9Sstevel@tonic-gate extern void cv_signal(kcondvar_t *); 1057c478bd9Sstevel@tonic-gate extern void cv_broadcast(kcondvar_t *); 1063348528fSdm120769 extern int cv_waituntil_sig(kcondvar_t *, kmutex_t *, timestruc_t *, int); 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #endif /* _ASM */ 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate #endif 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate #endif /* _SYS_CONDVAR_H */ 117