-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.c
56 lines (50 loc) · 962 Bytes
/
select.c
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
46
47
48
49
50
51
52
53
54
55
56
#include "types.h"
#include "param.h"
#include "select.h"
#include "spinlock.h"
#include "defs.h"
extern void wakeup(void *);
void initselproc(struct selproc * s)
{
s->selcount = 0;
for (int i=0; i<NSELPROC; i++)
{
s->sel[i] = 0;
}
}
void clearselid(struct selproc *s, int * selid)
{
for (int i=0; i<NSELPROC; i++)
{
if (s->sel[i] == selid)
{
s->sel[i] = 0;
s->selcount--;
}
}
}
void addselid(struct selproc *s, int * selid, struct spinlock * lk)
{
for (int i=0; i<NSELPROC; i++)
{
if (s->sel[i] == 0)
{
s->sel[i] = selid;
s->lk[i] = lk;
s->selcount++;
break;
}
}
}
void wakeupselect(struct selproc * s)
{
for (int i=0; i<NSELPROC; i++)
{
if (s->sel[i])
{
acquire(s->lk[i]);
wakeup((void*)s->sel[i]);
release(s->lk[i]);
}
}
}