You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
C
47 lines
1.3 KiB
C
#pragma once
|
|
|
|
#include "typecheck.h"
|
|
|
|
struct intrusive_list {
|
|
struct intrusive_list *next;
|
|
struct intrusive_list *prev;
|
|
};
|
|
|
|
static inline void intrusive_list_init_empty(struct intrusive_list *head) {
|
|
head->next = head;
|
|
head->prev = head;
|
|
}
|
|
|
|
static inline void intrusive_list_del(struct intrusive_list *node) {
|
|
struct intrusive_list old_node;
|
|
|
|
old_node = *node;
|
|
node->prev->next = old_node.next;
|
|
node->next->prev = old_node.prev;
|
|
}
|
|
|
|
static inline void intrusive_list_add(
|
|
struct intrusive_list *add_after,
|
|
struct intrusive_list *new_node)
|
|
{
|
|
new_node->prev = add_after;
|
|
new_node->next = add_after->next;
|
|
new_node->prev->next = new_node;
|
|
new_node->next->prev = new_node;
|
|
}
|
|
|
|
#define INTRUSIVE_LIST_FOR_EACH(ITER, NEXT, HEAD) \
|
|
for ( \
|
|
CHECK_TYPE(struct intrusive_list *, HEAD), \
|
|
(ITER) = (HEAD)->next, \
|
|
(NEXT) = (ITER)->next; \
|
|
(ITER) != (HEAD); \
|
|
(ITER) = (NEXT), (NEXT) = (ITER)->next)
|
|
|
|
#define INTRUSIVE_LIST_FOR_EACH_NO_REMOVE(ITER, HEAD) \
|
|
for ( \
|
|
CHECK_TYPE(struct intrusive_list *, HEAD), \
|
|
(ITER) = (HEAD)->next; \
|
|
(ITER) != (HEAD); \
|
|
(ITER) = (ITER)->next)
|