mirror of
https://github.com/CTCaer/hekate
synced 2024-12-22 03:11:16 +00:00
bdk: list: add LIST_FOREACH_INVERSE and LIST_FOREACH_ENTRY_INVERSE
This commit is contained in:
parent
2378bf2863
commit
50886382bf
1 changed files with 9 additions and 0 deletions
|
@ -30,6 +30,10 @@
|
|||
#define LIST_FOREACH(iter, list) \
|
||||
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. */
|
||||
#define LIST_FOREACH_SAFE(iter, list) \
|
||||
for(link_t *iter = (list)->next, *safe = iter->next; iter != (list); iter = safe, safe = iter->next)
|
||||
|
@ -39,6 +43,11 @@
|
|||
if ((list)->next != (list)) \
|
||||
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
|
||||
{
|
||||
struct _link_t *prev;
|
||||
|
|
Loading…
Reference in a new issue