void wakeup(Rendez *r)
void tsleep(Rendez *r, int (*f)(void*), void *arg, int ms)
int return0(void *arg)
The caller of sleep and a caller of wakeup share a Rendez structure, to provide a rendezvous point between them to synchronise on an event. Sleep uses a condition function f that returns true if the event has occurred.
Sleep evaluates f(arg). If true, the event has happened and sleep returns immediately. Otherwise, sleep blocks on the event variable r, awaiting wakeup.
Wakeup is called by either a process or an interrupt handler to wake any process sleeping at r, signifying that the corresponding condition is true (the event has occurred). It has no effect if there is no sleeping process.
Tsleep is similar to sleep, except that if the condition f(arg) is false and the caller does sleep, and nothing else wakes it within ms millliseconds, the system will wake it. Tsleep's caller must check its environment to decide whether timeout or the event occurred. The timing provided by tsleep is imprecise, but adequate in practice for the normal use of protecting against lost interrupts and otherwise unresponsive devices or software.
Return0 ignores its arguments and returns zero. It is commonly used as the predicate f in a call to tsleep to obtain a time delay, using a Rendez variable sleep in the Proc structure, for example:
Both sleep and tsleep can be interrupted by swiproc (see kproc(10.2)), causing a non-local goto through a call to error(10.2).
SLEEP(10.2 ) | Rev: Thu Feb 15 14:42:59 GMT 2007 |