/* 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*/