]> git.ozlabs.org Git - ccan/commitdiff
list: new list_for_each{, _safe}_off_dir_ macros
authorEric Wong <normalperson@yhbt.net>
Fri, 24 Oct 2014 22:02:30 +0000 (22:02 +0000)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 30 Mar 2015 06:46:33 +0000 (17:16 +1030)
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 <normalperson@yhbt.net>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/list/list.h

index 983675b81f9d53877fd5d0dfaa56abc1d742a641..90989c5fc04b6bd8436361dcda42f8f5f0ce7853 100644 (file)
@@ -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)           \