diff options
| author | John Vogel <jvogel4@stny.rr.com> | 2024-07-07 12:06:29 -0400 |
|---|---|---|
| committer | John Vogel <jvogel4@stny.rr.com> | 2024-07-07 12:06:29 -0400 |
| commit | e641fea471c85d267a22ac9ee431d07e4a5c8701 (patch) | |
| tree | 7704a7c5fc3a51dd646352aae435ff087ba0a431 /libqueue/queue/stq.h | |
| parent | fa77c0dd7f3ce3f69c405ae9535941ffeff478ae (diff) | |
| download | my-aports-e641fea471c85d267a22ac9ee431d07e4a5c8701.tar.gz | |
local/libqueue: new aport
Diffstat (limited to 'libqueue/queue/stq.h')
| -rw-r--r-- | libqueue/queue/stq.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libqueue/queue/stq.h b/libqueue/queue/stq.h new file mode 100644 index 0000000..dcf5c85 --- /dev/null +++ b/libqueue/queue/stq.h @@ -0,0 +1,49 @@ +/* vim: set ts=4 sw=4 ai: + * stq.h -- singly linked tail queue implementation derived from NetBSD's queue.h + */ + +#ifndef STQ_H +#define STQ_H + +struct stqe { + void *data; + struct stqe *next; +}; + +struct stqh { + struct stqe *first; + struct stqe **last; +}; + +#define stq_first(hd) ((hd)->first) +#define stq_last(hd) (*(((struct stqh *)(void *)((hd)->last))->last)) +#define stq_next(e) ((e)->next) +#define stq_empty(hd) (((hd)->first) == NULL) +#define stq_init(hd) do { \ + (hd)->first = NULL; \ + (hd)->last = &(hd)->first; \ +} while (0) + + +#define stq_foreach(var,head) \ + for ((var) = stq_first((head)); \ + (var); \ + (var) = stq_next((var))) + +#define stq_foreach_safe(var,head,vnext) \ + for ((var) = stq_first((head)); \ + (var) && ((vnext) = stq_next((var)),1); \ + (var) = (vnext)) + +struct stqh *stq_new(void); +struct stqe *stq_elem_new(void *); +void stq_insert_head(struct stqh *, struct stqe *); +void stq_insert_tail(struct stqh *, struct stqe *); +void stq_insert_after(struct stqh *, struct stqe *, struct stqe *); +void stq_remove_head(struct stqh *); +void stq_remove(struct stqh *, struct stqe *); +void stq_concat(struct stqh *, struct stqh *); +void stq_cleanup(struct stqh *, void (*)(void *)); +struct stqe *stq_find_from_data(struct stqh *, const void *, int (*)(const void *, const void *)); + +#endif/*!STQ_H*/ |
