plan9port/src/libthread/sleep.c

40 lines
560 B
C
Raw Normal View History

2003-09-30 17:47:42 +00:00
#include "threadimpl.h"
int _threadhighnrendez;
int _threadnrendez;
void
_threadsleep(_Procrend *r)
2003-09-30 17:47:42 +00:00
{
Thread *t;
2003-09-30 17:47:42 +00:00
t = _threadgetproc()->thread;
r->arg = t;
t->nextstate = Rendezvous;
t->asleep = 1;
unlock(r->l);
2003-09-30 17:47:42 +00:00
_sched();
t->asleep = 0;
lock(r->l);
2003-09-30 17:47:42 +00:00
}
void
_threadwakeup(_Procrend *r)
2003-09-30 17:47:42 +00:00
{
Thread *t;
2003-09-30 17:47:42 +00:00
t = r->arg;
while(t->state == Running)
sleep(0);
lock(&t->proc->lock);
if(t->state == Dead){
unlock(&t->proc->lock);
2003-09-30 17:47:42 +00:00
return;
}
assert(t->state == Rendezvous && t->asleep);
t->state = Ready;
_threadready(t);
unlock(&t->proc->lock);
2003-09-30 17:47:42 +00:00
}
2004-11-08 16:03:20 +00:00