*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->NetBSD man pages -> wakeup (9)              



NAME    [Toc]    [Back]

     ltsleep, sleep, tsleep, wakeup - process context sleep and and wakeup

SYNOPSIS    [Toc]    [Back]

     #include <sys/proc.h>

     ltsleep(void *ident, int priority, const char *wmesg, int timo,
             __volatile struct simplelock *slock);

     tsleep(void *ident, int priority, const char *wmesg, int timo);

     sleep(void *ident, int priority);

     wakeup(void *ident);

DESCRIPTION    [Toc]    [Back]

     These functions implement voluntary context switching.  ltsleep(),
     tsleep() and sleep() are used throughout the kernel whenever processing
     in the current context can not continue for any of the following reasons:

           +o   The current process needs to await the results of a pending I/O

           +o   The current process needs resources (e.g. memory) which are
               temporarily unavailable.

           +o   The current process wants access to data-structures which are
               locked by other processes.

     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     An identifier of the ``wait channel'' representing the resource
               for which the current process needs to wait.  This typically is
               the virtual address of some kernel data-structure related to
               the resource for which the process is contending.  The same
               identifier must be used in a call to wakeup() to get the process
 going again.  ident should not be NULL.

     priority  The process priority to be used when the process is awakened
               and put on the queue of runnable processes.  This mechanism is
               used to optimize ``throughput'' of processes executing in kernel
 mode.  If the flag 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 relocked
 after process resume.

     wmesg     A pointer to a character string indicating the reason a process
               is sleeping.  The kernel does not use the string, but makes it
               available (through the process structure field p_wmesg) for
               user level utilities such as ps(1).

     timo      If non-zero, the process will sleep for at most 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     If not NULL, the 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 sleep() function puts the process in an uninterruptible sleep.  It is
     functionally equivalent to:

           ltsleep(ident, priority  PRIMASK, 0, 0, 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
     [t]sleep().  Note that processes returning from sleep should always reevaluate
 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
     (see lock(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.

RETURN VALUES    [Toc]    [Back]

     ltsleep() 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 (see sigaction(2)), and EINTR
     otherwise.  If ltsleep() returns because of a timeout it returns

SEE ALSO    [Toc]    [Back]

     sigaction(2), hz(9), lock(9)

HISTORY    [Toc]    [Back]

     The sleep/wakeup process synchronization mechanism is very old.  It
     appeared in a very early version of Unix.  tsleep() appeared in 4.4BSD.
     ltsleep() appeared in NetBSD 1.5.

BSD                              June 23, 1996                             BSD
[ Back ]
 Similar pages
Name OS Title
wakeup OpenBSD process context sleep and wakeup
tsleep OpenBSD process context sleep and wakeup
sleep OpenBSD process context sleep and wakeup
sleep Tru64 General: Puts a calling process to sleep
ctxsw NetBSD switch to another process context
ctxsw OpenBSD switch to another process context
cpu_switch OpenBSD switch to another process context
mi_switch OpenBSD switch to another process context
mi_switch NetBSD switch to another process context
cpu_switch NetBSD switch to another process context
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service