aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/rendez.c
blob: 4451fa4d3c570102bc6f940d011a133f7f06a46c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "threadimpl.h"

int _threadhighnrendez;
int _threadnrendez;

void
_threadsleep(_Procrend *r)
{
	Thread *t;

	t = _threadgetproc()->thread;
	r->arg = t;
	t->nextstate = Rendezvous;
	t->inrendez = 1;
	unlock(r->l);
	_sched();
	t->inrendez = 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->inrendez);
	t->state = Ready;
	_threadready(t);
	unlock(&t->proc->lock);
}