blob: 7349b9a1b44f60cc007f1c8bb1e57edd902483b1 (
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
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
 | /*
** Copyright 2001 Double Precision, Inc.  See COPYING for
** distribution information.
*/
#include "config.h"
#include "pcpdtimer.h"
#include <string.h>
#include <time.h>
extern struct pcpdtimer *first_timer, *last_timer;
struct pcpdtimer *first_timer=NULL, *last_timer=NULL;
void pcpdtimer_install(struct pcpdtimer *p, time_t nseconds)
{
	struct pcpdtimer *q;
	if (p->alarm)
	{
		if (p->prev)
			p->prev->next=p->next;
		else
			first_timer=p->next;
		if (p->next)
			p->next->prev=p->prev;
		else
			last_timer=p->prev;
	}
	time(&p->alarm);
	p->alarm += nseconds;
	for (q=first_timer; q; q=q->next)
	{
		if (q->alarm > p->alarm)
			break;
	}
	if (!q)
	{
		if ((p->prev=last_timer) != 0)
			p->prev->next=p;
		else
			first_timer=p;
		p->next=0;
		last_timer=p;
	}
	else
	{
		if ((p->prev=q->prev) != 0)
			p->prev->next=p;
		else
			first_timer=p;
		p->next=q;
		q->prev=p;
	}
}
void pcpdtimer_triggered(struct pcpdtimer *p)
{
	if (!p->alarm)
		return;
	if (p->prev)
		p->prev->next=p->next;
	else
		first_timer=p->next;
	if (p->next)
		p->next->prev=p->prev;
	else
		last_timer=p->prev;
	p->alarm=0;
}
 |