1
2
3#include "list.h"
4
5
6
7
8
9
10
11void __list_add(struct list_head * add,
12 struct list_head * prev,
13 struct list_head * next)
14{
15 next->prev = add;
16 add->next = next;
17 add->prev = prev;
18 prev->next = add;
19}
20
21
22
23
24
25
26
27
28
29void list_add(struct list_head *add, struct list_head *head)
30{
31 __list_add(add, head, head->next);
32}
33
34
35
36
37
38
39
40
41
42void list_add_tail(struct list_head *add, struct list_head *head)
43{
44 __list_add(add, head->prev, head);
45}
46
47
48
49
50
51
52
53
54void __list_del(struct list_head * prev, struct list_head * next)
55{
56 next->prev = prev;
57 prev->next = next;
58}
59
60
61
62
63
64
65
66
67void list_del(struct list_head *entry)
68{
69 __list_del(entry->prev, entry->next);
70}
71
72
73
74
75
76void list_del_init(struct list_head *entry)
77{
78 __list_del(entry->prev, entry->next);
79 INIT_LIST_HEAD(entry);
80}
81
82
83
84
85
86int list_empty(struct list_head *head)
87{
88 return head->next == head;
89}
90
91
92
93
94
95
96void list_splice(struct list_head *list, struct list_head *head)
97{
98 struct list_head *first = list->next;
99
100 if (first != list) {
101 struct list_head *last = list->prev;
102 struct list_head *at = head->next;
103
104 first->prev = head;
105 head->next = first;
106
107 last->next = at;
108 at->prev = last;
109 }
110}
111