basic/list: add LIST_JOIN helper

Joins together two lists, tail to head.

a -> b
c -> d

a -> b -> c -> d
This commit is contained in:
Luca Boccassi
2020-07-29 17:12:45 +01:00
parent 6b222c4b02
commit 5511d8c1b9
2 changed files with 62 additions and 0 deletions
+15
View File
@@ -169,3 +169,18 @@
#define LIST_IS_EMPTY(head) \
(!(head))
/* Join two lists tail to head: a->b, c->d to a->b->c->d and de-initialise second list */
#define LIST_JOIN(name,a,b) \
do { \
assert(b); \
if (!(a)) \
(a) = (b); \
else { \
typeof(*(a)) *_head = (b), *_tail; \
LIST_FIND_TAIL(name, (a), _tail); \
_tail->name##_next = _head; \
_head->name##_prev = _tail; \
} \
(b) = NULL; \
} while (false)