Continue fighting pthreads.
Clean up thread library a bit too.
This commit is contained in:
parent
c6687d4591
commit
7966faa931
19 changed files with 539 additions and 654 deletions
38
src/libthread/sleep.c
Normal file
38
src/libthread/sleep.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include "threadimpl.h"
|
||||
|
||||
int _threadhighnrendez;
|
||||
int _threadnrendez;
|
||||
|
||||
void
|
||||
_threadsleep(_Procrend *r)
|
||||
{
|
||||
Thread *t;
|
||||
|
||||
t = _threadgetproc()->thread;
|
||||
r->arg = t;
|
||||
t->nextstate = Rendezvous;
|
||||
t->asleep = 1;
|
||||
unlock(r->l);
|
||||
_sched();
|
||||
t->asleep = 0;
|
||||
lock(r->l);
|
||||
}
|
||||
|
||||
void
|
||||
_threadwakeup(_Procrend *r)
|
||||
{
|
||||
Thread *t;
|
||||
|
||||
t = r->arg;
|
||||
while(t->state == Running)
|
||||
sleep(0);
|
||||
lock(&t->proc->lock);
|
||||
if(t->state == Dead){
|
||||
unlock(&t->proc->lock);
|
||||
return;
|
||||
}
|
||||
assert(t->state == Rendezvous && t->asleep);
|
||||
t->state = Ready;
|
||||
_threadready(t);
|
||||
unlock(&t->proc->lock);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue