-
#define INIT_LIST_HEAD(ptr) do { \
-
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
- } while (0)

1.1 判断链表是否为空
-
static __inline__ int list_empty(struct list_head *head)
-
{
-
return head->next == head;
- }
2.链表的插入
2.1 有两种方式进行链表的插入 list_add与list_add_tail
-
static __inline__ void list_add(struct list_head *new, struct list_head *head)
-
{
-
__list_add(new, head, head->next);
- }

2.2 list_add_tail
-
static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
-
{
-
__list_add(new, head->prev, head);
- }

2.3 他们都调用了__list_add进入指针的操作
-
static __inline__ void __list_add(struct list_head * new,
-
struct list_head * prev,
-
struct list_head * next)
-
{
-
next->prev = new;
-
new->next = next;
-
new->prev = prev;
-
prev->next = new;
- }
3.1 调用list_del进行结点的删除,注意参数entry就是要删除的结点,
-
static __inline__ void list_del(struct list_head *entry)
-
{
-
__list_del(entry->prev, entry->next);
- }

虽然head->next->next 或者head->prev->prev搜索链表时找不到node2了,表面上看node2是被删掉,
但是node2本身的prev与next还分别指向node3与node1
3.2 调用list_del_init进行结点的安全删除,注意参数entry就是要删除的结点,
并使删除后的node指向自己本身
-
static __inline__ void list_del_init(struct list_head *entry)
-
{
-
__list_del(entry->prev, entry->next);
-
INIT_LIST_HEAD(entry);
- }
