18#include <kernel/types.h>
20#include <utils/container_of.h>
21#include <utils/compiler.h>
48#define __LLIST_INIT(_head) \
54#define LLIST_INIT(_list) ((llist_t)__LLIST_INIT(&(_list).head))
57#define __INIT_LLIST(_name) _name = __LLIST_INIT(_name)
58#define INIT_LLIST(_name) _name = LLIST_INIT(_name)
61#define DECLARE_LLIST(_name) llist_t INIT_LLIST(_name)
64#define LLIST_NODE(_name) node_t _name
71#define FOREACH_LLIST(_name, _list) \
72 for (node_t *_name = llist_first(_list); _name != llist_head(_list); \
73 _name = llist_next(_name))
84#define FOREACH_LLIST_SAFE(_name, _tmp, _list) \
85 for (node_t *_name = llist_first(_list), *_tmp = llist_next(_name); \
86 _name != llist_head(_list); _name = _tmp, _tmp = llist_next(_tmp))
93#define FOREACH_LLIST_REVERSE(_name, _list) \
94 for (node_t *_name = llist_last(_list); _name != llist_head(_list); \
95 _name = llist_prev(_name))
106#define FOREACH_LLIST_SAFE_REVERSE(_name, _tmp, _list) \
107 for (node_t *_name = llist_last(_list), *_tmp = llist_prev(_name); \
108 _name != llist_head(_list); _name = _tmp, _tmp = llist_prev(_tmp))
116#define FOREACH_LLIST_ENTRY(_entry, _list, _field) \
117 for (_entry = llist_entry(llist_first(_list), typeof(*_entry), _field); \
118 &_entry->_field != llist_head(_list); \
119 _entry = llist_entry(llist_next(&_entry->_field), typeof(*_entry), \
129#define FOREACH_LLIST_ENTRY_SAFE(_entry, _tmp, _list, _field) \
130 for (_entry = llist_entry(llist_first(_list), typeof(*_entry), _field), \
132 llist_entry(llist_next(&_entry->_field), typeof(*_tmp), _field); \
133 &_entry->_field != llist_head(_list); \
134 _entry = _tmp, _tmp = llist_entry(llist_next(&_tmp->_field), \
135 typeof(*_entry), _field))
143#define FOREACH_LLIST_ENTRY_REVERSE(_entry, _list, _field) \
144 for (_entry = llist_entry(llist_last(_list), typeof(*_entry), _field); \
145 &_entry->_field != llist_head(_list); \
146 _entry = llist_entry(llist_prev(&_entry->_field), typeof(*_entry), \
156#define FOREACH_LLIST_ENTRY_REVERSE_SAFE(_entry, _tmp, _list, _field) \
157 for (_entry = llist_entry(llist_last(_list), typeof(*_entry), _field), \
159 llist_entry(llist_prev(&_entry->_field), typeof(*_tmp), _field); \
160 &_entry->_field != llist_head(_list); \
161 _entry = _tmp, _tmp = llist_entry(llist_prev(&_tmp->_field), \
162 typeof(*_entry), _field))
165#define llist_head(_list) (&(_list)->head)
194#define llist_entry(ptr, type, member) container_of(ptr, type, member)
312 if (compare(
new, node) <= 0)
314 node = llist_next(node);
338 ret = compare(
new, node);
343 node = llist_next(node);
364 if (!compare(node, data))
static node_t * llist_first(const llist_t *list)
Definition: linked_list.h:168
static void llist_add_tail(llist_t *list, node_t *new)
Insert a new entry as the last element of the list.
Definition: linked_list.h:257
struct linked_list_node * next
Next item in the list.
Definition: linked_list.h:28
static node_t * llist_find_first(const llist_t *list, const void *data, compare_t compare)
Retreive the first matching element inside the list (or NULL)
Definition: linked_list.h:361
static node_t * llist_pop_tail(llist_t *list)
Pop the last element in a list.
Definition: linked_list.h:291
static node_t * llist_last(const llist_t *list)
Definition: linked_list.h:174
#define llist_head(_list)
Definition: linked_list.h:165
#define FOREACH_LLIST(_name, _list)
Loop over each element inside a linked list.
Definition: linked_list.h:71
static void llist_add_before(node_t *next, node_t *new)
Insert a new entry into a list.
Definition: linked_list.h:237
static void llist_insert_sorted(llist_t *list, node_t *new, compare_t compare)
Insert a new item inside a sorted list in ascending order.
Definition: linked_list.h:307
static void llist_add_after(node_t *prev, node_t *new)
Insert a new entry into a list.
Definition: linked_list.h:227
static node_t * llist_remove(node_t *node)
Remove an entry from a list.
Definition: linked_list.h:267
static void __list_remove(node_t *prev, node_t *next)
Delete a list entry (internal use only).
Definition: linked_list.h:216
struct linked_list_node * prev
Previous item in the list.
Definition: linked_list.h:29
static PURE bool llist_is_empty(const llist_t *list)
Definition: linked_list.h:197
static node_t * llist_pop(llist_t *list)
Pop the first element in a list.
Definition: linked_list.h:278
static void __llist_add(node_t *new, node_t *prev, node_t *next)
Insert a new entry between two known consecutive ones (internal use only)
Definition: linked_list.h:203
static bool llist_insert_sorted_unique(llist_t *list, node_t *new, compare_t compare)
Insert a new item inside a sorted list in ascending order.
Definition: linked_list.h:332
static void llist_add(llist_t *list, node_t *new)
Insert a new entry as the first element of the list.
Definition: linked_list.h:247
The head of a doubly linked list.
Definition: linked_list.h:43
Intrusive doubly-linked list node.
Definition: linked_list.h:27