mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-03-11 05:33:43 -04:00
include: list.h - add list_splice() and list_splice_init() functions
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
fd719bb122
commit
a525015e3b
1 changed files with 35 additions and 0 deletions
|
|
@ -114,4 +114,39 @@ static inline int list_empty(const struct list_head *p)
|
||||||
return p->next == 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 */
|
#endif /* _LIST_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue