1219089Spjd/*
2219089Spjd * CDDL HEADER START
3219089Spjd *
4219089Spjd * The contents of this file are subject to the terms of the
5219089Spjd * Common Development and Distribution License (the "License").
6219089Spjd * You may not use this file except in compliance with the License.
7219089Spjd *
8219089Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9219089Spjd * or http://www.opensolaris.org/os/licensing.
10219089Spjd * See the License for the specific language governing permissions
11219089Spjd * and limitations under the License.
12219089Spjd *
13219089Spjd * When distributing Covered Code, include this CDDL HEADER in each
14219089Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15219089Spjd * If applicable, add the following below this CDDL HEADER, with the
16219089Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17219089Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18219089Spjd *
19219089Spjd * CDDL HEADER END
20219089Spjd */
21219089Spjd/*
22219089Spjd * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23290765Smav * Copyright (c) 2015 by Delphix. All rights reserved.
24219089Spjd */
25219089Spjd
26219089Spjd#ifndef	_SYS_ZRLOCK_H
27219089Spjd#define	_SYS_ZRLOCK_H
28219089Spjd
29219089Spjd#include <sys/zfs_context.h>
30219089Spjd
31219089Spjd#ifdef	__cplusplus
32219089Spjdextern "C" {
33219089Spjd#endif
34219089Spjd
35219089Spjdtypedef struct zrlock {
36219089Spjd	kmutex_t zr_mtx;
37219089Spjd	volatile int32_t zr_refcount;
38219089Spjd	kcondvar_t zr_cv;
39219089Spjd	uint16_t zr_pad;
40219089Spjd#ifdef	ZFS_DEBUG
41219089Spjd	kthread_t *zr_owner;
42219089Spjd	const char *zr_caller;
43219089Spjd#endif
44219089Spjd} zrlock_t;
45219089Spjd
46219089Spjdextern void zrl_init(zrlock_t *);
47219089Spjdextern void zrl_destroy(zrlock_t *);
48290765Smav#define	zrl_add(_z)	zrl_add_impl((_z), __func__)
49290765Smavextern void zrl_add_impl(zrlock_t *, const char *);
50219089Spjdextern void zrl_remove(zrlock_t *);
51219089Spjdextern int zrl_tryenter(zrlock_t *);
52219089Spjdextern void zrl_exit(zrlock_t *);
53219089Spjdextern int zrl_is_zero(zrlock_t *);
54219089Spjdextern int zrl_is_locked(zrlock_t *);
55219089Spjd#ifdef	ZFS_DEBUG
56219089Spjdextern kthread_t *zrl_owner(zrlock_t *);
57219089Spjd#endif
58219089Spjd
59219089Spjd#ifdef	__cplusplus
60219089Spjd}
61219089Spjd#endif
62219089Spjd
63219089Spjd#endif /* _SYS_ZRLOCK_H */
64