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.
51 lines
1.6 KiB
C
51 lines
1.6 KiB
C
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
#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 ( \
|
|
(void)TLSL_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 ( \
|
|
(void)TLSL_CHECK_TYPE(struct intrusive_list *, HEAD), \
|
|
(ITER) = (HEAD)->next; \
|
|
(ITER) != (HEAD); \
|
|
(ITER) = (ITER)->next)
|