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