内核链表的使用

     |   0 评论   |   0 浏览

内核链表

1#define dlist_for_each(pos, head) \
2    for (pos = (head)->next; pos != (head); \
3         pos = pos->next)
4
5#define dlist_for_each_safe(pos, n, head) \
6    for (pos = (head)->next, n = pos->next; pos != (head); \
7         pos = n, n = pos->next)

如果在遍历链表的过程中需要删除节点,应该使用 list_for_each_safe。
如果只是简单地遍历链表,而不需要删除节点,那么使用 list_for_each 就可以了。