Files
zinnia/kernel/include/kernel/tailq.h
T
2026-08-11 17:48:20 +02:00

53 lines
1.5 KiB
C

#pragma once
#define tailq_head(type) \
struct { \
type* tqh_first; \
type** tqh_last; \
}
#define tailq_link(type) \
struct { \
type* tqe_next; \
type** tqe_prev; \
}
#define tailq_init(head) \
do { \
(head)->tqh_first = nullptr; \
(head)->tqh_last = &(head)->tqh_first; \
} while (0)
#define tailq_first(head) ((head)->tqh_first)
#define tailq_next(elm, field) ((elm)->field.tqe_next)
#define tailq_empty(head) (tailq_first(head) == nullptr)
#define tailq_insert_tail(head, elm, field) \
do { \
(elm)->field.tqe_next = nullptr; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
} while (0)
#define tailq_insert_head(head, elm, field) \
do { \
if (((elm)->field.tqe_next = (head)->tqh_first) != nullptr) \
(head)->tqh_first->field.tqe_prev = &(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
} while (0)
#define tailq_remove(head, elm, field) \
do { \
if (((elm)->field.tqe_next) != nullptr) \
(elm)->field.tqe_next->field.tqe_prev = (elm)->field.tqe_prev; \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
} while (0)