]> git.alsa-project.org Git - alsa-lib.git/commitdiff
include: list.h - add list_splice() and list_splice_init() functions
authorJaroslav Kysela <perex@perex.cz>
Tue, 18 Nov 2025 13:37:45 +0000 (14:37 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 18 Nov 2025 13:41:53 +0000 (14:41 +0100)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/list.h

index 7f0cfc0cd67810f0ab2bf144faedb9036db44468..29edac0468eddee8c8dc3d880d62a669e7bab145 100644 (file)
@@ -114,4 +114,39 @@ static inline int list_empty(const struct list_head *p)
        return p->next == p;
 }
 
+/* list_splice - join two lists
+ * @list: the new list to add
+ * @head: the place to add it in the first list
+ */
+static inline void list_splice(const struct list_head *list,
+                               struct list_head *head)
+{
+       if (!list_empty(list)) {
+               struct list_head *first = list->next;
+               struct list_head *last = list->prev;
+               struct list_head *at = head->next;
+
+               first->prev = head;
+               head->next = first;
+
+               last->next = at;
+               at->prev = last;
+       }
+}
+
+/* list_splice_init - join two lists and reinitialize the emptied list
+ * @list: the new list to add
+ * @head: the place to add it in the first list
+ *
+ * The list at @list is reinitialized
+ */
+static inline void list_splice_init(struct list_head *list,
+                                   struct list_head *head)
+{
+       if (!list_empty(list)) {
+               list_splice(list, head);
+               INIT_LIST_HEAD(list);
+       }
+}
+
 #endif /* _LIST_H */