]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: list: add a macro to detect that a list contains at most one element
authorWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2024 16:21:50 +0000 (18:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 27 Apr 2024 07:36:36 +0000 (09:36 +0200)
The new LIST_ATMOST1() test verifies that the designated element is either
alone or points on both sides to the same element. This is used to detect
that a list has at most a single element, or that an element about to be
deleted was the last one of a list.

include/haproxy/list.h

index 368e6d76b821916a97a9489795b1f025a992ea21..b922bc19b287ef9b132ecec725d9a12dc64e4d0e 100644 (file)
  */
 #define LIST_INLIST(el) ((el)->n != (el))
 
+/* checks if the list element <el> has the same prev and next, i.e. it's either
+ * detached or alone in a list since (it points to itself or to a single other
+ * node). One can check that an element is strictly attached and alone by
+ * combining this with LIST_INLIST().
+ */
+#define LIST_ATMOST1(el) ((el)->n == (el)->p)
+
 /* atomically checks if the list element's next pointer points to anything
  * different from itself, implying the element should be part of a list. This
  * usually is similar to LIST_INLIST() except that while that one might be