summaryrefslogtreecommitdiff
path: root/lib/libtask/rendez.c
blob: d27fde7afbf6b3ff722dda62beab4e028df7c875 (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
39
40
41
42
43
44
45
#include "taskimpl.h"

/*
 * sleep and wakeup
 */
void
tasksleep(Rendez *r)
{
	addtask(&r->waiting, taskrunning);
	if(r->l)
		qunlock(r->l);
	taskstate("sleep");
	taskswitch();
	if(r->l)
		qlock(r->l);
}

static int
_taskwakeup(Rendez *r, int all)
{
	int i;
	Task *t;

	for(i=0;; i++){
		if(i==1 && !all)
			break;
		if((t = r->waiting.head) == nil)
			break;
		deltask(&r->waiting, t);
		taskready(t);
	}
	return i;
}

int
taskwakeup(Rendez *r)
{
	return _taskwakeup(r, 0);
}

int
taskwakeupall(Rendez *r)
{
	return _taskwakeup(r, 1);
}