1
0
Fork 0
mirror of https://github.com/CTCaer/hekate.git synced 2024-11-13 22:06:46 +00:00

bdk: list: add LIST_FOREACH_INVERSE and LIST_FOREACH_ENTRY_INVERSE

This commit is contained in:
CTCaer 2022-06-25 05:59:53 +03:00
parent 2378bf2863
commit 50886382bf

View file

@ -30,6 +30,10 @@
#define LIST_FOREACH(iter, list) \ #define LIST_FOREACH(iter, list) \
for(link_t *iter = (list)->next; iter != (list); iter = iter->next) for(link_t *iter = (list)->next; iter != (list); iter = iter->next)
/*! Iterate over all list links backwards. */
#define LIST_FOREACH_INVERSE(iter, list) \
for(link_t *iter = (list)->prev; iter != (list); iter = iter->prev)
/*! Safely iterate over all list links. */ /*! Safely iterate over all list links. */
#define LIST_FOREACH_SAFE(iter, list) \ #define LIST_FOREACH_SAFE(iter, list) \
for(link_t *iter = (list)->next, *safe = iter->next; iter != (list); iter = safe, safe = iter->next) for(link_t *iter = (list)->next, *safe = iter->next; iter != (list); iter = safe, safe = iter->next)
@ -39,6 +43,11 @@
if ((list)->next != (list)) \ if ((list)->next != (list)) \
for(etype *iter = CONTAINER_OF((list)->next, etype, mn); &iter->mn != (list); iter = CONTAINER_OF(iter->mn.next, etype, mn)) for(etype *iter = CONTAINER_OF((list)->next, etype, mn); &iter->mn != (list); iter = CONTAINER_OF(iter->mn.next, etype, mn))
/* Iterate over all list members backwards and make sure that the list has at least one entry. */
#define LIST_FOREACH_ENTRY_INVERSE(type, iter, list, mn) \
if ((list)->prev != (list)) \
for(type *iter = CONTAINER_OF((list)->prev, type, mn); &iter->mn != (list); iter = CONTAINER_OF(iter->mn.prev, type, mn))
typedef struct _link_t typedef struct _link_t
{ {
struct _link_t *prev; struct _link_t *prev;