From dc096f951e482a7c3061288213ff0b3209afffcd Mon Sep 17 00:00:00 2001 From: ligd Date: Fri, 11 Aug 2023 18:28:10 +0800 Subject: [PATCH] list: update list.h The function name comes from list.h inside Linux, but rewrite from scratch to avoid the copyright issue. Since many developers are familiar with Linux list API. Signed-off-by: ligd --- include/nuttx/list.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/nuttx/list.h b/include/nuttx/list.h index 972db0fc27..ea03ce9c70 100644 --- a/include/nuttx/list.h +++ b/include/nuttx/list.h @@ -92,6 +92,8 @@ #define list_entry(ptr, type, member) container_of(ptr, type, member) #define list_first_entry(list, type, member) container_of((list)->next, type, member) #define list_last_entry(list, type, member) container_of((list)->prev, type, member) +#define list_next_entry(list, type, member) container_of((list)->member.next, type, member) +#define list_prev_entry(list, type, member) container_of((list)->member.prev, type, member) #define list_add_after(entry, new_entry) list_add_head(entry, new_entry) #define list_add_head(list, item) \ @@ -129,6 +131,14 @@ } \ while (0) +#define list_delete_init(item) \ + do \ + { \ + list_delete(item); \ + list_initialize(item); \ + } \ + while (0) + #define list_remove_head_type(list, type, member) \ ({ \ FAR struct list_node *__node = list_remove_head(list); \ @@ -247,6 +257,11 @@ &entry->member != (list); entry = temp, \ temp = container_of(temp->member.next, type, member)) +#define list_for_every_entry_continue(list, head, type, member) \ + for ((list) = list_next_entry(list, type, member); \ + &(list)->member != (head); \ + (list) = list_next_entry(list, type, member)) + /* iterates over the list in reverse order, entry should be the container * structure type */