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 .Nd "lockmgr family of functions"
44 .Fn lockinit "struct lock *lkp" "int prio" "const char *wmesg" "int timo" "int flags"
46 .Fn lockdestroy "struct lock *lkp"
48 .Fn lockcount "struct lock *lkp"
50 .Fn lockmgr "struct lock *lkp" "u_int flags" "struct mtx *interlkp" "struct thread *td"
52 .Fn lockstatus "struct lock *lkp" "struct thread *td"
54 .Fn lockmgr_printinfo "struct lock *lkp"
58 function is used to initialize a lock.
59 It must be called before any operation can be performed on a lock.
61 .Bl -tag -width ".Fa wmesg"
63 A pointer to the lock to initialize.
65 The priority passed to
69 This is used for both debugging output and
72 The timeout value passed to
75 The flags the lock is to be initialized with.
76 .Bl -tag -width ".Dv LG_CANRECURSE"
78 Do not sleep while acquiring the lock.
82 Allow recursive exclusive locks.
84 Allow exclusive locks only.
88 during a sleep; otherwise, 0 is used.
94 function is used to destroy a lock, and while it is called in a number of
95 places in the kernel, it currently does nothing.
99 function returns a count of the number of exclusive locks and shared locks
100 held against the lock
105 function handles general locking functionality within the kernel, including
106 support for shared and exclusive locks, and recursion.
108 is also able to upgrade and downgrade locks.
111 .Bl -tag -width ".Fa interlkp"
113 A pointer to the lock to manipulate.
115 Flags indicating what action is to be taken.
116 .Bl -tag -width ".Dv LK_EXCLUPGRADE"
118 Acquire a shared lock.
119 If an exclusive lock is currently held, it will be downgraded.
121 Acquire an exclusive lock.
122 If an exclusive lock is already held, and
124 is not set, the system will
127 Downgrade exclusive lock to a shared lock.
128 Downgrading a shared lock is not permitted.
129 If an exclusive lock has been recursed, all references will be downgraded.
130 .It Dv LK_EXCLUPGRADE
131 Upgrade a shared lock to an exclusive lock.
134 if there is someone ahead of you in line waiting for an upgrade.
135 If this call fails, the shared lock is lost.
136 Attempts to upgrade an exclusive lock will cause a
139 Upgrade a shared lock to an exclusive lock.
140 If this call fails, the shared lock is lost.
141 During the upgrade, the shared lock could
142 be temporarily dropped.
143 Attempts to upgrade an exclusive lock will cause a
147 Releasing a lock that is not held can cause a
150 Wait for all activity on the lock to end, then mark it decommissioned.
151 This is used before freeing a lock that is part of a piece of memory that is
154 .In sys/lockmgr.h . )
156 Fail if operation has slept.
158 Do not allow the call to sleep.
159 This can be used to test the lock.
161 Allow recursion on an exclusive lock.
162 For every lock there must be a release.
164 Unlock the interlock (which should be locked already).
167 An interlock mutex for controlling group access to the lock.
174 is currently owned and not recursed, and will return it unlocked.
178 A thread responsible for this call.
186 function returns the status of the lock in relation to the
193 and an exclusive lock is held,
198 .Fn lockmgr_printinfo
199 function prints debugging information about the lock.
200 It is used primarily by
206 function returns an integer greater than or equal to zero.
210 function returns 0 on success and non-zero on failure.
215 .Bl -tag -width ".Dv LK_EXCLUSIVE"
217 An exclusive lock is held by the thread
220 An exclusive lock is held by someone other than the thread
223 A shared lock is held.
225 The lock is not held by anyone.
233 was requested and another thread had already requested a lock upgrade.
236 was set, and a sleep would have been required.
244 was set in the lock priority, and a signal was delivered during a sleep.
250 was set in the lock priority, a signal was delivered during a sleep,
251 and the system call is to be restarted.
252 .It Bq Er EWOULDBLOCK
253 a non-zero timeout was given, and the timeout expired.
264 must be held prior to calling
266 and will be returned unlocked.
268 Upgrade attempts that fail result in the loss of the lock that
270 Also, it is invalid to upgrade an
271 exclusive lock, and a
273 will be the result of trying.
285 This manual page was written by
286 .An Chad David Aq davidc@acns.ab.ca .