-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.c
59 lines (50 loc) · 978 Bytes
/
queue.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
57
58
59
//
// queue.c
//
// Variables for queues, and a routine to initialize the pool of links.
//
//
#include "dlxos.h"
#include "queue.h"
Queue freeLinks;
static Link linkpool[QUEUE_MAX_LINKS];
void
QueueModuleInit ()
{
int i;
QueueInit (&freeLinks);
for (i = 0; i < QUEUE_MAX_LINKS; i++) {
dbprintf ('i', "Initializing queue link %d.\n", i);
linkpool[i].next = NULL;
QueueFreeLink (&(linkpool[i]));
}
}
void
QueueInit (Queue *q)
{
q->first = (Link *)q;
q->last = (Link *)q;
q->nitems = 0;
}
void
QueueFreeLink (Link *l)
{
extern Queue freeLinks;
// Make sure the link has already been freed!
ASSERT ((l->next == NULL), "Link not empty");
QueueInsertLast (&freeLinks, l);
}
Link *
QueueAllocLink ()
{
extern Queue freeLinks;
Link *l;
if (! QueueEmpty (&freeLinks)) {
l = QueueFirst (&freeLinks);
QueueRemove (l);
} else {
l = NULL;
}
ASSERT ((l != NULL), "Link not allocated!");
return (l);
}