erofs-utils: lib: add list_splice_tail() helper
authorJingbo Xu <jefflexu@linux.alibaba.com>
Wed, 13 Sep 2023 12:02:56 +0000 (20:02 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 14 Sep 2023 09:45:11 +0000 (17:45 +0800)
Add list_splice_tail() helper.

Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230913120304.15741-2-jefflexu@linux.alibaba.com
include/erofs/list.h

index 3f5da1a5c2dbd6a156933a56265f2dba04bbf3d8..d7a9feeca5b5f01215893b16f07d0a1d53de03b3 100644 (file)
@@ -70,6 +70,26 @@ static inline int list_empty(struct list_head *head)
        return head->next == head;
 }
 
+static inline void __list_splice(struct list_head *list,
+               struct list_head *prev, struct list_head *next)
+{
+       struct list_head *first = list->next;
+       struct list_head *last = list->prev;
+
+       first->prev = prev;
+       prev->next = first;
+
+       last->next = next;
+       next->prev = last;
+}
+
+static inline void list_splice_tail(struct list_head *list,
+                                   struct list_head *head)
+{
+       if (!list_empty(list))
+               __list_splice(list, head->prev, head);
+}
+
 #define list_entry(ptr, type, member) container_of(ptr, type, member)
 
 #define list_first_entry(ptr, type, member)                                    \