xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/zrlock.h (revision 12684:397e44ebb8a9)
1*12684STom.Erickson@Sun.COM /*
2*12684STom.Erickson@Sun.COM  * CDDL HEADER START
3*12684STom.Erickson@Sun.COM  *
4*12684STom.Erickson@Sun.COM  * The contents of this file are subject to the terms of the
5*12684STom.Erickson@Sun.COM  * Common Development and Distribution License (the "License").
6*12684STom.Erickson@Sun.COM  * You may not use this file except in compliance with the License.
7*12684STom.Erickson@Sun.COM  *
8*12684STom.Erickson@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*12684STom.Erickson@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*12684STom.Erickson@Sun.COM  * See the License for the specific language governing permissions
11*12684STom.Erickson@Sun.COM  * and limitations under the License.
12*12684STom.Erickson@Sun.COM  *
13*12684STom.Erickson@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*12684STom.Erickson@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*12684STom.Erickson@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*12684STom.Erickson@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*12684STom.Erickson@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*12684STom.Erickson@Sun.COM  *
19*12684STom.Erickson@Sun.COM  * CDDL HEADER END
20*12684STom.Erickson@Sun.COM  */
21*12684STom.Erickson@Sun.COM /*
22*12684STom.Erickson@Sun.COM  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23*12684STom.Erickson@Sun.COM  */
24*12684STom.Erickson@Sun.COM 
25*12684STom.Erickson@Sun.COM #ifndef	_SYS_ZRLOCK_H
26*12684STom.Erickson@Sun.COM #define	_SYS_ZRLOCK_H
27*12684STom.Erickson@Sun.COM 
28*12684STom.Erickson@Sun.COM #include <sys/zfs_context.h>
29*12684STom.Erickson@Sun.COM 
30*12684STom.Erickson@Sun.COM #ifdef	__cplusplus
31*12684STom.Erickson@Sun.COM extern "C" {
32*12684STom.Erickson@Sun.COM #endif
33*12684STom.Erickson@Sun.COM 
34*12684STom.Erickson@Sun.COM typedef struct zrlock {
35*12684STom.Erickson@Sun.COM 	kmutex_t zr_mtx;
36*12684STom.Erickson@Sun.COM 	volatile int32_t zr_refcount;
37*12684STom.Erickson@Sun.COM 	kcondvar_t zr_cv;
38*12684STom.Erickson@Sun.COM 	uint16_t zr_pad;
39*12684STom.Erickson@Sun.COM #ifdef	ZFS_DEBUG
40*12684STom.Erickson@Sun.COM 	kthread_t *zr_owner;
41*12684STom.Erickson@Sun.COM 	const char *zr_caller;
42*12684STom.Erickson@Sun.COM #endif
43*12684STom.Erickson@Sun.COM } zrlock_t;
44*12684STom.Erickson@Sun.COM 
45*12684STom.Erickson@Sun.COM extern void zrl_init(zrlock_t *);
46*12684STom.Erickson@Sun.COM extern void zrl_destroy(zrlock_t *);
47*12684STom.Erickson@Sun.COM #ifdef	ZFS_DEBUG
48*12684STom.Erickson@Sun.COM #define	zrl_add(_z)	zrl_add_debug((_z), __func__)
49*12684STom.Erickson@Sun.COM extern void zrl_add_debug(zrlock_t *, const char *);
50*12684STom.Erickson@Sun.COM #else
51*12684STom.Erickson@Sun.COM extern void zrl_add(zrlock_t *);
52*12684STom.Erickson@Sun.COM #endif
53*12684STom.Erickson@Sun.COM extern void zrl_remove(zrlock_t *);
54*12684STom.Erickson@Sun.COM extern int zrl_tryenter(zrlock_t *);
55*12684STom.Erickson@Sun.COM extern void zrl_exit(zrlock_t *);
56*12684STom.Erickson@Sun.COM extern int zrl_is_zero(zrlock_t *);
57*12684STom.Erickson@Sun.COM extern int zrl_is_locked(zrlock_t *);
58*12684STom.Erickson@Sun.COM #ifdef	ZFS_DEBUG
59*12684STom.Erickson@Sun.COM extern kthread_t *zrl_owner(zrlock_t *);
60*12684STom.Erickson@Sun.COM #endif
61*12684STom.Erickson@Sun.COM 
62*12684STom.Erickson@Sun.COM #ifdef	__cplusplus
63*12684STom.Erickson@Sun.COM }
64*12684STom.Erickson@Sun.COM #endif
65*12684STom.Erickson@Sun.COM 
66*12684STom.Erickson@Sun.COM #endif /* _SYS_ZRLOCK_H */
67