aboutsummaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2021-12-16 11:25:32 +0100
committerAntonio Borneo <borneo.antonio@gmail.com>2022-02-14 15:10:41 +0000
commita11fe473eaee235a51dba7900c08cc7629ed2794 (patch)
tree8fd8a5e4bbbc440db9d4935d38238c96367bf05b /src/helper
parent16cc853bcfbcc8dba6eadd91b434c05387034c0a (diff)
downloadriscv-openocd-a11fe473eaee235a51dba7900c08cc7629ed2794.zip
riscv-openocd-a11fe473eaee235a51dba7900c08cc7629ed2794.tar.gz
riscv-openocd-a11fe473eaee235a51dba7900c08cc7629ed2794.tar.bz2
helper/list: add list_for_each_entry_direction()
Use a bool flag to specify if the list should be forward or backward iterated. Change-Id: Ied19d049f46cdcb7f50137d459cc7c02014526bc Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6784 Tested-by: jenkins
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/list.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/helper/list.h b/src/helper/list.h
index a7cd4ad..552a320 100644
--- a/src/helper/list.h
+++ b/src/helper/list.h
@@ -657,6 +657,20 @@ static inline void list_splice_tail_init(struct list_head *list,
pos = list_prev_entry(pos, member))
/**
+ * list_for_each_entry_direction - iterate forward/backward over list of given type
+ * @param forward the iterate direction, true for forward, false for backward.
+ * @param pos the type * to use as a loop cursor.
+ * @param head the head for your list.
+ * @param member the name of the list_head within the struct.
+ */
+#define list_for_each_entry_direction(forward, pos, head, member) \
+ for (pos = forward ? list_first_entry(head, typeof(*pos), member) \
+ : list_last_entry(head, typeof(*pos), member); \
+ !list_entry_is_head(pos, head, member); \
+ pos = forward ? list_next_entry(pos, member) \
+ : list_prev_entry(pos, member))
+
+/**
* list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
* @param pos the type * to use as a start point
* @param head the head of the list