2 * Copyright (c) 2007 Stephan Uphoff <ups@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #ifndef _SYS_RMLOCK_H_
33 #define _SYS_RMLOCK_H_
35 #include <sys/mutex.h>
36 #include <sys/_lock.h>
37 #include <sys/_rmlock.h>
42 * Flags passed to rm_init(9).
44 #define RM_NOWITNESS 0x00000001
45 #define RM_RECURSE 0x00000002
47 void rm_init(struct rmlock *rm, const char *name);
48 void rm_init_flags(struct rmlock *rm, const char *name, int opts);
49 void rm_destroy(struct rmlock *rm);
50 int rm_wowned(struct rmlock *rm);
51 void rm_sysinit(void *arg);
52 void rm_sysinit_flags(void *arg);
54 void _rm_wlock_debug(struct rmlock *rm, const char *file, int line);
55 void _rm_wunlock_debug(struct rmlock *rm, const char *file, int line);
56 void _rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
57 const char *file, int line);
58 void _rm_runlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
59 const char *file, int line);
61 void _rm_wlock(struct rmlock *rm);
62 void _rm_wunlock(struct rmlock *rm);
63 void _rm_rlock(struct rmlock *rm, struct rm_priotracker *tracker);
64 void _rm_runlock(struct rmlock *rm, struct rm_priotracker *tracker);
67 * Public interface for lock operations.
70 #error LOCK_DEBUG not defined, include <sys/lock.h> before <sys/rmlock.h>
74 #define rm_wlock(rm) _rm_wlock_debug((rm), LOCK_FILE, LOCK_LINE)
75 #define rm_wunlock(rm) _rm_wunlock_debug((rm), LOCK_FILE, LOCK_LINE)
76 #define rm_rlock(rm,tracker) \
77 _rm_rlock_debug((rm),(tracker), LOCK_FILE, LOCK_LINE )
78 #define rm_runlock(rm,tracker) \
79 _rm_runlock_debug((rm), (tracker), LOCK_FILE, LOCK_LINE )
81 #define rm_wlock(rm) _rm_wlock((rm))
82 #define rm_wunlock(rm) _rm_wunlock((rm))
83 #define rm_rlock(rm,tracker) _rm_rlock((rm),(tracker))
84 #define rm_runlock(rm,tracker) _rm_runlock((rm), (tracker))
92 struct rm_args_flags {
98 #define RM_SYSINIT(name, rm, desc) \
99 static struct rm_args name##_args = { \
103 SYSINIT(name##_rm_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \
104 rm_sysinit, &name##_args); \
105 SYSUNINIT(name##_rm_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \
109 #define RM_SYSINIT_FLAGS(name, rm, desc, opts) \
110 static struct rm_args name##_args = { \
115 SYSINIT(name##_rm_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \
116 rm_sysinit_flags, &name##_args); \
117 SYSUNINIT(name##_rm_sysuninit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \
121 #endif /* !_SYS_RMLOCK_H_ */