]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: list: add new macro LIST_INLIST_ATOMIC()
authorWilly Tarreau <w@1wt.eu>
Thu, 21 Oct 2021 12:06:01 +0000 (14:06 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 21 Oct 2021 13:28:24 +0000 (15:28 +0200)
This macro is similar to LIST_INLIST() except that it is guaranteed to
perform the test atomically, so that even if LIST_INLIST() is intrumented
with debugging code to perform extra consistency checks, it will not fail
when used in the context of barriers and atomic ops.

include/haproxy/list.h

index 1d39a9d7180fd8e96ae3a86566d9ea1a3b15e74c..fab1316e449d3175caa385dd8da40e047588b2ca 100644 (file)
  */
 #define LIST_INLIST(el) ((el)->n != (el))
 
+/* 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
+ * instrumented using debugging code to perform further consistency checks,
+ * the macro below guarantees to always perform a single atomic test and is
+ * safe to use with barriers.
+ */
+#define LIST_INLIST_ATOMIC(el) ({                       \
+       typeof(el) __ptr = (el);                        \
+       HA_ATOMIC_LOAD(&(__ptr)->n) != __ptr;           \
+})
+
 /* 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.