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