-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.h
35 lines (29 loc) · 1.02 KB
/
queue.h
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
#ifndef QUEUE_H_
#define QUEUE_H_
#define QUEUE(TYPE) \
{ \
TYPE* first; \
TYPE* last; \
}
#define queue_init(Q) (void)((Q)->first = (Q)->last = NULL)
#define queue_is_empty(Q) (!(Q)->first)
#define queue_push(Q, ITEM, NEXT) \
(void)({ \
((ITEM)->NEXT) = NULL; \
if (queue_is_empty(Q)) \
(Q)->first = (Q)->last = (ITEM); \
else { \
(Q)->last->NEXT = (ITEM); \
(Q)->last = (ITEM); \
} \
})
#define queue_pop(Q, PITEM, NEXT) \
(void)({ \
if (queue_is_empty(Q)) \
*(PITEM) = NULL; \
else { \
*(PITEM) = (Q)->first; \
(Q)->first = (Q)->first->NEXT; \
} \
})
#endif