void sleep(Rendezvous *r, int (*condition)(void*), void *arg)
void wakeup(Rendezvous *r).
typedef struct{ Lock l; Proc *p; }Rendezvous;
void sleep(Rendezvous *r, int (*condition)(void*), void *arg) { int s; s = inhibit(); /* interrupts */ lock(&r->l); /* * if condition happened, never mind */ if((*condition)(arg)){ unlock(&r->l); allow(); /* interrupts */ return; } /* * now we are committed to * change state and call scheduler */ if(r->p) error("double sleep %d %d", r->p->pid, thisp->pid); thisp->state = Wakeme; r->p = thisp; unlock(&r->l); allow(s); /* interrupts */ sched(); /* relinquish CPU */ }
void wakeup(Rendezvous *r) { Proc *p; int s; s = inhibit(); /* interrupts; return old state */ lock(&r->l); p = r->p; if(p){ r->p = 0; if(p->state != Wakeme) panic("wakeup: not Wakeme"); ready(p); } unlock(&r->l); if(s) allow(); }
void wakeup(Rendezvous *r) { Proc *p; int s; p = r->p; if(p){ s = inhibit(); lock(&r->l); r->p = 0; if(p->state != Wakeme) panic("wakeup: not Wakeme"); ready(p); unlock(&r->l); if(s) allow(); } }