sys/fs/zfs.h: replace grub in comments.
[unleashed.git] / include / sys / rwlock_impl.h
blob5716ae9e7f3f50c45be66bfc90b02ee7b6d91411
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _SYS_RWLOCK_IMPL_H
28 #define _SYS_RWLOCK_IMPL_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * Implementation-private definitions for readers/writer locks.
36 #ifndef _ASM
38 #include <sys/rwlock.h>
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 typedef struct rwlock_impl {
45 uintptr_t rw_wwwh; /* waiters, write wanted, hold count */
46 } rwlock_impl_t;
48 #endif /* _ASM */
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)
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.)
68 #define _RW_READ_HELD(rwlp, tmp) \
69 ((((tmp) = ((rwlock_impl_t *)(rwlp))->rw_wwwh) & RW_LOCKED) && \
70 !((tmp) & RW_WRITE_LOCKED))
72 #define _RW_WRITE_HELD(rwlp) \
73 ((((rwlock_impl_t *)(rwlp))->rw_wwwh & \
74 (RW_OWNER | RW_WRITE_LOCKED)) == RW_WRITE_LOCK(curthread))
76 #define _RW_LOCK_HELD(rwlp) \
77 ((((rwlock_impl_t *)(rwlp))->rw_wwwh & RW_LOCKED) ? 1 : 0)
79 #define _RW_ISWRITER(rwlp) \
80 ((((rwlock_impl_t *)(rwlp))->rw_wwwh & RW_WRITE_CLAIMED) ? 1 : 0)
82 #ifdef __cplusplus
84 #endif
86 #endif /* _SYS_RWLOCK_IMPL_H */