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
27 .\" $FreeBSD: src/share/man/man9/lock.9,v 1.11 2003/09/08 19:57:21 ru Exp $
36 .Nm lockmgr_printinfo ,
38 .Nd "lockmgr family of functions"
43 .Fn lockinit "struct lock *lkp" "const char *wmesg" "int timo" "int flags"
45 .Fn lockuninit "struct lock *lkp"
47 .Fn lockmgr "struct lock *lkp" "u_int flags"
49 .Fn lockstatus "struct lock *lkp" "struct thread *td"
51 .Fn lockmgr_printinfo "struct lock *lkp"
53 .Fn lockowned "struct lock *lkp"
57 function is used to initialize a lock.
58 It must be called before any operation can be performed on a lock.
60 .Bl -tag -width ".Fa wmesg"
62 A pointer to the lock to initialize.
65 This is used for both debugging output and
68 The timeout value passed to
71 The flags the lock is to be initialized with.
72 .Bl -tag -width ".Dv LK_CANRECURSE"
74 Do not sleep while acquiring the lock.
78 Allow recursive exclusive locks.
82 during a sleep; otherwise, 0 is used.
88 function destroys a lock that was previously initialized using
93 function handles general locking functionality within the kernel, including
94 support for shared and exclusive locks, and recursion.
96 is also able to upgrade and downgrade locks.
99 .Bl -tag -width ".Fa flags"
101 A pointer to the lock to manipulate.
103 Flags indicating what action is to be taken.
104 .Bl -tag -width ".Dv LK_EXCLUPGRADE"
106 Acquire a shared lock.
107 If an exclusive lock is currently held, it will be downgraded.
109 Acquire an exclusive lock.
110 If an exclusive lock is already held, and
112 is not set, the system will
115 Downgrade exclusive lock to a shared lock.
116 Downgrading a shared lock is not permitted.
117 If an exclusive lock has been recursed, all references will be downgraded.
118 .It Dv LK_EXCLUPGRADE
119 Upgrade a shared lock to an exclusive lock.
122 if there is someone ahead of you in line waiting for an upgrade.
123 If this call fails for any reason, the shared lock is lost.
124 Attempts to upgrade an exclusive lock not already
125 owned by the caller will cause a
127 but otherwise will always succeed.
128 NOTE! When this operation succeeds, it guarantees that no other
129 exclusive lock was able to acquire the lock ahead of you, but
130 as indicated above, if it fails your current shared lock is lost.
132 Upgrade a shared lock to an exclusive lock.
133 If this call fails for any reason, the shared lock is lost.
134 Attempts to upgrade an exclusive lock not already
135 owned by the caller will cause a
137 but otherwise will always succeed.
138 WARNING! This operation can block with the current lock temporarily
139 released, and other exclusive or shared lock holders can inject before
140 the lock is acquired on your behalf.
143 Releasing a lock that is not held can cause a
146 Fail if operation has slept.
148 Do not allow the call to sleep.
149 This can be used to test the lock.
151 Allow recursion on an exclusive lock.
152 For every lock there must be a release.
158 function returns the status of the lock in relation to the
165 and an exclusive lock is held,
170 .Fn lockmgr_printinfo
171 function prints debugging information about the lock.
172 It is used primarily by
178 function is used to determine whether the calling thread owns a lock.
182 function returns 0 on success and non-zero on failure.
187 .Bl -tag -width ".Dv LK_EXCLUSIVE"
189 An exclusive lock is held by the thread
192 An exclusive lock is held by someone other than the thread
195 A shared lock is held.
197 The lock is not held by anyone.
202 function returns a non-zero return value if the caller owns the lock shared or exclusive.
204 The lock manager itself is implemented within the file
205 .Pa /sys/kern/kern_lock.c .
206 Data structures and function prototypes for the lock manager are in
207 .Pa /sys/sys/lock.h .
214 was set, and a sleep would have been required.
222 was set in the lock priority, and a signal was delivered during a sleep.
228 was set in the lock priority, a signal was delivered during a sleep,
229 and the system call is to be restarted.
230 .It Bq Er EWOULDBLOCK
231 a non-zero timeout was given, and the timeout expired.
234 Upgrade attempts that fail result in the loss of the lock that
236 Also, it is invalid to upgrade an
237 exclusive lock, and a
239 will be the result of trying.
246 The lock manager appeared in
249 The lock manager API first appeared in
252 This man page was written by
253 .An Chad David Aq Mt davidc@acns.ab.ca .