diff options
Diffstat (limited to 'libqueue/queue/tq.h')
| -rw-r--r-- | libqueue/queue/tq.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/libqueue/queue/tq.h b/libqueue/queue/tq.h new file mode 100644 index 0000000..cf3ff46 --- /dev/null +++ b/libqueue/queue/tq.h @@ -0,0 +1,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*/ |
