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
|
/* vim: set ts=4 sw=4 ai:
* tq.h -- tailq implementation derived from NetBSD's queue.h
*/
#ifndef TQ_H
#define TQ_H
struct tqe {
void *data;
struct tqe *next;
struct tqe **pprev;
};
struct tqh {
struct tqe *first;
struct tqe **last;
};
#define tq_first(hd) ((hd)->first)
#define tq_last(hd) (*(((struct tqh *)(void *)((hd)->last))->last))
#define tq_next(e) ((e)->next)
#define tq_prev(e) (*(((struct tqh *)(void *)((e)->pprev))->last))
#define tq_empty(hd) (((hd)->first) == NULL)
#define tq_init(hd) do { \
(hd)->first = NULL; \
(hd)->last = &(hd)->first; \
} while (0)
#define tq_foreach(var,head) \
for ((var) = ((head)->first); \
(var) != NULL; \
(var) = ((var)->next))
#define tq_foreach_safe(var,head,vnext) \
for ((var) = ((head)->first); \
(var) != NULL && ((vnext) = tq_next((var)), 1); \
(var) = (vnext))
#define tq_foreach_reverse(var,head) \
for ((var) = tq_last((head)); \
(var) != NULL; \
(var) = tq_prev((var)))
#define tq_foreach_reverse_safe(var,head,vprev) \
for ((var) = tq_last((head)); \
(var) != NULL && ((vprev) = tq_prev((var)),1); \
(var) = (vprev))
struct tqh *tq_new(void);
struct tqe *tq_elem_new(void *);
void tq_insert_head(struct tqh *, struct tqe *);
void tq_insert_tail(struct tqh *, struct tqe *);
void tq_insert_after(struct tqh *, struct tqe *, struct tqe *);
void tq_insert_before(struct tqh *, struct tqe *, struct tqe *);
void tq_remove(struct tqh *, struct tqe *);
void tq_replace(struct tqh *, struct tqe *, struct tqe *);
void tq_concat(struct tqh *, struct tqh *);
void tq_cleanup(struct tqh *, void (*)(void *));
struct tqe *tq_find_from_data(struct tqh *, const void *, int (*)(const void *, const void *));
#endif/*!TQ_H*/
|