summaryrefslogtreecommitdiff
path: root/ccan
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-13 23:49:15 (GMT)
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-13 23:49:15 (GMT)
commitc975dc96b7e81d709f6ec71b539db06794a949cc (patch)
treeb2bbac72c52e00cfdceee0b6a34c3c33e6078cca /ccan
parentf3c9ffe094ff8d57d040b9599556082664548838 (diff)
ccan/list: new list_{del,node}_init functions
* ccan/list/list.h (list_del_init, list_node_init): new functions for multiple list_del() calls [ccan ec8654d94d3c5c47aa5f82698f7e8048c79765b1] (Rusty Russell) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ccan')
-rw-r--r--ccan/list/list.h35
1 files changed, 34 insertions, 1 deletions
diff --git a/ccan/list/list.h b/ccan/list/list.h
index 838ded4..749db78 100644
--- a/ccan/list/list.h
+++ b/ccan/list/list.h
@@ -92,6 +92,18 @@ static inline void list_head_init(struct list_head *h)
}
/**
+ * list_node_init - initialize a list_node
+ * @n: the list_node to link to itself.
+ *
+ * You don't need to use this normally! But it lets you list_del(@n)
+ * safely.
+ */
+static inline void list_node_init(struct list_node *n)
+{
+ n->next = n->prev = n;
+}
+
+/**
* list_add - add an entry at the start of a linked list.
* @h: the list_head to add the node to
* @n: the list_node to add to the list.
@@ -183,7 +195,7 @@ static inline int list_empty_nodebug(const struct list_head *h)
* another list, but not deleted again.
*
* See also:
- * list_del_from()
+ * list_del_from(), list_del_init()
*
* Example:
* list_del(&child->list);
@@ -202,6 +214,27 @@ static inline void list_del_(struct list_node *n, const char* abortstr)
}
/**
+ * list_del_init - delete a node, and reset it so it can be deleted again.
+ * @n: the list_node to be deleted.
+ *
+ * list_del(@n) or list_del_init() again after this will be safe,
+ * which can be useful in some cases.
+ *
+ * See also:
+ * list_del_from(), list_del()
+ *
+ * Example:
+ * list_del_init(&child->list);
+ * parent->num_children--;
+ */
+#define list_del_init(n) list_del_init_(n, LIST_LOC)
+static inline void list_del_init_(struct list_node *n, const char *abortstr)
+{
+ list_del_(n, abortstr);
+ list_node_init(n);
+}
+
+/**
* list_del_from - delete an entry from a known linked list.
* @h: the list_head the node is in.
* @n: the list_node to delete from the list.