Deleted Added
full compact
1.\"
2.\" Copyright (C) 2002 Chad David <davidc@acns.ab.ca>. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice(s), this list of conditions and the following disclaimer as

--- 10 unchanged lines hidden (view full) ---

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
25.\" DAMAGE.
26.\"
27.\" $FreeBSD: head/share/man/man9/lock.9 177697 2008-03-28 21:30:37Z brueffer $
27.\" $FreeBSD: head/share/man/man9/lock.9 177962 2008-04-06 21:22:12Z attilio $
28.\"
29.Dd March 28, 2008
29.Dd April 6, 2008
30.Dt LOCK 9
31.Os
32.Sh NAME
33.Nm lockinit ,
34.Nm lockdestroy ,
35.Nm lockmgr ,
36.Nm lockmgr_args ,
37.Nm lockmgr_args_rw ,
38.Nm lockmgr_disown ,
39.Nm lockmgr_printinfo ,
40.Nm lockmgr_recursed ,
41.Nm lockmgr_rw ,
42.Nm lockmgr_waiters ,
43.Nm lockstatus ,
44.Nm lockmgr_assert
45.Nd "lockmgr family of functions"
46.Sh SYNOPSIS
47.In sys/types.h
48.In sys/lock.h
49.In sys/lockmgr.h
50.Ft void
51.Fn lockinit "struct lock *lkp" "int prio" "const char *wmesg" "int timo" "int flags"
52.Ft void
53.Fn lockdestroy "struct lock *lkp"
54.Ft int
53.Fn lockmgr "struct lock *lkp" "u_int flags" "struct mtx *interlkp"
55.Fn lockmgr "struct lock *lkp" "u_int flags" "struct mtx *ilk"
56.Ft int
55.Fn lockmgr_args "struct lock *lkp" "u_int flags" "struct mtx *interlkp" "const char *wmesg" "int prio" "int timo"
57.Fn lockmgr_args "struct lock *lkp" "u_int flags" "struct mtx *ilk" "const char *wmesg" "int prio" "int timo"
58.Ft int
59.Fn lockmgr_args_rw "struct lock *lkp" "u_int flags" "struct rwlock *ilk" "const char *wmesg" "int prio" "int timo"
60.Ft void
61.Fn lockmgr_disown "struct lock *lkp"
62.Ft void
63.Fn lockmgr_printinfo "struct lock *lkp"
64.Ft int
65.Fn lockmgr_recursed "struct lock *lkp"
66.Ft int
67.Fn lockmgr_rw "struct lock *lkp" "u_int flags" "struct rwlock *ilk"
68.Ft int
69.Fn lockmgr_waiters "struct lock *lkp"
70.Ft int
71.Fn lockstatus "struct lock *lkp"
72.Pp
73.Cd "options INVARIANTS"
74.Cd "options INVARIANT_SUPPORT"
75.Ft void
76.Fn lockmgr_assert "struct lock *lkp" "int what"

--- 45 unchanged lines hidden (view full) ---

122.Pp
123The
124.Fn lockdestroy
125function is used to destroy a lock, and while it is called in a number of
126places in the kernel, it currently does nothing.
127.Pp
128The
129.Fn lockmgr
124function handles general locking functionality within the kernel, including
130and
131.Fn lockmgr_rw
132functions handle general locking functionality within the kernel, including
133support for shared and exclusive locks, and recursion.
134.Fn lockmgr
127is also able to upgrade and downgrade locks.
135and
136.Fn lockmgr_rw
137are also able to upgrade and downgrade locks.
138.Pp
129Its arguments are:
130.Bl -tag -width ".Fa interlkp"
139Their arguments are:
140.Bl -tag -width ".Fa flags"
141.It Fa lkp
142A pointer to the lock to manipulate.
143.It Fa flags
144Flags indicating what action is to be taken.
145.Bl -tag -width ".Dv LK_CANRECURSE"
146.It Dv LK_SHARED
147Acquire a shared lock.
148If an exclusive lock is currently held, it will be downgraded.

--- 30 unchanged lines hidden (view full) ---

179Do not allow the call to sleep.
180This can be used to test the lock.
181.It Dv LK_CANRECURSE
182Allow recursion on an exclusive lock.
183For every lock there must be a release.
184.It Dv LK_INTERLOCK
185Unlock the interlock (which should be locked already).
186.El
177.It Fa interlkp
187.It Fa ilk
188An interlock mutex for controlling group access to the lock.
189If
190.Dv LK_INTERLOCK
191is specified,
192.Fn lockmgr
183assumes
184.Fa interlkp
193and
194.Fn lockmgr_rw
195assume
196.Fa ilk
197is currently owned and not recursed, and will return it unlocked.
198See
199.Xr mtx_assert 9 .
200.El
201.Pp
202The
203.Fn lockmgr_args
192function works like
204and
205.Fn lockmgr_args_rw
206function work like
207.Fn lockmgr
208and
209.Fn lockmgr_rw
210but accepting a
211.Fa wmesg ,
212.Fa timo
213and
214.Fa prio
215on a per-instance basis.
216The specified values will override the default
217ones, but this can still be used passing, respectively,

--- 90 unchanged lines hidden (view full) ---

308usage is highly discouraged.
309They are intended to cater a bad behaviour
310introduced by buffer cache lock handling.
311They will hopefully be
312made useless by revisiting such locks.
313.Sh RETURN VALUES
314The
315.Fn lockmgr
300function returns 0 on success and non-zero on failure.
316and
317.Fn lockmgr_rw
318functions return 0 on success and non-zero on failure.
319.Pp
320The
321.Fn lockstatus
322function returns:
323.Bl -tag -width ".Dv LK_EXCLUSIVE"
324.It Dv LK_EXCLUSIVE
325An exclusive lock is held by the current thread.
326.It Dv LK_EXCLOTHER
327An exclusive lock is held by someone other than the current thread.
328.It Dv LK_SHARED
329A shared lock is held.
330.It Li 0
331The lock is not held by anyone.
332.El
333.Sh ERRORS
334.Fn lockmgr
317fails if:
335and
336.Fn lockmgr_rw
337fail if:
338.Bl -tag -width Er
339.It Bq Er EBUSY
340.Dv LK_FORCEUPGRADE
341was requested and another thread had already requested a lock upgrade.
342.It Bq Er EBUSY
343.Dv LK_NOWAIT
344was set, and a sleep would have been required.
345.It Bq Er ENOLCK
346.Dv LK_SLEEPFAIL
347was set and
348.Fn lockmgr
349or
350.Fn lockmgr_rw
351did sleep.
352.It Bq Er EINTR
353.Dv PCATCH
354was set in the lock priority, and a signal was delivered during a sleep.
355Note the
356.Er ERESTART
357error below.
358.It Bq Er ERESTART

--- 4 unchanged lines hidden (view full) ---

363a non-zero timeout was given, and the timeout expired.
364.El
365.Sh LOCKS
366If
367.Dv LK_INTERLOCK
368is passed in the
369.Fa flags
370argument to
349.Fn lockmgr ,
371.Fn lockmgr
372or
373.Fn lockmgr_rw ,
374the
351.Fa interlkp
375.Fa ilk
376must be held prior to calling
353.Fn lockmgr ,
377.Fn lockmgr
378or
379.Fn lockmgr_rw ,
380and will be returned unlocked.
381.Pp
382Upgrade attempts that fail result in the loss of the lock that
383is currently held.
384Also, it is invalid to upgrade an
385exclusive lock, and a
386.Xr panic 9
387will be the result of trying.

--- 13 unchanged lines hidden ---