2 .\" Copyright (c) 2004,2010 The DragonFly Project. All rights reserved.
4 .\" This code is derived from software contributed to The DragonFly Project
5 .\" by Hiten Pandya <hmp@backplane.com>.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in
15 .\" the documentation and/or other materials provided with the
17 .\" 3. Neither the name of The DragonFly Project nor the names of its
18 .\" contributors may be used to endorse or promote products derived
19 .\" from this software without specific, prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 .\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" Copyright (c) 1996 Joerg Wunsch
36 .\" All rights reserved.
38 .\" Redistribution and use in source and binary forms, with or without
39 .\" modification, are permitted provided that the following conditions
41 .\" 1. Redistributions of source code must retain the above copyright
42 .\" notice, this list of conditions and the following disclaimer.
43 .\" 2. Redistributions in binary form must reproduce the above copyright
44 .\" notice, this list of conditions and the following disclaimer in the
45 .\" documentation and/or other materials provided with the distribution.
47 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
48 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
51 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 .\" $FreeBSD: src/share/man/man9/sleep.9,v 1.18.2.5 2001/12/17 11:30:19 ru Exp $
69 .Nm tsleep_interlock ,
72 .Nd wait/sleep/block for events
79 .Fn tsleep "void *ident" "int flags" "const char *wmesg" "int timo"
81 .Fn ssleep "void *ident" "struct spinlock *spin" "int flags" "const char *wmesg" "int timo"
83 .Fn lksleep "void *ident" "struct lock *lock" "int flags" "const char *wmesg" "int timo"
85 .Fn mtxsleep "void *ident" "struct mtx *mtx" "int flags" "const char *wmesg" "int timo"
87 .Fn zsleep "void *ident" "struct lwkt_serialize *slz" "int flags" "const char *wmesg" "int timo"
89 .Fn tsleep_interlock "void *ident" "int flags"
91 .Fn wakeup "void *ident"
93 .Fn wakeup_one "void *ident"
103 handle event-based process blocking.
104 If a process must wait for an
105 external event, it is put on sleep by
115 is an arbitrary address that uniquely identifies the event on which
116 the process is being asleep.
117 All processes sleeping on a single
119 are woken up later by
121 often called from inside an interrupt routine, to indicate that the
122 resource the process/thread was blocking on is available now.
126 is a string describing the sleep condition for tools like
128 Due to the limited space of those programs to display arbitrary strings,
129 this message should not be longer than 6 characters.
133 function is general in its use and suspends the current process/thread until a
134 wakeup is performed on the specified identifier.
135 The process/thread will then be made runnable.
136 The process/thread will sleep at most
138 \&/ hz seconds (0 means no timeout).
143 flag, signals are checked before and after sleeping, else signals are
149 in that it queues a thread on a sleep queue, but it does not actually put the
151 This allows coupling tsleep with higher-level synchronization primitives.
154 (acquire high level synchronization primitive)
155 (test condition of interest)
156 tsleep_interlock(ident, flags)
157 (release high level synchronization primitive)
158 tsleep(..., PINTERLOCK)
161 For example, to implement
164 spin_lock_wr(&important_lock);
165 if (important_condition == 0) {
166 tsleep_interlock(ident, flags);
167 spin_unlock_wr(&important_lock);
168 tsleep(..., PINTERLOCK);
176 while at the same time releasing the exclusive (write) spinlock
178 before sleeping and reacquiring it before
181 This is an atomic operation, which guarantees that a
191 while at the same time releasing the exclusive lockmgr lock
193 before sleeping and reacquiring it before
196 This is an atomic operation, which guarantees that a
206 while at the same time atomically releasing the mutex
208 before sleeping and reacquiring it in exclusive state before
216 while at the same time releasing the serializer
218 before sleeping and reacquiring it before
221 This is an atomic operation, which guarantees that a
229 function is used to make the first process/thread in the queue that is
230 sleeping on the parameter
233 This can prevent the system from becoming saturated
234 when a large number of processes/threads are sleeping on the same address,
235 but only one of them can actually do any useful work when made
237 .Sh IMPLEMENTATION NOTES
244 ignores priority information because it is not required by the
249 flag set are assumed to be disk-waits, otherwise they are
256 if awakened, otherwise an appropriate error code is returned.
258 The various sleep functions are in
259 .Pa /sys/kern/kern_synch.c .
262 .It Bq Er EWOULDBLOCK
265 A signal needs to be delivered and the system call should
266 be restarted if possible.
272 The system call needs to be interrupted by the signal.
283 The sleep/wakeup process synchronization mechanism is very old.
284 It appeared in a very early version of Unix.
304 This manual page was written by
309 .An Hiten Pandya Aq hmp@dragonflybsd.org