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
39 .Nm lockmgr_printinfo ,
40 .Nm lockmgr_recursed ,
44 .Nd "lockmgr family of functions"
50 .Fn lockinit "struct lock *lkp" "int prio" "const char *wmesg" "int timo" "int flags"
52 .Fn lockdestroy "struct lock *lkp"
54 .Fn lockmgr "struct lock *lkp" "u_int flags" "struct mtx *ilk"
56 .Fn lockmgr_args "struct lock *lkp" "u_int flags" "struct mtx *ilk" "const char *wmesg" "int prio" "int timo"
58 .Fn lockmgr_args_rw "struct lock *lkp" "u_int flags" "struct rwlock *ilk" "const char *wmesg" "int prio" "int timo"
60 .Fn lockmgr_disown "struct lock *lkp"
62 .Fn lockmgr_printinfo "const struct lock *lkp"
64 .Fn lockmgr_recursed "const struct lock *lkp"
66 .Fn lockmgr_rw "struct lock *lkp" "u_int flags" "struct rwlock *ilk"
68 .Fn lockstatus "const struct lock *lkp"
70 .Cd "options INVARIANTS"
71 .Cd "options INVARIANT_SUPPORT"
73 .Fn lockmgr_assert "const struct lock *lkp" "int what"
77 function is used to initialize a lock.
78 It must be called before any operation can be performed on a lock.
80 .Bl -tag -width ".Fa wmesg"
82 A pointer to the lock to initialize.
84 The priority passed to
88 This is used for both debugging output and
91 The timeout value passed to
94 The flags the lock is to be initialized with:
95 .Bl -tag -width ".Dv LK_CANRECURSE"
97 Enable adaptive spinning for this lock if the kernel is compiled with the
98 ADAPTIVE_LOCKMGRS option.
100 Allow recursive exclusive locks.
102 Disable lock profiling for this lock.
104 Allow exclusive locks only.
111 should log messages about duplicate locks being acquired.
115 logging for this lock.
119 during a sleep; otherwise, 0 is used.
125 function is used to destroy a lock, and while it is called in a number of
126 places in the kernel, it currently does nothing.
132 functions handle general locking functionality within the kernel, including
133 support for shared and exclusive locks, and recursion.
137 are also able to upgrade and downgrade locks.
140 .Bl -tag -width ".Fa flags"
142 A pointer to the lock to manipulate.
144 Flags indicating what action is to be taken.
145 .Bl -tag -width ".Dv LK_NODDLKTREAT"
147 Acquire a shared lock.
148 If an exclusive lock is currently held,
152 Acquire an exclusive lock.
153 If an exclusive lock is already held, and
155 is not set, the system will
158 Downgrade exclusive lock to a shared lock.
159 Downgrading a shared lock is not permitted.
160 If an exclusive lock has been recursed, the system will
163 Upgrade a shared lock to an exclusive lock.
164 If this call fails, the shared lock is lost, even if the
167 During the upgrade, the shared lock could
168 be temporarily dropped.
169 Attempts to upgrade an exclusive lock will cause a
172 Try to upgrade a shared lock to an exclusive lock.
173 The failure to upgrade does not result in the dropping
174 of the shared lock ownership.
177 Releasing a lock that is not held can cause a
180 Wait for all activity on the lock to end, then mark it decommissioned.
181 This is used before freeing a lock that is part of a piece of memory that is
184 .In sys/lockmgr.h . )
186 Fail if operation has slept.
188 Do not allow the call to sleep.
189 This can be used to test the lock.
193 checks for this instance.
195 Allow recursion on an exclusive lock.
196 For every lock there must be a release.
198 Unlock the interlock (which should be locked already).
199 .It Dv LK_NODDLKTREAT
202 postpones serving further shared requests for shared-locked lock if there is
203 exclusive waiter, to avoid exclusive lock starvation.
204 But, if the thread requesting the shared lock already owns a shared lockmgr
205 lock, the request is granted even in presence of the parallel exclusive lock
206 request, which is done to avoid deadlocks with recursive shared acquisition.
210 flag can only be used by code which requests shared non-recursive lock.
211 The flag allows exclusive requests to preempt the current shared request
212 even if the current thread owns shared locks.
213 This is safe since shared lock is guaranteed to not recurse, and is used
214 when thread is known to held unrelated shared locks, to not cause
215 unnecessary starvation.
225 An interlock mutex for controlling group access to the lock.
234 is currently owned and not recursed, and will return it unlocked.
252 on a per-instance basis.
253 The specified values will override the default
254 ones, but this can still be used passing, respectively,
255 .Dv LK_WMESG_DEFAULT ,
258 .Dv LK_TIMO_DEFAULT .
262 function switches the owner from the current thread to be
264 if the lock is already held.
267 .Fn lockmgr_printinfo
268 function prints debugging information about the lock.
269 It is used primarily by
275 function returns true if the lock is recursed, 0
280 function returns the status of the lock in relation to the current thread.
283 .Cd "options INVARIANTS"
285 .Cd "options INVARIANT_SUPPORT" ,
290 for the assertions specified in
292 and panics if they are not met.
293 One of the following assertions must be specified:
294 .Bl -tag -width ".Dv KA_UNLOCKED"
296 Assert that the current thread has either a shared or an exclusive lock on the
298 lock pointed to by the first argument.
300 Assert that the current thread has a shared lock on the
302 lock pointed to by the first argument.
304 Assert that the current thread has an exclusive lock on the
306 lock pointed to by the first argument.
308 Assert that the current thread has no lock on the
310 lock pointed to by the first argument.
313 In addition, one of the following optional assertions can be used with
320 .Bl -tag -width ".Dv KA_NOTRECURSED"
322 Assert that the current thread has a recursed lock on
324 .It Dv KA_NOTRECURSED
325 Assert that the current thread does not have a recursed lock on
333 functions return 0 on success and non-zero on failure.
338 .Bl -tag -width ".Dv LK_EXCLUSIVE"
340 An exclusive lock is held by the current thread.
342 An exclusive lock is held by someone other than the current thread.
344 A shared lock is held.
346 The lock is not held by anyone.
356 was requested and another thread had already requested a lock upgrade.
359 was set, and a sleep would have been required, or
361 operation was not able to upgrade the lock.
371 was set in the lock priority, and a signal was delivered during a sleep.
377 was set in the lock priority, a signal was delivered during a sleep,
378 and the system call is to be restarted.
379 .It Bq Er EWOULDBLOCK
380 a non-zero timeout was given, and the timeout expired.
393 must be held prior to calling
397 and will be returned unlocked.
399 Upgrade attempts that fail result in the loss of the lock that
401 Also, it is invalid to upgrade an
402 exclusive lock, and a
404 will be the result of trying.
416 This manual page was written by
417 .An Chad David Aq Mt davidc@acns.ab.ca .