list_for_each_safe解释

来源:互联网 发布:知乎恐怖提问 编辑:程序博客网 时间:2024/06/08 13:35

list_for_each_safe在源码目录/tools/include/linux/list.h下:

/**
 * list_for_each_safe - iterate over a list safe against removal of list entry
 * @pos:    the &struct list_head to use as a loop cursor.
 * @n:        another &struct list_head to use as temporary storage
 * @head:    the head for your list.
 */
#define list_for_each_safe(pos, n, head) \
    for (pos = (head)->next, n = pos->next; pos != (head); \
        pos = n, n = pos->next)

可以看出三个参数,第一个是当前位置,第二个是当前位置的下一个位置,第三个是链表头,

此函数的作用就是遍历整个链表。

0 0