10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 53914Spm145316 * Common Development and Distribution License (the "License"). 63914Spm145316 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 225834Spt157919 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 233914Spm145316 * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_MUTEX_H 270Sstevel@tonic-gate #define _SYS_MUTEX_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifndef _ASM 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifndef _ASM 400Sstevel@tonic-gate 410Sstevel@tonic-gate /* 420Sstevel@tonic-gate * Public interface to mutual exclusion locks. See mutex(9F) for details. 430Sstevel@tonic-gate * 440Sstevel@tonic-gate * The basic mutex type is MUTEX_ADAPTIVE, which is expected to be used 450Sstevel@tonic-gate * in almost all of the kernel. MUTEX_SPIN provides interrupt blocking 460Sstevel@tonic-gate * and must be used in interrupt handlers above LOCK_LEVEL. The iblock 470Sstevel@tonic-gate * cookie argument to mutex_init() encodes the interrupt level to block. 480Sstevel@tonic-gate * The iblock cookie must be NULL for adaptive locks. 490Sstevel@tonic-gate * 500Sstevel@tonic-gate * MUTEX_DEFAULT is the type usually specified (except in drivers) to 510Sstevel@tonic-gate * mutex_init(). It is identical to MUTEX_ADAPTIVE. 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * MUTEX_DRIVER is always used by drivers. mutex_init() converts this to 540Sstevel@tonic-gate * either MUTEX_ADAPTIVE or MUTEX_SPIN depending on the iblock cookie. 550Sstevel@tonic-gate * 560Sstevel@tonic-gate * Mutex statistics can be gathered on the fly, without rebooting or 570Sstevel@tonic-gate * recompiling the kernel, via the lockstat driver (lockstat(7D)). 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate typedef enum { 600Sstevel@tonic-gate MUTEX_ADAPTIVE = 0, /* spin if owner is running, otherwise block */ 610Sstevel@tonic-gate MUTEX_SPIN = 1, /* block interrupts and spin */ 620Sstevel@tonic-gate MUTEX_DRIVER = 4, /* driver (DDI) mutex */ 630Sstevel@tonic-gate MUTEX_DEFAULT = 6 /* kernel default mutex */ 640Sstevel@tonic-gate } kmutex_type_t; 650Sstevel@tonic-gate 660Sstevel@tonic-gate typedef struct mutex { 670Sstevel@tonic-gate #ifdef _LP64 680Sstevel@tonic-gate void *_opaque[1]; 690Sstevel@tonic-gate #else 700Sstevel@tonic-gate void *_opaque[2]; 710Sstevel@tonic-gate #endif 720Sstevel@tonic-gate } kmutex_t; 730Sstevel@tonic-gate 740Sstevel@tonic-gate #ifdef _KERNEL 750Sstevel@tonic-gate 760Sstevel@tonic-gate #define MUTEX_HELD(x) (mutex_owned(x)) 770Sstevel@tonic-gate #define MUTEX_NOT_HELD(x) (!mutex_owned(x) || panicstr) 780Sstevel@tonic-gate 790Sstevel@tonic-gate extern void mutex_init(kmutex_t *, char *, kmutex_type_t, void *); 800Sstevel@tonic-gate extern void mutex_destroy(kmutex_t *); 810Sstevel@tonic-gate extern void mutex_enter(kmutex_t *); 820Sstevel@tonic-gate extern int mutex_tryenter(kmutex_t *); 830Sstevel@tonic-gate extern void mutex_exit(kmutex_t *); 840Sstevel@tonic-gate extern int mutex_owned(kmutex_t *); 850Sstevel@tonic-gate extern struct _kthread *mutex_owner(kmutex_t *); 865834Spt157919 875834Spt157919 extern ushort_t mutex_backoff_base; 885834Spt157919 extern uint_t mutex_backoff_cap; 895834Spt157919 extern ushort_t mutex_cap_factor; 905834Spt157919 extern uchar_t mutex_backoff_shift; 915834Spt157919 extern void (*mutex_lock_delay)(uint_t); 925834Spt157919 extern uint_t (*mutex_lock_backoff)(uint_t); 935834Spt157919 extern void (*mutex_delay)(void); 945834Spt157919 extern void mutex_delay_default(void); 955834Spt157919 extern void mutex_sync(void); 960Sstevel@tonic-gate 97*6138Ssvemuri extern void default_lock_delay(uint_t); 98*6138Ssvemuri extern uint_t default_lock_backoff(uint_t); 99*6138Ssvemuri 1000Sstevel@tonic-gate #endif /* _KERNEL */ 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate #endif /* _ASM */ 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate #ifdef __cplusplus 1050Sstevel@tonic-gate } 1060Sstevel@tonic-gate #endif 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate #endif /* _SYS_MUTEX_H */ 109