1
2#ifndef LINUX_LIST_H
3#define LINUX_LIST_H 1
4
5
6
7
8
9
10
11
12
13
14
15struct list_head {
16 struct list_head *next, *prev;
17};
18
19#define LIST_HEAD_INIT(name) { &(name), &(name) }
20
21#define LIST_HEAD(name) \
22 struct list_head name = { &name, &name }
23
24#define INIT_LIST_HEAD(ptr) do { \
25 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
26} while (0)
27
28#if (!defined(__GNUC__) && !defined(__WATCOMC__))
29#define __inline__
30#endif
31
32
33
34
35
36
37
38static __inline__ void __list_add(struct list_head * new,
39 struct list_head * prev,
40 struct list_head * next)
41{
42 next->prev = new;
43 new->next = next;
44 new->prev = prev;
45 prev->next = new;
46}
47
48
49
50
51static __inline__ void list_add(struct list_head *new, struct list_head *head)
52{
53 __list_add(new, head, head->next);
54}
55
56
57
58
59static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
60{
61 __list_add(new, head->prev, head);
62}
63
64
65
66
67
68
69
70
71static __inline__ void __list_del(struct list_head * prev,
72 struct list_head * next)
73{
74 next->prev = prev;
75 prev->next = next;
76}
77
78static __inline__ void list_del(struct list_head *entry)
79{
80 __list_del(entry->prev, entry->next);
81}
82
83static __inline__ int list_empty(struct list_head *head)
84{
85 return head->next == head;
86}
87
88
89
90
91static __inline__ void list_splice(struct list_head *list, struct list_head *head)
92{
93 struct list_head *first = list->next;
94
95 if (first != list) {
96 struct list_head *last = list->prev;
97 struct list_head *at = head->next;
98
99 first->prev = head;
100 head->next = first;
101
102 last->next = at;
103 at->prev = last;
104 }
105}
106
107#define list_entry(ptr, type, member) \
108 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
109
110#define list_for_each(pos, head) \
111 for (pos = (head)->next; pos != (head); pos = pos->next)
112
113#endif
114