This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit cabb8b820c1b2c30f82b18a702efd011bec66d04
Author: yinshengkai <[email protected]>
AuthorDate: Wed Aug 27 16:33:13 2025 +0800

    list: add list_move support
    
    list_move() moves every entry of one list to another and leaves the
    source empty.  Two callers in tree already relink lists by hand for
    this (watchdog_unregister() detaches its channel list before freeing);
    give them a helper that keeps the relink in one place.
    
    Signed-off-by: yinshengkai <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 include/nuttx/list.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/include/nuttx/list.h b/include/nuttx/list.h
index 704559a6faf..9eb7064b52a 100644
--- a/include/nuttx/list.h
+++ b/include/nuttx/list.h
@@ -316,6 +316,42 @@
       &entry->member != (list); \
       entry = list_container_of(entry->member.prev, type, member))
 
+/* The list_split macro divides a linked list at a given node and
+ * inserts the portion of the list from its beginning up to node
+ * (inclusive) into another linked list before the specified node next.
+ */
+
+#define list_split(head, item, list) \
+ do \
+   { \
+     FAR struct list_node *__head = (head); \
+     FAR struct list_node *__list = (list); \
+     FAR struct list_node *__item = (item); \
+     (__list)->prev = (__head)->prev; \
+     (__list)->prev->next = (__list); \
+     (__list)->next = (__item); \
+     (__head)->prev = (__item)->prev; \
+     (__head)->prev->next = (__head); \
+     (__item)->prev = (__list); \
+   } \
+ while (0)
+
+/* Move all items from one list to another */
+
+#define list_move(from, to) \
+ do \
+   { \
+     if (list_is_empty(from)) \
+       { \
+         list_initialize(to); \
+       } \
+     else \
+       { \
+         list_split(from, (from)->next, to); \
+       } \
+   } \
+ while (0)
+
 /****************************************************************************
  * Inline Functions
  ****************************************************************************/

Reply via email to