]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lists: add LIST_ADDED() to check if an element belongs to a list
authorWilly Tarreau <w@1wt.eu>
Mon, 13 May 2019 15:48:46 +0000 (17:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 13 May 2019 17:14:52 +0000 (19:14 +0200)
Some code parts use LIST_ISEMPTY() a lot on list elements to detect
if they were reset consecutive to their removal from a list, but this
test is always confusing as this was initially designed for list heads.

Instead let's have a new macro, LIST_ADDED(), which returns true when
the element is in a list (i.e. it's not "empty").

include/common/mini-clist.h

index 648cbd5dca1a257736343e5e57899eacf5b79cd5..592bb9613666e991876e449a4a9b82b78bb7e314 100644 (file)
@@ -111,6 +111,11 @@ struct cond_wordlist {
 /* checks if the list head <lh> is empty or not */
 #define LIST_ISEMPTY(lh) ((lh)->n == (lh))
 
+/* checks if the list element <el> was added to a list or not. This only
+ * works when detached elements are reinitialized (using LIST_DEL_INIT)
+ */
+#define LIST_ADDED(el) ((el)->n != (el))
+
 /* returns a pointer of type <pt> to a structure following the element
  * which contains list head <lh>, which is known as element <el> in
  * struct pt.