下面介绍Linux通用链表(list)的splice(合并)函数:
1. static inline void __list_splice(struct list_head *list,
struct list_head *head)
{
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合并到另一链表的head的后一个位置.
2. static inline void list_splice_init(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head);
}
}
这个函数是上面的应用版, 加了一个判断list是否为空.
3. 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);
}
}
这是一个init版的splice应用, 加判断, 并且在合并之后对list进行重置.
1. static inline void __list_splice(struct list_head *list,
struct list_head *head)
{
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合并到另一链表的head的后一个位置.
2. static inline void list_splice_init(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head);
}
}
这个函数是上面的应用版, 加了一个判断list是否为空.
3. 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);
}
}
这是一个init版的splice应用, 加判断, 并且在合并之后对list进行重置.