int
ltsleep(
wchan_t ident
, pri_t priority
, const char *wmesg
, int timo
, volatile struct simplelock *slock
)
int
tsleep(
wchan_t ident
, pri_t priority
, const char *wmesg
, int timo
)
void
wakeup(
wchan_t ident
)
Please see the condvar(9), mutex(9), and rwlock(9) manual pages for information on kernel synchronisation primitives.
These functions implement voluntary context switching.
ltsleep()
and
tsleep(
)
are used throughout the kernel whenever processing in the current context
can not continue for any of the following reasons:
The function
wakeup()
is used to notify sleeping processes of possible changes to the condition
that caused them to go to sleep.
Typically, an awakened process will -- after it has acquired a context
again -- retry the action that blocked its operation to see if the
``blocking''
condition has cleared.
The
ltsleep()
function takes the following arguments:
ident
)
to get the process going again.
ident
should not be
NULL
.
priority
PCATCH
is OR'ed into
priority
the process checks for posted signals before and after sleeping.
If the flag
PNORELOCK
is OR'ed into
priority
,
slock
is NOT re-locked after process resume.
wmesg
p_wmesg
)
for user level utilities such as
ps(1).
timo
timo/hz
seconds.
If this amount of time elapses and no
wakeup(
ident
)
has occurred, and no signal
(if
PCATCH
was set)
was posted,
tsleep(
)
will return
EWOULDBLOCK
.
slock
slock
interlock is unlocked once the scheduler lock is acquired.
Unless
PNORELOCK
was set,
slock
is locked again once
the process is resumed from sleep.
This provides wakeup-before-sleep condition protection facility.
The
tsleep()
macro is functionally equivalent to:
ltsleep(ident, priority, wmesg, timo, NULL)
The
wakeup()
function will mark all processes which are currently sleeping on the identifier
ident
as runnable.
Eventually, each of the processes will resume execution in the kernel
context, causing a return from
tsleep().
Note that processes returning from sleep should always re-evaluate the
conditions that blocked them, since a call to
wakeup(
)
merely signals a
possible
change to the blocking conditions.
For example, when two or more processes are waiting for an exclusive-access
lock
(seelock(9)),
only one of them will succeed in acquiring the lock when it is released.
All others will have to go back to sleep and wait for the next opportunity.
)
returns 0 if it returns as a result of a
wakeup(
).
If a
ltsleep(
)
returns as a result of a signal, the return value is
ERESTART
if the signal has the
SA_RESTART
property
(seesigaction(2)),
and
EINTR
otherwise.
If
ltsleep(
)
returns because of a timeout it returns
EWOULDBLOCK
.
)
appeared in
4.4BSD.
ltsleep(
)
appeared in
NetBSD1.5.