From f42e6ed8b8c71b3cdc1f0ed7c3f8d2f0c0ec6427 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Thu, 4 Jul 2002 08:30:49 -0700 Subject: [PATCH] add new list_splice_init() A little cleanup: Most callers of list_splice() immediately reinitialise the source list_head after calling list_splice(). So create a new list_splice_init() which does all that. --- include/linux/list.h | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'include/linux') diff --git a/include/linux/list.h b/include/linux/list.h index ac65cc310ab6..3e70aa03ac11 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -136,6 +136,19 @@ static inline int list_empty(list_t *head) return head->next == head; } +static inline void __list_splice(list_t *list, list_t *head) +{ + list_t *first = list->next; + list_t *last = list->prev; + list_t *at = head->next; + + first->prev = head; + head->next = first; + + last->next = at; + at->prev = last; +} + /** * list_splice - join two lists * @list: the new list to add. @@ -145,15 +158,22 @@ static inline void list_splice(list_t *list, list_t *head) { list_t *first = list->next; - if (first != list) { - list_t *last = list->prev; - list_t *at = head->next; - - first->prev = head; - head->next = first; + if (first != list) + __list_splice(list, head); +} - last->next = at; - at->prev = last; +/** + * list_splice_init - join two lists and reinitialise the emptied list. + * @list: the new list to add. + * @head: the place to add it in the first list. + * + * The list at @list is reinitialised + */ +static inline void list_splice_init(list_t *list, list_t *head) +{ + if (!list_empty(list)) { + __list_splice(list, head); + INIT_LIST_HEAD(list); } } -- cgit v1.2.3