1b819ceaGordon Ross/*
2b819ceaGordon Ross * CDDL HEADER START
3b819ceaGordon Ross *
4b819ceaGordon Ross * The contents of this file are subject to the terms of the
5b819ceaGordon Ross * Common Development and Distribution License (the "License").
6b819ceaGordon Ross * You may not use this file except in compliance with the License.
7b819ceaGordon Ross *
8b819ceaGordon Ross * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9b819ceaGordon Ross * or http://www.opensolaris.org/os/licensing.
10b819ceaGordon Ross * See the License for the specific language governing permissions
11b819ceaGordon Ross * and limitations under the License.
12b819ceaGordon Ross *
13b819ceaGordon Ross * When distributing Covered Code, include this CDDL HEADER in each
14b819ceaGordon Ross * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15b819ceaGordon Ross * If applicable, add the following below this CDDL HEADER, with the
16b819ceaGordon Ross * fields enclosed by brackets "[]" replaced with your own identifying
17b819ceaGordon Ross * information: Portions Copyright [yyyy] [name of copyright owner]
18b819ceaGordon Ross *
19b819ceaGordon Ross * CDDL HEADER END
20b819ceaGordon Ross */
21b819ceaGordon Ross/*
22b819ceaGordon Ross * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23b819ceaGordon Ross * Use is subject to license terms.
24b819ceaGordon Ross *
25b819ceaGordon Ross * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
26b819ceaGordon Ross */
27b819ceaGordon Ross
28b819ceaGordon Ross#ifndef _SYS_RWLOCK_H
29b819ceaGordon Ross#define	_SYS_RWLOCK_H
30b819ceaGordon Ross
31b819ceaGordon Ross/*
32b819ceaGordon Ross * Public interface to readers/writer locks.  See rwlock(9F) for details.
33b819ceaGordon Ross */
34b819ceaGordon Ross
35b819ceaGordon Ross#include <sys/synch.h>	/* lwp_rwlock_t */
36b819ceaGordon Ross
37b819ceaGordon Ross#ifdef	__cplusplus
38b819ceaGordon Rossextern "C" {
39b819ceaGordon Ross#endif
40b819ceaGordon Ross
41b819ceaGordon Rosstypedef enum {
42b819ceaGordon Ross	RW_DRIVER = 2,		/* driver (DDI) rwlock */
43b819ceaGordon Ross	RW_DEFAULT = 4		/* kernel default rwlock */
44b819ceaGordon Ross} krw_type_t;
45b819ceaGordon Ross
46b819ceaGordon Rosstypedef enum {
47b819ceaGordon Ross	RW_WRITER,
48b819ceaGordon Ross	RW_READER
49b819ceaGordon Ross} krw_t;
50b819ceaGordon Ross
51b819ceaGordon Rossstruct _krwlock {
52b819ceaGordon Ross	lwp_rwlock_t rw_lock;
53b819ceaGordon Ross	void	*rw_owner;
54b819ceaGordon Ross};
55b819ceaGordon Rosstypedef struct _krwlock krwlock_t;
56b819ceaGordon Ross
57b819ceaGordon Ross#if defined(_KERNEL) || defined(_FAKE_KERNEL)
58b819ceaGordon Ross
59b819ceaGordon Ross#define	RW_READ_HELD(x)		(rw_read_held((x)))
60b819ceaGordon Ross#define	RW_WRITE_HELD(x)	(rw_write_held((x)))
61b819ceaGordon Ross#define	RW_LOCK_HELD(x)		(rw_lock_held((x)))
62b819ceaGordon Ross#define	RW_ISWRITER(x)		(rw_iswriter(x))
63b819ceaGordon Ross
64b819ceaGordon Rossextern	void	rw_init(krwlock_t *, char *, krw_type_t, void *);
65b819ceaGordon Rossextern	void	rw_destroy(krwlock_t *);
66b819ceaGordon Rossextern	void	rw_enter(krwlock_t *, krw_t);
67b819ceaGordon Rossextern	int	rw_tryenter(krwlock_t *, krw_t);
68b819ceaGordon Rossextern	void	rw_exit(krwlock_t *);
69b819ceaGordon Rossextern	void	rw_downgrade(krwlock_t *);
70b819ceaGordon Rossextern	int	rw_tryupgrade(krwlock_t *);
71b819ceaGordon Rossextern	int	rw_read_held(krwlock_t *);
72b819ceaGordon Rossextern	int	rw_write_held(krwlock_t *);
73b819ceaGordon Rossextern	int	rw_lock_held(krwlock_t *);
74b819ceaGordon Rossextern	int	rw_read_locked(krwlock_t *);
75b819ceaGordon Rossextern	int	rw_iswriter(krwlock_t *);
76b819ceaGordon Rossextern	void	*rw_owner(krwlock_t *);
77b819ceaGordon Ross
78b819ceaGordon Ross#endif	/* defined(_KERNEL) */
79b819ceaGordon Ross
80b819ceaGordon Ross#ifdef	__cplusplus
81b819ceaGordon Ross}
82b819ceaGordon Ross#endif
83b819ceaGordon Ross
84b819ceaGordon Ross#endif	/* _SYS_RWLOCK_H */