From 42ccb5ac45058a4ad8a74794414e76ec371d50c0 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 13 May 2019 17:48:46 +0200 Subject: [PATCH] MINOR: lists: add LIST_ADDED() to check if an element belongs to a list 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/common/mini-clist.h b/include/common/mini-clist.h index 648cbd5dc..592bb9613 100644 --- a/include/common/mini-clist.h +++ b/include/common/mini-clist.h @@ -111,6 +111,11 @@ struct cond_wordlist { /* checks if the list head is empty or not */ #define LIST_ISEMPTY(lh) ((lh)->n == (lh)) +/* checks if the list element 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 to a structure following the element * which contains list head , which is known as element in * struct pt.