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 5*6138Ssvemuri * Common Development and Distribution License (the "License"). 6*6138Ssvemuri * 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 /* 22*6138Ssvemuri * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23*6138Ssvemuri * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_RWLOCK_H 270Sstevel@tonic-gate #define _SYS_RWLOCK_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate /* 320Sstevel@tonic-gate * Public interface to readers/writer locks. See rwlock(9F) for details. 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate #ifdef __cplusplus 380Sstevel@tonic-gate extern "C" { 390Sstevel@tonic-gate #endif 400Sstevel@tonic-gate 410Sstevel@tonic-gate #ifndef _ASM 420Sstevel@tonic-gate 430Sstevel@tonic-gate typedef enum { 440Sstevel@tonic-gate RW_DRIVER = 2, /* driver (DDI) rwlock */ 450Sstevel@tonic-gate RW_DEFAULT = 4 /* kernel default rwlock */ 460Sstevel@tonic-gate } krw_type_t; 470Sstevel@tonic-gate 480Sstevel@tonic-gate typedef enum { 490Sstevel@tonic-gate RW_WRITER, 500Sstevel@tonic-gate RW_READER 510Sstevel@tonic-gate } krw_t; 520Sstevel@tonic-gate 530Sstevel@tonic-gate typedef struct _krwlock { 540Sstevel@tonic-gate void *_opaque[1]; 550Sstevel@tonic-gate } krwlock_t; 560Sstevel@tonic-gate 570Sstevel@tonic-gate #if defined(_KERNEL) 580Sstevel@tonic-gate 590Sstevel@tonic-gate #define RW_READ_HELD(x) (rw_read_held((x))) 600Sstevel@tonic-gate #define RW_WRITE_HELD(x) (rw_write_held((x))) 610Sstevel@tonic-gate #define RW_LOCK_HELD(x) (rw_lock_held((x))) 620Sstevel@tonic-gate #define RW_ISWRITER(x) (rw_iswriter(x)) 630Sstevel@tonic-gate 640Sstevel@tonic-gate extern void rw_init(krwlock_t *, char *, krw_type_t, void *); 650Sstevel@tonic-gate extern void rw_destroy(krwlock_t *); 660Sstevel@tonic-gate extern void rw_enter(krwlock_t *, krw_t); 670Sstevel@tonic-gate extern int rw_tryenter(krwlock_t *, krw_t); 680Sstevel@tonic-gate extern void rw_exit(krwlock_t *); 690Sstevel@tonic-gate extern void rw_downgrade(krwlock_t *); 700Sstevel@tonic-gate extern int rw_tryupgrade(krwlock_t *); 710Sstevel@tonic-gate extern int rw_read_held(krwlock_t *); 720Sstevel@tonic-gate extern int rw_write_held(krwlock_t *); 730Sstevel@tonic-gate extern int rw_lock_held(krwlock_t *); 740Sstevel@tonic-gate extern int rw_read_locked(krwlock_t *); 750Sstevel@tonic-gate extern int rw_iswriter(krwlock_t *); 760Sstevel@tonic-gate extern struct _kthread *rw_owner(krwlock_t *); 77*6138Ssvemuri extern uint_t (*rw_lock_backoff)(uint_t); 78*6138Ssvemuri extern void (*rw_lock_delay)(uint_t); 790Sstevel@tonic-gate 800Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 810Sstevel@tonic-gate 820Sstevel@tonic-gate #endif /* _ASM */ 830Sstevel@tonic-gate 840Sstevel@tonic-gate #ifdef __cplusplus 850Sstevel@tonic-gate } 860Sstevel@tonic-gate #endif 870Sstevel@tonic-gate 880Sstevel@tonic-gate #endif /* _SYS_RWLOCK_H */ 89