1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_RWLOCK_IMPL_H 28 #define _SYS_RWLOCK_IMPL_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * Implementation-private definitions for readers/writer locks. 34 */ 35 36 #ifndef _ASM 37 38 #include <sys/rwlock.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 typedef struct rwlock_impl { 45 uintptr_t rw_wwwh; /* waiters, write wanted, hold count */ 46 } rwlock_impl_t; 47 48 #endif /* _ASM */ 49 50 #define RW_HAS_WAITERS 1 51 #define RW_WRITE_WANTED 2 52 #define RW_WRITE_LOCKED 4 53 #define RW_READ_LOCK 8 54 #define RW_WRITE_LOCK(thread) ((uintptr_t)(thread) | RW_WRITE_LOCKED) 55 #define RW_HOLD_COUNT (-RW_READ_LOCK) 56 #define RW_HOLD_COUNT_SHIFT 3 /* log2(RW_READ_LOCK) */ 57 #define RW_READ_COUNT RW_HOLD_COUNT 58 #define RW_OWNER RW_HOLD_COUNT 59 #define RW_LOCKED RW_HOLD_COUNT 60 #define RW_WRITE_CLAIMED (RW_WRITE_LOCKED | RW_WRITE_WANTED) 61 #define RW_DOUBLE_LOCK (RW_WRITE_LOCK(0) | RW_READ_LOCK) 62 63 /* 64 * These macros are used by both the implementation of rw_*() routines and 65 * by the implementation of the rwlock-related DTrace subroutines. (DTrace 66 * cannot make calls into the rw_*() routines; it must use the macros.) 67 */ 68 #define _RW_READ_HELD(rwlp, tmp) \ 69 ((((tmp) = ((rwlock_impl_t *)(rwlp))->rw_wwwh) & RW_LOCKED) && \ 70 !((tmp) & RW_WRITE_LOCKED)) 71 72 #define _RW_WRITE_HELD(rwlp) \ 73 ((((rwlock_impl_t *)(rwlp))->rw_wwwh & \ 74 (RW_OWNER | RW_WRITE_LOCKED)) == RW_WRITE_LOCK(curthread)) 75 76 #define _RW_LOCK_HELD(rwlp) \ 77 ((((rwlock_impl_t *)(rwlp))->rw_wwwh & RW_LOCKED) ? 1 : 0) 78 79 #define _RW_ISWRITER(rwlp) \ 80 ((((rwlock_impl_t *)(rwlp))->rw_wwwh & RW_WRITE_CLAIMED) ? 1 : 0) 81 82 #ifdef __cplusplus 83 } 84 #endif 85 86 #endif /* _SYS_RWLOCK_IMPL_H */ 87