xref: /freebsd/share/man/man9/lock.9 (revision 32eef9aeb1f39a1623cea55da147c89abbd5b9a5)
1e5e600c9SMark Murray.\" Copyright (c) 2000
2e5e600c9SMark Murray.\"	The Regents of the University of California.  All rights reserved.
3e5e600c9SMark Murray.\"
4e5e600c9SMark Murray.\" All rights reserved.
5e5e600c9SMark Murray.\"
6e5e600c9SMark Murray.\" Redistribution and use in source and binary forms, with or without
7e5e600c9SMark Murray.\" modification, are permitted provided that the following conditions
8e5e600c9SMark Murray.\" are met:
9e5e600c9SMark Murray.\" 1. Redistributions of source code must retain the above copyright
10e5e600c9SMark Murray.\"    notice, this list of conditions and the following disclaimer.
11e5e600c9SMark Murray.\" 2. Redistributions in binary form must reproduce the above copyright
12e5e600c9SMark Murray.\"    notice, this list of conditions and the following disclaimer in the
13e5e600c9SMark Murray.\"    documentation and/or other materials provided with the distribution.
14e5e600c9SMark Murray.\"
15e5e600c9SMark Murray.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16e5e600c9SMark Murray.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17e5e600c9SMark Murray.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18e5e600c9SMark Murray.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19e5e600c9SMark Murray.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20e5e600c9SMark Murray.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21e5e600c9SMark Murray.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22e5e600c9SMark Murray.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23e5e600c9SMark Murray.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24e5e600c9SMark Murray.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25e5e600c9SMark Murray.\"
26e5e600c9SMark Murray.\" $FreeBSD$
27e5e600c9SMark Murray.\"
28ea3d1f09SRuslan Ermilov.Dd October 24, 2000
29e5e600c9SMark Murray.Dt LOCK 9
303d45e180SRuslan Ermilov.Os
31e5e600c9SMark Murray.Sh NAME
32e5e600c9SMark Murray.Nm lockinit ,
33e5e600c9SMark Murray.Nm lockmgr ,
34e5e600c9SMark Murray.Nm lockcount ,
35e5e600c9SMark Murray.Nm lockstatus
36e5e600c9SMark Murray.Nd kernel process locking
37e5e600c9SMark Murray.Sh SYNOPSIS
3832eef9aeSRuslan Ermilov.In sys/types.h
3932eef9aeSRuslan Ermilov.In sys/lock.h
40e5e600c9SMark Murray.Ft void
41e5e600c9SMark Murray.Fn lockinit "struct lock *lkp" "int prio" "char *wmesg" "int timo" "int flags"
42e5e600c9SMark Murray.Ft int
43e5e600c9SMark Murray.Fn lockmgr "struct lock *lkp" "u_int flags" "struct simplelock *interlkp" "struct proc *p"
44e5e600c9SMark Murray.Ft int
45e5e600c9SMark Murray.Fn lockcount "struct lock *lkp"
46e5e600c9SMark Murray.Ft int
47e5e600c9SMark Murray.Fn lockstatus "struct lock *lkp" "struct proc *p"
48e5e600c9SMark Murray.Sh DESCRIPTION
49e5e600c9SMark MurrayThe function
50e5e600c9SMark Murray.Fn lockinit
51e5e600c9SMark Murrayis used to initialise a lock.
52e5e600c9SMark MurrayIt is required if locks are used.
53e5e600c9SMark MurrayThe function
54e5e600c9SMark Murray.Fn lockmgr
55e5e600c9SMark Murrayis used to manage locks.
56e5e600c9SMark MurrayThe function
57e5e600c9SMark Murray.Fn lockcount
58e5e600c9SMark Murrayreturns the number of shared lock holders on a lock.
59e5e600c9SMark MurrayThe function
60e5e600c9SMark Murray.Fn lockstatus
61e5e600c9SMark Murraydetermines the status of a lock.
62e5e600c9SMark Murray.Pp
63e5e600c9SMark MurrayThe following values are defined:
64e5e600c9SMark Murray.Bl -tag -width "LK_XXXXXXXXXXXX" -compact
65e5e600c9SMark Murray.It Dv LK_SHARED
66e5e600c9SMark Murrayget one of many possible shared locks.
67e5e600c9SMark MurrayIf a process holding an exclusive lock requests a shared lock,
68e5e600c9SMark Murraythe exclusive lock(s) will be downgraded to shared locks.
69e5e600c9SMark Murray.It Dv LK_EXCLUSIVE
70e5e600c9SMark Murraystop further shared locks, when they are cleared,
71e5e600c9SMark Murraygrant a pending upgrade if it exists, then grant an exclusive
72e5e600c9SMark Murraylock.
73e5e600c9SMark MurrayOnly one exclusive lock may exist at a time, except that
74e5e600c9SMark Murraya process holding an exclusive lock may get additional exclusive
75e5e600c9SMark Murraylocks if it explicitly sets the LK_CANRECURSE flag in the lock
76e5e600c9SMark Murrayrequest, or if the LK_CANRECUSE flag was set when the lock was
77e5e600c9SMark Murrayinitialized.
78e5e600c9SMark Murray.It Dv LK_UPGRADE
79e5e600c9SMark Murraythe process must hold a shared lock that it wants to
80e5e600c9SMark Murrayhave upgraded to an exclusive lock.
81e5e600c9SMark MurrayOther processes may get exclusive access to the resource between
82e5e600c9SMark Murraythe time that the upgrade is requested and the time that it is
83e5e600c9SMark Murraygranted.
84e5e600c9SMark Murray.It Dv LK_EXCLUPGRADE
85e5e600c9SMark Murraythe process must hold a shared lock that it wants to
86e5e600c9SMark Murrayhave upgraded to an exclusive lock.
87e5e600c9SMark MurrayIf the request succeeds, no other processes will have gotten
88e5e600c9SMark Murrayexclusive access to the resource between the time that the upgrade
89e5e600c9SMark Murrayis requested and the time that it is granted.
90e5e600c9SMark MurrayHowever, if another process has already requested an upgrade,
91e5e600c9SMark Murraythe request will fail.
92e5e600c9SMark Murray.It Dv LK_DOWNGRADE
93e5e600c9SMark Murraythe process must hold an exclusive lock that it wants
94e5e600c9SMark Murrayto have downgraded to a shared lock.
95e5e600c9SMark MurrayIf the process holds multiple (recursive) exclusive locks,
96e5e600c9SMark Murraythey will all be downgraded to shared locks.
97e5e600c9SMark Murray.It Dv LK_RELEASE
98e5e600c9SMark Murrayrelease one instance of a lock.
99e5e600c9SMark Murray.It Dv LK_DRAIN
100e5e600c9SMark Murraywait for all activity on the lock to end, then mark it
101e5e600c9SMark Murraydecommissioned.
102e5e600c9SMark MurrayThis feature is used before freeing a lock that is part of a
103e5e600c9SMark Murraypiece of memory that is about to be freed.
104e5e600c9SMark Murray.It Dv LK_EXCLOTHER
105e5e600c9SMark Murrayreturn for lockstatus().
106e5e600c9SMark MurrayUsed when another process holds the lock exclusively.
107e5e600c9SMark Murray.El
108e5e600c9SMark Murray.Sh RETURN VALUES
109e5e600c9SMark MurraySuccessfully obtained locks return 0.
110e5e600c9SMark MurrayLocks will always succeed unless one of the following is true:
111e5e600c9SMark MurrayLK_FORCEUPGRADE is requested and some other process has already
112e5e600c9SMark Murrayrequested a lock upgrade; returns
113e5e600c9SMark Murray.Er EBUSY .
114e5e600c9SMark MurrayLK_WAIT is set and a sleep would be required; returns
115e5e600c9SMark Murray.Er EBUSY .
116e5e600c9SMark MurrayLK_SLEEPFAIL is set and a sleep was done; returns
117e5e600c9SMark Murray.Er ENOLCK .
118e5e600c9SMark MurrayPCATCH is set in lock priority and a signal arrives; returns
119e5e600c9SMark Murrayeither
120e5e600c9SMark Murray.Er EINTR
121e5e600c9SMark Murrayor
122e5e600c9SMark Murray.Er ERESTART
123e5e600c9SMark Murrayif system calls is to be restarted.
124e5e600c9SMark MurrayNon-null lock timeout and timeout expires; returns
125e5e600c9SMark Murray.Er EWOULDBLOCK .
126e5e600c9SMark MurrayA failed lock attempt always returns a non-zero error value.
127e5e600c9SMark MurrayNo lock is held after an error return (in particular, a failed
128e5e600c9SMark MurrayLK_UPGRADE or LK_FORCEUPGRADE will have released its shared
129e5e600c9SMark Murrayaccess lock).
130