Add three list helpers:

        list_del_init
        list_splice
        list_splice_tail

Signed-off-by: Jingbo Xu <[email protected]>
---
 include/erofs/list.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/include/erofs/list.h b/include/erofs/list.h
index 3f5da1a..7895ff0 100644
--- a/include/erofs/list.h
+++ b/include/erofs/list.h
@@ -65,11 +65,42 @@ static inline void list_del(struct list_head *entry)
        entry->prev = entry->next = NULL;
 }
 
+static inline void list_del_init(struct list_head *entry)
+{
+       __list_del(entry->prev, entry->next);
+       init_list_head(entry);
+}
+
 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(struct list_head *list, struct list_head *head)
+{
+       if (!list_empty(list))
+               __list_splice(list, head, head->next);
+}
+
+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)                                    
\
-- 
2.19.1.6.gb485710b

Reply via email to