Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libmetal: add metal_list_for_each_safe() support #251

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,29 @@ static inline struct metal_list *metal_list_first(struct metal_list *list)
return metal_list_is_empty(list) ? NULL : list->next;
}

/**
* @brief Used for iterating over a list
*
* @param list Pointer to the head node of the list
* @param node Pointer to each node in the list during iteration
*/
#define metal_list_for_each(list, node) \
for ((node) = (list)->next; \
(node) != (list); \
(node) = (node)->next)

/**
* @brief Used for iterating over a list safely
*
* @param list Pointer to the head node of the list
* @param temp Pointer to the next node's address during iteration
* @param node Pointer to each node in the list during iteration
*/
#define metal_list_for_each_safe(list, temp, node) \
for ((node) = (list)->next, (temp) = (node)->next; \
(node) != (list); \
(node) = (temp), (temp) = (node)->next)

static inline bool metal_list_find_node(struct metal_list *list,
struct metal_list *node)
{
Expand Down