~kris/9p

9hist

ref: d3fd7b40dbba842df4e540b303f9dcc647671437 9hist/pc/cycintr.c -rw-r--r-- 1.2 KiB
d3fd7b40 — David du Colombier Plan 9 from Bell Labs 2000-07-27 26 years ago
                                                                                
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"


static struct
{
	Lock;
	Cycintr	*ci;
}cycintrs;

/*
 * called by clockintrsched()
 */
vlong
cycintrnext(void)
{
	Cycintr *ci;
	vlong when;

	ilock(&cycintrs);
	when = 0;
	ci = cycintrs.ci;
	if(ci != nil)
		when = ci->when;
	iunlock(&cycintrs);
	return when;
}

vlong
checkcycintr(Ureg *u, void*)
{
	Cycintr *ci;
	vlong when;

	ilock(&cycintrs);
	while(ci = cycintrs.ci){
		when = ci->when;
		if(when > fastticks(nil)){
			iunlock(&cycintrs);
			return when;
		}
		cycintrs.ci = ci->next;
		iunlock(&cycintrs);
		(*ci->f)(u, ci);
		ilock(&cycintrs);
	}
	iunlock(&cycintrs);
	return 0;
}

void
cycintradd(Cycintr *nci)
{
	Cycintr *ci, **last;

	ilock(&cycintrs);
	last = &cycintrs.ci;
	while(ci = *last){
		if(ci == nci){
			*last = ci->next;
			break;
		}
		last = &ci->next;
	}

	last = &cycintrs.ci;
	while(ci = *last){
		if(ci->when > nci->when)
			break;
		last = &ci->next;
	}
	nci->next = *last;
	*last = nci;
	iunlock(&cycintrs);
}

void
cycintrdel(Cycintr *dci)
{
	Cycintr *ci, **last;

	ilock(&cycintrs);
	last = &cycintrs.ci;
	while(ci = *last){
		if(ci == dci){
			*last = ci->next;
			break;
		}
		last = &ci->next;
	}
	iunlock(&cycintrs);
}