559eb8d2e3
* Fix hard sentence breaks.
164 lines
4.4 KiB
Groff
164 lines
4.4 KiB
Groff
.\"
|
|
.\" Copyright (c) 1996 Joerg Wunsch
|
|
.\"
|
|
.\" All rights reserved.
|
|
.\"
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
.\" modification, are permitted provided that the following conditions
|
|
.\" are met:
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
.\"
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
.\"
|
|
.\" $FreeBSD$
|
|
.\"
|
|
.Dd December 17, 1998
|
|
.Os
|
|
.Dt SLEEP 9
|
|
.Sh NAME
|
|
.Nm sleep ,
|
|
.Nm msleep ,
|
|
.Nm tsleep ,
|
|
.Nm wakeup
|
|
.Nd wait for events
|
|
.Sh SYNOPSIS
|
|
.In sys/param.h
|
|
.In sys/systm.h
|
|
.In sys/proc.h
|
|
.Ft int
|
|
.Fn tsleep "void *ident" "int priority" "const char *wmesg" "int timo"
|
|
.Ft int
|
|
.Fn msleep "void *ident" "struct mtx *mtx" "int priority" "const char *wmesg" "int timo"
|
|
.Ft void
|
|
.Fn wakeup "void *ident"
|
|
.Ft void
|
|
.Fn wakeup_one "void *ident"
|
|
.Sh DESCRIPTION
|
|
The functions
|
|
.Fn tsleep
|
|
and
|
|
.Fn wakeup
|
|
handle event-based process blocking.
|
|
If a process must wait for an
|
|
external event, it is put on sleep by
|
|
.Fn tsleep .
|
|
The parameter
|
|
.Fa ident
|
|
is an arbitrary address that uniquely identifies the event on which
|
|
the process is being asleep.
|
|
All processes sleeping on a single
|
|
.Fa ident
|
|
are woken up later by
|
|
.Fn wakeup ,
|
|
often called from inside an interrupt routine, to indicate that the
|
|
resource the process was blocking on is available now.
|
|
.Pp
|
|
The parameter
|
|
.Fa wmesg
|
|
is a string describing the sleep condition for tools like
|
|
.Xr ps 1 .
|
|
Due to the limited space of those programs to display arbitrary strings,
|
|
this message should not be longer than 6 characters.
|
|
.Pp
|
|
The
|
|
.Fn wakeup_one
|
|
function is used to make the first process in the queue that is
|
|
sleeping on the parameter
|
|
.Fa ident
|
|
runnable.
|
|
This can prevent the system from becoming saturated
|
|
when a large number of processes are sleeping on the same address,
|
|
but only one of them can actually do any useful work when made
|
|
runnable.
|
|
.Pp
|
|
The
|
|
.Fn tsleep
|
|
function is the general sleep call.
|
|
Suspends the current process until a wakeup is
|
|
performed on the specified identifier.
|
|
The process will then be made
|
|
runnable with the specified
|
|
.Fa priority .
|
|
Sleeps at most
|
|
.Fa timo
|
|
\&/ hz seconds (0 means no timeout).
|
|
If
|
|
.Fa pri
|
|
includes the
|
|
.Dv PCATCH
|
|
flag, signals are checked before and after sleeping, else signals are
|
|
not checked.
|
|
Returns 0 if awakened,
|
|
.Er EWOULDBLOCK
|
|
if the timeout expires.
|
|
If
|
|
.Dv PCATCH
|
|
is set and a signal needs to be delivered,
|
|
.Er ERESTART
|
|
is returned if the current system call should be restarted if
|
|
possible, and
|
|
.Er EINTR
|
|
is returned if the system call should be interrupted by the signal
|
|
(return
|
|
.Er EINTR ) .
|
|
.Pp
|
|
The
|
|
.Fn msleep
|
|
function is a variation on tsleep.
|
|
The parameter
|
|
.Fa mtx
|
|
is a mutex which will be released before sleeping and reacquired before
|
|
.Fn msleep
|
|
returns.
|
|
If
|
|
.Fa pri
|
|
includes the
|
|
.Dv PDROP
|
|
flag, the
|
|
.Fa mtx
|
|
parameter will not be reacquired before returning.
|
|
The mutex is
|
|
used to ensure that a condition can be checked atomically, and
|
|
that the current process can be suspended without missing a
|
|
change to the condition, or an associated wakeup.
|
|
.Sh RETURN VALUES
|
|
See above.
|
|
.Sh SEE ALSO
|
|
.Xr ps 1 ,
|
|
.Xr malloc 9 ,
|
|
.Xr mi_switch 9
|
|
.Sh HISTORY
|
|
The sleep/wakeup process synchronization mechanism is very old.
|
|
It
|
|
appeared in a very early version of
|
|
.Ux .
|
|
.Pp
|
|
The
|
|
.Fn tsleep
|
|
function appeared in
|
|
.Bx 4.4 .
|
|
.Pp
|
|
The
|
|
.Fn sleep
|
|
function used to be the traditional form.
|
|
It did not let you specify a timeout or a
|
|
.Fa wmesg ,
|
|
hence it was discontinued.
|
|
.Sh AUTHORS
|
|
.An -nosplit
|
|
This man page was written by
|
|
.An J\(:org Wunsch Aq joerg@FreeBSD.org .
|