Chris Lattner | 633a5b1 | 2002-09-17 23:03:30 +0000 | [diff] [blame] | 1 | char rcsid_queue[] = "$Id$"; |
2 | |||||
3 | #include "b.h" | ||||
4 | #include <stdio.h> | ||||
5 | |||||
6 | Queue globalQ; | ||||
7 | |||||
8 | Queue | ||||
9 | newQ() | ||||
10 | { | ||||
11 | Queue q; | ||||
12 | |||||
13 | q = (Queue) zalloc(sizeof(struct queue)); | ||||
14 | assert(q); | ||||
15 | q->head = 0; | ||||
16 | q->tail = 0; | ||||
17 | |||||
18 | return q; | ||||
19 | } | ||||
20 | |||||
21 | void | ||||
22 | addQ(q, ts) Queue q; Item_Set ts; | ||||
23 | { | ||||
24 | List qe; | ||||
25 | |||||
26 | assert(q); | ||||
27 | assert(ts); | ||||
28 | |||||
29 | qe = newList(ts, 0); | ||||
30 | if (q->head) { | ||||
31 | assert(q->tail); | ||||
32 | q->tail->next = qe; | ||||
33 | q->tail = qe; | ||||
34 | } else { | ||||
35 | q->head = q->tail = qe; | ||||
36 | } | ||||
37 | } | ||||
38 | |||||
39 | Item_Set | ||||
40 | popQ(q) Queue q; | ||||
41 | { | ||||
42 | List qe; | ||||
43 | Item_Set ts; | ||||
44 | |||||
45 | assert(q); | ||||
46 | |||||
47 | if (q->head) { | ||||
48 | qe = q->head; | ||||
49 | q->head = q->head->next; | ||||
50 | ts = (Item_Set) qe->x; | ||||
51 | zfree(qe); | ||||
52 | return ts; | ||||
53 | } else { | ||||
54 | return 0; | ||||
55 | } | ||||
56 | } | ||||
57 | |||||
58 | void | ||||
59 | dumpQ(q) Queue q; | ||||
60 | { | ||||
61 | printf("Begin Queue\n"); | ||||
62 | foreachList((ListFn)dumpItem_Set, q->head); | ||||
63 | printf("End Queue\n"); | ||||
64 | } |