/* documented in queue(9) */ #include /* struct QueueNode { * ... * struct QueueNode *name_next; * ... * } * struct QueueHead { * struct QueueNode *head, **slot; * } */ #define QUEUE_INIT(q) do { \ (q)->head = NULL; \ (q)->slot = &(q)->head; \ } while(0) #define QUEUE_APPEND(q, name, el) do { \ assert((el)->name##_next == NULL); \ assert((q)->slot != NULL); \ assert(*(q)->slot == NULL); \ *(q)->slot = (el); \ (q)->slot = &(el)->name##_next; \ } while(0) #define QUEUE_POP(q, name) ({ \ typeof((q)->head) __q_el = (q)->head; \ if (__q_el) { \ (q)->head = __q_el->name##_next; \ __q_el->name##_next = NULL; \ if ((q)->slot == &__q_el->name##_next) { \ (q)->slot = &(q)->head; \ } \ } \ __q_el; \ })