2 .\" Copyright (C) 2002 Chad David <davidc@acns.ab.ca>. 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(s), this list of conditions and the following disclaimer as
9 .\" the first lines of this file unmodified other than the possible
10 .\" addition of one or more copyright notices.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice(s), this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
16 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 .\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
19 .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 .\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38 .Nm lockmgr_printinfo ,
39 .Nm lockmgr_recursed ,
42 .Nd "lockmgr family of functions"
48 .Fn lockinit "struct lock *lkp" "int prio" "const char *wmesg" "int timo" "int flags"
50 .Fn lockdestroy "struct lock *lkp"
52 .Fn lockmgr "struct lock *lkp" "u_int flags" "struct mtx *interlkp"
54 .Fn lockmgr_args "struct lock *lkp" "u_int flags" "struct mtx *interlkp" "const char *wmesg" "int prio" "int timo"
56 .Fn lockmgr_disown "struct lock *lkp"
58 .Fn lockmgr_printinfo "struct lock *lkp"
60 .Fn lockmgr_recursed "struct lock *lkp"
62 .Fn lockstatus "struct lock *lkp"
64 .Cd "options INVARIANTS"
65 .Cd "options INVARIANT_SUPPORT"
67 .Fn lockmgr_assert "struct lock *lkp" "int what"
71 function is used to initialize a lock.
72 It must be called before any operation can be performed on a lock.
74 .Bl -tag -width ".Fa wmesg"
76 A pointer to the lock to initialize.
78 The priority passed to
82 This is used for both debugging output and
85 The timeout value passed to
88 The flags the lock is to be initialized with:
89 .Bl -tag -width ".Dv LK_CANRECURSE"
91 Allow recursive exclusive locks.
93 Disable lock profiling for this lock.
95 Allow exclusive locks only.
102 should log messages about duplicate locks being acquired.
106 logging for this lock.
110 during a sleep; otherwise, 0 is used.
116 function is used to destroy a lock, and while it is called in a number of
117 places in the kernel, it currently does nothing.
121 function handles general locking functionality within the kernel, including
122 support for shared and exclusive locks, and recursion.
124 is also able to upgrade and downgrade locks.
127 .Bl -tag -width ".Fa interlkp"
129 A pointer to the lock to manipulate.
131 Flags indicating what action is to be taken.
132 .Bl -tag -width ".Dv LK_CANRECURSE"
134 Acquire a shared lock.
135 If an exclusive lock is currently held, it will be downgraded.
137 Acquire an exclusive lock.
138 If an exclusive lock is already held, and
140 is not set, the system will
143 Downgrade exclusive lock to a shared lock.
144 Downgrading a shared lock is not permitted.
145 If an exclusive lock has been recursed, all references will be downgraded.
147 Upgrade a shared lock to an exclusive lock.
148 If this call fails, the shared lock is lost.
149 During the upgrade, the shared lock could
150 be temporarily dropped.
151 Attempts to upgrade an exclusive lock will cause a
155 Releasing a lock that is not held can cause a
158 Wait for all activity on the lock to end, then mark it decommissioned.
159 This is used before freeing a lock that is part of a piece of memory that is
162 .In sys/lockmgr.h . )
164 Fail if operation has slept.
166 Do not allow the call to sleep.
167 This can be used to test the lock.
169 Allow recursion on an exclusive lock.
170 For every lock there must be a release.
172 Unlock the interlock (which should be locked already).
175 An interlock mutex for controlling group access to the lock.
182 is currently owned and not recursed, and will return it unlocked.
196 on a per-instance basis.
197 The specified values will override the default
198 ones, but this can still be used passing, respectively,
199 .Dv LK_WMESG_DEFAULT ,
202 .Dv LK_TIMO_DEFAULT .
206 function switches the owner from the current thread to be
208 if the lock is already held.
211 .Fn lockmgr_printinfo
212 function prints debugging information about the lock.
213 It is used primarily by
219 function returns true if the lock is recursed, 0
224 function returns the status of the lock in relation to the current thread.
227 .Cd "options INVARIANTS"
229 .Cd "options INVARIANT_SUPPORT" ,
234 for the assertions specified in
236 and panics if they are not met.
237 One of the following assertions must be specified:
238 .Bl -tag -width ".Dv KA_UNLOCKED"
240 Assert that the current thread has either a shared or an exclusive lock on the
242 lock pointed to by the first argument.
244 Assert that the current thread has a shared lock on the
246 lock pointed to by the first argument.
248 Assert that the current thread has an exclusive lock on the
250 lock pointed to by the first argument.
252 Assert that the current thread has no lock on the
254 lock pointed to by the first argument.
256 Assert that an unspecified thread has a lock on the
258 lock pointed to by the first argument.
260 Assert that no thread has a lock on the
262 lock pointed to by the first argument.
265 In addition, one of the following optional assertions can be used with
272 .Bl -tag -width ".Dv KA_NOTRECURSED"
274 Assert that the current thread has a recursed lock on
276 .It Dv KA_NOTRECURSED
277 Assert that the current thread does not have a recursed lock on
285 usage is highly discouraged.
286 They are intended to cater a bad behaviour
287 introduced by buffer cache lock handling.
288 They will hopefully be
289 made useless by revisiting such locks.
293 function returns 0 on success and non-zero on failure.
298 .Bl -tag -width ".Dv LK_EXCLUSIVE"
300 An exclusive lock is held by the current thread.
302 An exclusive lock is held by someone other than the current thread.
304 A shared lock is held.
306 The lock is not held by anyone.
314 was requested and another thread had already requested a lock upgrade.
317 was set, and a sleep would have been required.
325 was set in the lock priority, and a signal was delivered during a sleep.
331 was set in the lock priority, a signal was delivered during a sleep,
332 and the system call is to be restarted.
333 .It Bq Er EWOULDBLOCK
334 a non-zero timeout was given, and the timeout expired.
345 must be held prior to calling
347 and will be returned unlocked.
349 Upgrade attempts that fail result in the loss of the lock that
351 Also, it is invalid to upgrade an
352 exclusive lock, and a
354 will be the result of trying.
366 This manual page was written by
367 .An Chad David Aq davidc@acns.ab.ca .