blob: a8990354d7060b7c24e73e8347784bcfa064f863 [file] [log] [blame]
Patrick Georgiafd4c872020-05-05 23:43:18 +02001/* Taken from depthcharge: src/base/list.h */
Patrick Georgiac959032020-05-05 22:49:26 +02002/* SPDX-License-Identifier: GPL-2.0-or-later */
Patrick Rudolph67aca3e2018-04-12 11:44:43 +02003
Patrick Rudolph666c1722018-04-03 09:57:33 +02004#ifndef __LIST_H__
5#define __LIST_H__
Patrick Rudolph67aca3e2018-04-12 11:44:43 +02006
7#include <stddef.h>
8#include <stdint.h>
9
Patrick Rudolph666c1722018-04-03 09:57:33 +020010struct list_node {
11 struct list_node *next;
12 struct list_node *prev;
13};
Patrick Rudolph67aca3e2018-04-12 11:44:43 +020014
Patrick Rudolph666c1722018-04-03 09:57:33 +020015// Remove list_node node from the doubly linked list it's a part of.
16void list_remove(struct list_node *node);
17// Insert list_node node after list_node after in a doubly linked list.
18void 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.
20void list_insert_before(struct list_node *node, struct list_node *before);
Patrick Rudolph67aca3e2018-04-12 11:44:43 +020021
22#define list_for_each(ptr, head, member) \
23 for ((ptr) = container_of((head).next, typeof(*(ptr)), member); \
24 &((ptr)->member); \
25 (ptr) = container_of((ptr)->member.next, \
26 typeof(*(ptr)), member))
27
Patrick Rudolph666c1722018-04-03 09:57:33 +020028#endif /* __LIST_H__ */