1996-04-03 07:41:27 +00:00
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\"
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1996-04-03 07:41:27 +00:00
|
|
|
.\" "
|
1998-12-21 10:29:28 +00:00
|
|
|
.Dd December 17, 1998
|
1996-04-03 07:41:27 +00:00
|
|
|
.Os
|
|
|
|
.Dt SLEEP 9
|
|
|
|
.Sh NAME
|
1996-04-05 21:08:40 +00:00
|
|
|
.Nm sleep ,
|
2000-09-11 00:52:31 +00:00
|
|
|
.Nm msleep ,
|
1996-04-05 21:08:40 +00:00
|
|
|
.Nm tsleep ,
|
|
|
|
.Nm wakeup
|
1996-04-03 07:41:27 +00:00
|
|
|
.Nd wait for events
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Fd #include <sys/param.h>
|
|
|
|
.Fd #include <sys/systm.h>
|
|
|
|
.Fd #include <sys/proc.h>
|
|
|
|
.Ft int
|
1998-01-16 18:12:57 +00:00
|
|
|
.Fn tsleep "void *ident" "int priority" "const char *wmesg" "int timo"
|
1998-12-21 10:29:28 +00:00
|
|
|
.Ft int
|
2000-11-10 01:51:55 +00:00
|
|
|
.Fn msleep "void *ident" "struct mtx *mtx" "int priority" "const char *wmesg" "int timo"
|
1996-04-03 07:41:27 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn wakeup "void *ident"
|
1997-04-09 05:39:32 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn wakeup_one "void *ident"
|
1996-04-03 07:41:27 +00:00
|
|
|
.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
|
|
|
|
.Nm tsleep .
|
|
|
|
The parameter
|
|
|
|
.Ar ident
|
|
|
|
is an arbitrary address that uniquely identifies the event on which
|
1996-04-06 13:33:23 +00:00
|
|
|
the process is being asleep. All processes sleeping on a single
|
1996-04-03 07:41:27 +00:00
|
|
|
.Ar ident
|
|
|
|
are woken up later by
|
|
|
|
.Nm wakeup ,
|
|
|
|
often called from inside an interrupt routine, to indicate that the
|
|
|
|
resource the process was blocking on is available now.
|
|
|
|
.Pp
|
|
|
|
The parameter
|
|
|
|
.Ar 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
|
1997-04-09 05:39:32 +00:00
|
|
|
The
|
|
|
|
.Fn wakeup_one
|
|
|
|
function is used to make the first process in the queue that is
|
|
|
|
sleeping on the parameter
|
|
|
|
.Fa ident
|
2001-07-14 19:41:16 +00:00
|
|
|
runnable. This can prevent the system from becoming saturated
|
1997-04-09 05:39:32 +00:00
|
|
|
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
|
1996-04-03 07:41:27 +00:00
|
|
|
.Nm Tsleep
|
|
|
|
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
|
|
|
|
.Ar priority .
|
|
|
|
Sleeps at most
|
|
|
|
.Ar timo
|
|
|
|
\&/ hz seconds (0 means no timeout). If
|
|
|
|
.Ar pri
|
|
|
|
includes the
|
1996-04-05 23:23:25 +00:00
|
|
|
.Dv PCATCH
|
1996-04-03 07:41:27 +00:00
|
|
|
flag, signals are checked before and after sleeping, else signals are
|
|
|
|
not checked. Returns 0 if awakened,
|
2000-11-22 16:11:48 +00:00
|
|
|
.Er EWOULDBLOCK
|
1996-04-03 07:41:27 +00:00
|
|
|
if the timeout expires. If
|
1996-04-05 23:23:25 +00:00
|
|
|
.Dv PCATCH
|
1996-04-03 07:41:27 +00:00
|
|
|
is set and a signal needs to be delivered,
|
2000-11-22 16:11:48 +00:00
|
|
|
.Er ERESTART
|
1996-04-03 07:41:27 +00:00
|
|
|
is returned if the current system call should be restarted if
|
|
|
|
possible, and
|
2000-11-22 16:11:48 +00:00
|
|
|
.Er EINTR
|
1996-04-03 07:41:27 +00:00
|
|
|
is returned if the system call should be interrupted by the signal
|
2001-08-07 15:48:51 +00:00
|
|
|
(return
|
|
|
|
.Er EINTR ) .
|
1996-04-03 07:41:27 +00:00
|
|
|
.Pp
|
2000-09-11 00:52:31 +00:00
|
|
|
.Nm Msleep
|
|
|
|
is a variation on tsleep. The parameter
|
|
|
|
.Ar mtx
|
|
|
|
is a mutex, which will be exited before sleeping, and entered before
|
|
|
|
.Nm msleep
|
|
|
|
returns. If
|
|
|
|
.Ar pri
|
|
|
|
includes the
|
|
|
|
.Dv PDROP
|
|
|
|
flag, the
|
|
|
|
.Ar mtx
|
|
|
|
parameter will not be entered before returning. The mutex is
|
|
|
|
used to ensure that a condition can be checked atomicly, and
|
|
|
|
that the current process can be suspended without missing a
|
|
|
|
change to the condition, or an associated wakeup.
|
1996-04-03 07:41:27 +00:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
See above.
|
|
|
|
.Sh SEE ALSO
|
1998-12-23 00:24:59 +00:00
|
|
|
.Xr ps 1 ,
|
2000-08-15 15:14:13 +00:00
|
|
|
.Xr malloc 9 ,
|
|
|
|
.Xr mi_switch 9
|
1996-04-03 07:41:27 +00:00
|
|
|
.Sh HISTORY
|
1996-04-07 08:37:54 +00:00
|
|
|
The sleep/wakeup process synchronization mechanism is very old. It
|
1996-04-03 07:41:27 +00:00
|
|
|
appeared in a very early version of Unix.
|
|
|
|
.Pp
|
|
|
|
.Nm Tsleep
|
|
|
|
appeared in
|
|
|
|
.Bx 4.4 .
|
1998-12-21 10:34:53 +00:00
|
|
|
.Pp
|
1999-11-03 10:39:54 +00:00
|
|
|
.Nm Sleep
|
2000-05-09 20:35:13 +00:00
|
|
|
used to be the traditional form. It doesn't let you specify a timeout or a
|
1999-11-03 10:39:54 +00:00
|
|
|
.Ar wmesg ,
|
|
|
|
hence it has been discontinued.
|
1996-04-03 07:41:27 +00:00
|
|
|
.Sh AUTHORS
|
2000-11-22 09:35:58 +00:00
|
|
|
.An -nosplit
|
2000-08-15 15:09:13 +00:00
|
|
|
This man page was written by
|
2000-11-10 17:46:15 +00:00
|
|
|
.An J\(:org Wunsch .
|