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