Patrick Georgi | afd4c87 | 2020-05-05 23:43:18 +0200 | [diff] [blame] | 1 | /* Taken from depthcharge: src/base/list.h */ |
Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 3 | |
Patrick Rudolph | 666c172 | 2018-04-03 09:57:33 +0200 | [diff] [blame] | 4 | #ifndef __LIST_H__ |
| 5 | #define __LIST_H__ |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 6 | |
Patrick Rudolph | 666c172 | 2018-04-03 09:57:33 +0200 | [diff] [blame] | 7 | struct list_node { |
| 8 | struct list_node *next; |
| 9 | struct list_node *prev; |
| 10 | }; |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 11 | |
Patrick Rudolph | 666c172 | 2018-04-03 09:57:33 +0200 | [diff] [blame] | 12 | // Remove list_node node from the doubly linked list it's a part of. |
| 13 | void list_remove(struct list_node *node); |
| 14 | // Insert list_node node after list_node after in a doubly linked list. |
| 15 | void list_insert_after(struct list_node *node, struct list_node *after); |
| 16 | // Insert list_node node before list_node before in a doubly linked list. |
| 17 | void list_insert_before(struct list_node *node, struct list_node *before); |
Raul E Rangel | 4c8c844 | 2021-11-01 13:40:14 -0600 | [diff] [blame] | 18 | // Appends the node to the end of the list. |
| 19 | void list_append(struct list_node *node, struct list_node *head); |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 20 | |
Patrick Rudolph | 88991ca | 2020-08-19 08:40:31 +0200 | [diff] [blame] | 21 | #define list_for_each(ptr, head, member) \ |
| 22 | for ((ptr) = container_of((head).next, typeof(*(ptr)), member); \ |
| 23 | (uintptr_t)ptr + (uintptr_t)offsetof(typeof(*(ptr)), member); \ |
| 24 | (ptr) = container_of((ptr)->member.next, \ |
Patrick Rudolph | 67aca3e | 2018-04-12 11:44:43 +0200 | [diff] [blame] | 25 | typeof(*(ptr)), member)) |
| 26 | |
Patrick Rudolph | 666c172 | 2018-04-03 09:57:33 +0200 | [diff] [blame] | 27 | #endif /* __LIST_H__ */ |