744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson/*
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * CDDL HEADER START
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson *
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * The contents of this file are subject to the terms of the
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * Common Development and Distribution License (the "License").
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * You may not use this file except in compliance with the License.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson *
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * or http://www.opensolaris.org/os/licensing.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * See the License for the specific language governing permissions
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * and limitations under the License.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson *
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * When distributing Covered Code, include this CDDL HEADER in each
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * If applicable, add the following below this CDDL HEADER, with the
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * fields enclosed by brackets "[]" replaced with your own identifying
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * information: Portions Copyright [yyyy] [name of copyright owner]
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson *
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * CDDL HEADER END
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson */
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson/*
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
9a686fbc186e8e2a64e9a5094d44c7d6fa0ea167Paul Dagnelie * Copyright (c) 2015 by Delphix. All rights reserved.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson */
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#ifndef _SYS_ZRLOCK_H
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#define _SYS_ZRLOCK_H
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#include <sys/zfs_context.h>
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#ifdef __cplusplus
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonextern "C" {
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#endif
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksontypedef struct zrlock {
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson kmutex_t zr_mtx;
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson volatile int32_t zr_refcount;
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson kcondvar_t zr_cv;
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson uint16_t zr_pad;
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#ifdef ZFS_DEBUG
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson kthread_t *zr_owner;
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson const char *zr_caller;
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#endif
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson} zrlock_t;
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonextern void zrl_init(zrlock_t *);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonextern void zrl_destroy(zrlock_t *);
9a686fbc186e8e2a64e9a5094d44c7d6fa0ea167Paul Dagnelie#define zrl_add(_z) zrl_add_impl((_z), __func__)
9a686fbc186e8e2a64e9a5094d44c7d6fa0ea167Paul Dagnelieextern void zrl_add_impl(zrlock_t *, const char *);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonextern void zrl_remove(zrlock_t *);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonextern int zrl_tryenter(zrlock_t *);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonextern void zrl_exit(zrlock_t *);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonextern int zrl_is_zero(zrlock_t *);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonextern int zrl_is_locked(zrlock_t *);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#ifdef ZFS_DEBUG
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Ericksonextern kthread_t *zrl_owner(zrlock_t *);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#endif
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#ifdef __cplusplus
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson}
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#endif
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#endif /* _SYS_ZRLOCK_H */