From c79f01497208e3cea20d4d563dee158e0e6f4674 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 21 Oct 2021 14:06:01 +0200 Subject: [PATCH] MINOR: list: add new macro LIST_INLIST_ATOMIC() 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/haproxy/list.h b/include/haproxy/list.h index 1d39a9d71..fab1316e4 100644 --- a/include/haproxy/list.h +++ b/include/haproxy/list.h @@ -101,6 +101,18 @@ */ #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 to a structure following the element * which contains list head , which is known as element in * struct pt.