From 0201703d51e85e5c3eeeef558176c1ed61369ad8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 24 Oct 2014 22:02:30 +0000 Subject: [PATCH 1/1] list: new list_for_each{, _safe}_off_dir_ macros These internal iteration macros will make implementing reverse iteration simpler. For now, reimplement existing list_for_each_off and list_for_each_safe_off macros on top of these macros to prove they pass existing tests. Signed-off-by: Eric Wong Reviewed-by: David Gibson Signed-off-by: Rusty Russell --- ccan/list/list.h | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/ccan/list/list.h b/ccan/list/list.h index 983675b8..90989c5f 100644 --- a/ccan/list/list.h +++ b/ccan/list/list.h @@ -653,6 +653,24 @@ static inline void list_prepend_list_(struct list_head *to, list_head_init(from); } +/* internal macros, do not use directly */ +#define list_for_each_off_dir_(h, i, off, dir) \ + for (i = list_node_to_off_(list_debug(h, LIST_LOC)->n.dir, \ + (off)); \ + list_node_from_off_((void *)i, (off)) != &(h)->n; \ + i = list_node_to_off_(list_node_from_off_((void *)i, (off))->dir, \ + (off))) + +#define list_for_each_safe_off_dir_(h, i, nxt, off, dir) \ + for (i = list_node_to_off_(list_debug(h, LIST_LOC)->n.dir, \ + (off)), \ + nxt = list_node_to_off_(list_node_from_off_(i, (off))->dir, \ + (off)); \ + list_node_from_off_(i, (off)) != &(h)->n; \ + i = nxt, \ + nxt = list_node_to_off_(list_node_from_off_(i, (off))->dir, \ + (off))) + /** * list_for_each_off - iterate through a list of memory regions. * @h: the list_head @@ -683,11 +701,7 @@ static inline void list_prepend_list_(struct list_head *to, * printf("Name: %s\n", child->name); */ #define list_for_each_off(h, i, off) \ - for (i = list_node_to_off_(list_debug(h, LIST_LOC)->n.next, \ - (off)); \ - list_node_from_off_((void *)i, (off)) != &(h)->n; \ - i = list_node_to_off_(list_node_from_off_((void *)i, (off))->next, \ - (off))) + list_for_each_off_dir_((h),(i),(off),next) /** * list_for_each_safe_off - iterate through a list of memory regions, maybe @@ -706,15 +720,7 @@ static inline void list_prepend_list_(struct list_head *to, * printf("Name: %s\n", child->name); */ #define list_for_each_safe_off(h, i, nxt, off) \ - for (i = list_node_to_off_(list_debug(h, LIST_LOC)->n.next, \ - (off)), \ - nxt = list_node_to_off_(list_node_from_off_(i, (off))->next, \ - (off)); \ - list_node_from_off_(i, (off)) != &(h)->n; \ - i = nxt, \ - nxt = list_node_to_off_(list_node_from_off_(i, (off))->next, \ - (off))) - + list_for_each_safe_off_dir_((h),(i),(nxt),(off),next) /* Other -off variants. */ #define list_entry_off(n, type, off) \ -- 2.39.2