1 /* Taken from depthcharge: src/base/list.h */ 2 /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 4 #ifndef __COMMONLIB_LIST_H__ 5 #define __COMMONLIB_LIST_H__ 6 7 #include <commonlib/helpers.h> 8 #include <stdint.h> 9 10 struct list_node { 11 struct list_node *next; 12 struct list_node *prev; 13 }; 14 15 // Remove list_node node from the doubly linked list it's a part of. 16 void list_remove(struct list_node *node); 17 // Insert list_node node after list_node after in a doubly linked list. 18 void list_insert_after(struct list_node *node, struct list_node *after); 19 // Insert list_node node before list_node before in a doubly linked list. 20 void list_insert_before(struct list_node *node, struct list_node *before); 21 // Appends the node to the end of the list. 22 void list_append(struct list_node *node, struct list_node *head); 23 24 #define list_for_each(ptr, head, member) \ 25 for ((ptr) = container_of((head).next, typeof(*(ptr)), member); \ 26 (uintptr_t)ptr + (uintptr_t)offsetof(typeof(*(ptr)), member); \ 27 (ptr) = container_of((ptr)->member.next, \ 28 typeof(*(ptr)), member)) 29 30 #endif /* __COMMONLIB_LIST_H__ */ 31