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 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * condvar.h: 287c478bd9Sstevel@tonic-gate * 297c478bd9Sstevel@tonic-gate * definitions for thread synchronization primitives: condition variables 307c478bd9Sstevel@tonic-gate * This is the public part of the interface to condition variables. The 317c478bd9Sstevel@tonic-gate * private (implementation-specific) part is in <arch>/sys/condvar_impl.h. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifndef _SYS_CONDVAR_H 357c478bd9Sstevel@tonic-gate #define _SYS_CONDVAR_H 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifndef _ASM 387c478bd9Sstevel@tonic-gate #include <sys/types.h> 397c478bd9Sstevel@tonic-gate #include <sys/time.h> 407c478bd9Sstevel@tonic-gate #ifdef _KERNEL 417c478bd9Sstevel@tonic-gate #include <sys/mutex.h> 427c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 437c478bd9Sstevel@tonic-gate #endif /* _ASM */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #ifdef __cplusplus 467c478bd9Sstevel@tonic-gate extern "C" { 477c478bd9Sstevel@tonic-gate #endif 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate #ifndef _ASM 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate /* 527c478bd9Sstevel@tonic-gate * Condtion variables. 537c478bd9Sstevel@tonic-gate */ 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate typedef struct _kcondvar { 567c478bd9Sstevel@tonic-gate ushort_t _opaque; 577c478bd9Sstevel@tonic-gate } kcondvar_t; 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate typedef enum { 607c478bd9Sstevel@tonic-gate CV_DEFAULT, 617c478bd9Sstevel@tonic-gate CV_DRIVER 627c478bd9Sstevel@tonic-gate } kcv_type_t; 637c478bd9Sstevel@tonic-gate 64*9ed8ca5fSRafael Vanoni #if defined(_KERNEL) 65*9ed8ca5fSRafael Vanoni 66d3d50737SRafael Vanoni /* 67d3d50737SRafael Vanoni * Time resolution values used in cv_reltimedwait() and cv_reltimedwait_sig() 68d3d50737SRafael Vanoni * to specify how accurately a relative timeout must expire - if it can be 69d3d50737SRafael Vanoni * anticipated or deferred. 70d3d50737SRafael Vanoni */ 71*9ed8ca5fSRafael Vanoni typedef enum { 72d3d50737SRafael Vanoni TR_NANOSEC, 73d3d50737SRafael Vanoni TR_MICROSEC, 74d3d50737SRafael Vanoni TR_MILLISEC, 75d3d50737SRafael Vanoni TR_SEC, 76d3d50737SRafael Vanoni TR_CLOCK_TICK, 77d3d50737SRafael Vanoni TR_COUNT 78*9ed8ca5fSRafael Vanoni } time_res_t; 79d3d50737SRafael Vanoni 80d3d50737SRafael Vanoni extern time_res_t time_res[]; 81d3d50737SRafael Vanoni 82d3d50737SRafael Vanoni #define TIME_RES_VALID(tr) (tr >= TR_NANOSEC && tr < TR_COUNT) 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * condition variable function prototypes 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate extern void cv_init(kcondvar_t *, char *, kcv_type_t, void *); 897c478bd9Sstevel@tonic-gate extern void cv_destroy(kcondvar_t *); 907c478bd9Sstevel@tonic-gate extern void cv_wait(kcondvar_t *, kmutex_t *); 917c478bd9Sstevel@tonic-gate extern void cv_wait_stop(kcondvar_t *, kmutex_t *, int); 927c478bd9Sstevel@tonic-gate extern clock_t cv_timedwait(kcondvar_t *, kmutex_t *, clock_t); 93d3d50737SRafael Vanoni extern clock_t cv_reltimedwait(kcondvar_t *, kmutex_t *, clock_t, time_res_t); 947c478bd9Sstevel@tonic-gate extern int cv_wait_sig(kcondvar_t *, kmutex_t *); 957c478bd9Sstevel@tonic-gate extern clock_t cv_timedwait_sig(kcondvar_t *, kmutex_t *, clock_t); 96d3d50737SRafael Vanoni extern clock_t cv_reltimedwait_sig(kcondvar_t *, kmutex_t *, clock_t, 97d3d50737SRafael Vanoni time_res_t); 987c478bd9Sstevel@tonic-gate extern int cv_wait_sig_swap(kcondvar_t *, kmutex_t *); 997c478bd9Sstevel@tonic-gate extern int cv_wait_sig_swap_core(kcondvar_t *, kmutex_t *, int *); 1007c478bd9Sstevel@tonic-gate extern void cv_signal(kcondvar_t *); 1017c478bd9Sstevel@tonic-gate extern void cv_broadcast(kcondvar_t *); 1023348528fSdm extern int cv_waituntil_sig(kcondvar_t *, kmutex_t *, timestruc_t *, int); 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #endif /* _ASM */ 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate #endif 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate #endif /* _SYS_CONDVAR_H */ 113