From 2062ec0d67fb83fa25fc938c992a8e882612c777 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Mon, 15 Jul 2019 13:15:18 -0700 Subject: session: use llist in session node evt handling Type: refactor Change-Id: I24159e0a848f552b4e27acfb5fe6f2cd91b50a19 Signed-off-by: Florin Coras --- src/vppinfra/llist.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/vppinfra/llist.h') diff --git a/src/vppinfra/llist.h b/src/vppinfra/llist.h index 1648021681f..d521a725fc3 100644 --- a/src/vppinfra/llist.h +++ b/src/vppinfra/llist.h @@ -102,7 +102,17 @@ do { \ * @param H list head * @return 1 if sentinel is the only node part of the list, 0 otherwise */ -#define clib_llist_is_empty(LP,name,H) ((H) == clib_llist_next((LP),name,(H))) +#define clib_llist_is_empty(LP,name,H) \ + (clib_llist_entry_index (LP,H) == (H)->name.next) +/** + * Check if element is linked in a list + * + * @param E list element + * @param name list anchor name + */ +#define clib_llist_elt_is_linked(E,name) \ + ((E)->name.next != CLIB_LLIST_INVALID_INDEX \ + && (E)->name.prev != CLIB_LLIST_INVALID_INDEX) /** * Insert entry between previous and next * @@ -175,7 +185,22 @@ do { \ _lprev (_ll_var (N),name) = _lprev (E,name); \ _lnext (E,name) = _lprev (E,name) = CLIB_LLIST_INVALID_INDEX; \ }while (0) - +/** + * Removes and returns the first element in the list. + * + * The element is not freed. It's the responsability of the caller to + * free it. + * + * @param LP linked list pool + * @param name list anchor name + * @param E storage the first entry + * @param H list head entry + */ +#define clib_llist_pop_first(LP,name,E,H) \ +do { \ + E = clib_llist_next (LP,name,H); \ + clib_llist_remove (LP,name,E); \ +} while (0) /** * Splice two lists at a given position * -- cgit 1.2.3-korg