]> git.ozlabs.org Git - ccan-lca-2011.git/blobdiff - ccan/list/list.h
list: rename debug_list to list_debug, use list_check_node in list_del
[ccan-lca-2011.git] / ccan / list / list.h
index 3496294b52c89acc65ac10f58398ff4e08bfe523..5b4f81c965725d473f7cfc6df52812c21fc7cfc4 100644 (file)
@@ -39,7 +39,7 @@ struct list_head
 };
 
 /**
- * list_check - check a list for consistency
+ * list_check - check head of a list for consistency
  * @h: the list_head
  * @abortstr: the location to print on aborting, or NULL.
  *
@@ -51,6 +51,8 @@ struct list_head
  * Returns the list head if the list is consistent, NULL if not (it
  * can never return NULL if @abortstr is set).
  *
+ * See also: list_check_node()
+ *
  * Example:
  *     static void dump_parent(struct parent *p)
  *     {
@@ -64,10 +66,31 @@ struct list_head
  */
 struct list_head *list_check(const struct list_head *h, const char *abortstr);
 
+/**
+ * list_check_node - check node of a list for consistency
+ * @n: the list_node
+ * @abortstr: the location to print on aborting, or NULL.
+ *
+ * Check consistency of the list node is in (it must be in one).
+ *
+ * See also: list_check()
+ *
+ * Example:
+ *     static void dump_child(const struct child *c)
+ *     {
+ *             list_check_node(&c->list, "bad child list");
+ *             printf("%s\n", c->name);
+ *     }
+ */
+struct list_node *list_check_node(const struct list_node *n,
+                                 const char *abortstr);
+
 #ifdef CCAN_LIST_DEBUG
-#define debug_list(h) list_check((h), __func__)
+#define list_debug(h) list_check((h), __func__)
+#define list_debug_node(n) list_check_node((n), __func__)
 #else
-#define debug_list(h) (h)
+#define list_debug(h) (h)
+#define list_debug_node(n) (n)
 #endif
 
 /**
@@ -118,7 +141,7 @@ static inline void list_add(struct list_head *h, struct list_node *n)
        n->prev = &h->n;
        h->n.next->prev = n;
        h->n.next = n;
-       (void)debug_list(h);
+       (void)list_debug(h);
 }
 
 /**
@@ -137,7 +160,7 @@ static inline void list_add_tail(struct list_head *h, struct list_node *n)
        n->prev = h->n.prev;
        h->n.prev->next = n;
        h->n.prev = n;
-       (void)debug_list(h);
+       (void)list_debug(h);
 }
 
 /**
@@ -150,9 +173,9 @@ static inline void list_add_tail(struct list_head *h, struct list_node *n)
  */
 static inline void list_del(struct list_node *n)
 {
+       (void)list_debug_node(n);
        n->next->prev = n->prev;
        n->prev->next = n->next;
-       (void)debug_list(n->next);
 #ifdef CCAN_LIST_DEBUG
        /* Catch use-after-del. */
        n->next = n->prev = NULL;
@@ -170,7 +193,7 @@ static inline void list_del(struct list_node *n)
  */
 static inline bool list_empty(const struct list_head *h)
 {
-       (void)debug_list(h);
+       (void)list_debug(h);
        return h->n.next == &h->n;
 }
 
@@ -233,7 +256,7 @@ static inline bool list_empty(const struct list_head *h)
  *             printf("Name: %s\n", child->name);
  */
 #define list_for_each(h, i, member)                                    \
-       for (i = container_of_var(debug_list(h)->n.next, i, member);    \
+       for (i = container_of_var(list_debug(h)->n.next, i, member);    \
             &i->member != &(h)->n;                                     \
             i = container_of_var(i->member.next, i, member))
 
@@ -256,7 +279,7 @@ static inline bool list_empty(const struct list_head *h)
  *     }
  */
 #define list_for_each_safe(h, i, nxt, member)                          \
-       for (i = container_of_var(debug_list(h)->n.next, i, member),    \
+       for (i = container_of_var(list_debug(h)->n.next, i, member),    \
                nxt = container_of_var(i->member.next, i, member);      \
             &i->member != &(h)->n;                                     \
             i = nxt, nxt = container_of_var(i->member.next, i, member))