1 .\" Copyright (c) 2006 Gleb Smirnoff <glebius@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 .Nd kernel synchronization primitives
47 .Fn rw_init "struct rwlock *rwlock" "const char *name"
49 .Fn rw_rlock "struct rwlock *rwlock"
51 .Fn rw_wlock "struct rwlock *rwlock"
53 .Fn rw_runlock "struct rwlock *rwlock"
55 .Fn rw_wunlock "struct rwlock *rwlock"
57 .Fn rw_initialized "struct rwlock *rwlock"
59 .Fn rw_destroy "struct rwlock *rwlock"
61 .Cd "options INVARIANTS"
62 .Cd "options INVARIANT_SUPPORT"
64 .Fn rw_assert "struct rwlock *rwlock" "int what"
66 .Fn RW_SYSINIT "name" "struct rwlock *rwlock" "const char *description"
68 Read/write locks are a method of thread synchronization, which
69 allows several threads have shared access to protected data, or
70 one thread have exclusive access.
71 The threads that share access are known as
73 since they should only read the protected data, while thread
74 with exclusive access is known as a
76 since it can modify protected data.
78 Although the description of read/write locks looks very similar
81 locks, their usage pattern is different.
82 The read/write locks can be treated as mutexes (see
84 with shared/exclusive semantics.
89 can be locked while holding a non-spin mutex;
91 cannot be held while sleeping.
94 locks have priority propagation like mutexes, but priority
95 can be propagated only to exclusive holder.
96 This limitation comes from the fact that shared owners
98 Another important property is that shared holder of
101 .Ss Macros and Functions
102 .Bl -tag -width indent
103 .It Fn rw_init "struct rwlock *rwlock" "const char *name"
104 Initialize structure located at
106 as read/write lock, described by name
108 The description is used solely for debugging purposes.
109 This function must be used before any other manipulations
111 .It Fn rw_rlock "struct rwlock *rwlock"
115 If any thread holds this lock exclusively, the current thread blocks,
116 and its priority is propagated to exclusive holder.
119 function can be called when the thread has already acquired reader
123 .Dq "recursing on a lock" .
124 .It Fn rw_wlock "struct rwlock *rwlock"
128 If there are any shared owners of the lock, the current thread blocks.
131 function cannot be called recursively.
132 .It Fn rw_runlock "struct rwlock *rwlock"
133 This function releases shared lock, previously acquired by
135 .It Fn rw_wunlock "struct rwlock *rwlock"
136 This function releases exclusive lock, previously acquired by
138 .It Fn rw_initialized "struct rwlock *rwlock"
139 This function returns non-zero if the
141 has been initialized, and zero otherwise.
142 .It Fn rw_destroy "struct rwlock *rwlock"
143 This functions destroys a lock previously initialized with
148 .It Fn rw_assert "struct rwlock *rwlock" "int what"
149 This function allows assertions specified in
153 If the assertions are not true and the kernel is compiled
155 .Cd "options INVARIANTS"
157 .Cd "options INVARIANT_SUPPORT" ,
158 the kernel will panic.
159 Currently the following assertions are supported:
160 .Bl -tag -width ".Dv RA_UNLOCKED"
162 Assert that current thread is either shared or exclusive owner
165 pointed to by the first argument.
167 Assert that current thread is shared owner of the
170 to by the first argument.
172 Assert that current thread is exclusive owner of the
175 to by the first argument.
177 Assert that current thread is neither shared nor exclusive owner
180 pointed to by the first argument.
191 functions appeared in
197 facility was written by
199 This manual page was written by
200 .An "Gleb Smirnoff" .