注解:
对于list_cut_position的用法不能理解,看了实际的例子才知道如何用的。
主要是对于list、entry和head的关系没搞太明白。
list:是一个空链表头,可以是head也可以不是
entry:是head链表的任意一个节点
这样就比较好理解了,加入我有个链表,链表头为head,下面有0-5,共5个节点。
我现在初始化了一个新的链表头list,下面没有节点。
我想把head下面的3-5号节点拿过来。
调用接口传参为:
list_cut_position(list, head, head中的标号为3的节点地址)
函数源码:
static inline void __list_cut_position(struct list_head *list,
struct list_head *head, struct list_head *entry)
{
struct list_head *new_first = entry->next;
list->next = head->next;
list->next->prev = list;
list->prev = entry;
entry->next = list;
head->next = new_first;
new_first->prev = head;
}
/**
* list_cut_position - cut a list into two
* @list: a new list to add all removed entries
* @head: a list with entries
* @entry: an entry within head, could be the head itself
* and if so we won't cut the list
*
* This helper moves the initial part of @head, up to and
* including @entry, from @head to @list. You should
* pass on @entry an element you know is on @head. @list
* should be an empty list or a list you do not care about
* losing its data.
*
*/
static inline void list_cut_position(struct list_head *list,
struct list_head *head, struct list_head *entry)
{
if (list_empty(head))
return;
if (list_is_singular(head) &&
(head->next != entry && head != entry))
return;
if (entry == head)
INIT_LIST_HEAD(list);
else
__list_cut_position(list, head, entry);
}
参考:参考示例
这里面有示例代码,自己看吧。。。