Fix missing 2.6.12 in graphic
[kps.git] / list.h
blobe072b559bd220913186cbb2c2d7b94086574f913
1 /* Kernel changelog analysis
2 * (C) 2008 Wang Chen
4 * This code is licenced under the GPL.
6 */
8 #ifndef INC_LIST
9 #define INC_LIST
11 struct list_head {
12 struct list_head *next, *prev;
15 #define LIST_HEAD_INIT(name) { &(name), &(name) }
17 #define LIST_HEAD(name) \
18 struct list_head name = LIST_HEAD_INIT(name)
20 static inline void INIT_LIST_HEAD(struct list_head *list)
22 list->next = list;
23 list->prev = list;
26 static inline void __list_add(struct list_head *new,
27 struct list_head *prev,
28 struct list_head *next)
30 next->prev = new;
31 new->next = next;
32 new->prev = prev;
33 prev->next = new;
36 /* Insert a new entry after the specified head. */
37 static inline void list_add(struct list_head *new, struct list_head *head)
39 __list_add(new, head, head->next);
42 /* Insert a new entry before the specified head. */
43 static inline void list_add_tail(struct list_head *new, struct list_head *head)
45 __list_add(new, head->prev, head);
48 static inline void __list_del(struct list_head *prev, struct list_head *next)
50 next->prev = prev;
51 prev->next = next;
55 * These are non-NULL pointers that will result in page faults
56 * under normal circumstances, used to verify that nobody uses
57 * non-initialized list entries.
59 #define LIST_POISON1 ((void *) 0x00100100)
60 #define LIST_POISON2 ((void *) 0x00200200)
62 static inline void list_del(struct list_head *entry)
64 __list_del(entry->prev, entry->next);
65 entry->next = LIST_POISON1;
66 entry->prev = LIST_POISON2;
69 static inline void list_replace(struct list_head *old,
70 struct list_head *new)
72 new->next = old->next;
73 new->next->prev = new;
74 new->prev = old->prev;
75 new->prev->next = new;
78 static inline void list_move(struct list_head *list, struct list_head *head)
80 __list_del(list->prev, list->next);
81 list_add(list, head);
84 static inline void list_move_tail(struct list_head *list,
85 struct list_head *head)
87 __list_del(list->prev, list->next);
88 list_add_tail(list, head);
91 static inline int list_is_last(const struct list_head *list,
92 const struct list_head *head)
94 return list->next == head;
97 static inline int list_empty(const struct list_head *head)
99 return head->next == head;
102 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
104 * list_entry - get the struct for this entry
105 * @ptr: the &struct list_head pointer.
106 * @type: the type of the struct this is embedded in.
107 * @member: the name of the list_struct within the struct.
109 #define list_entry(ptr, type, member) ({ \
110 const typeof(((type *)0)->member) *__mptr = (ptr); \
111 (type *)((char *)__mptr - offsetof(type, member)); })
114 * list_first_entry - get the first element from a list
115 * @ptr: the list head to take the element from.
116 * @type: the type of the struct this is embedded in.
117 * @member: the name of the list_struct within the struct.
119 * Note, that list is expected to be not empty.
121 #define list_first_entry(ptr, type, member) \
122 list_entry((ptr)->next, type, member)
125 * list_for_each - iterate over a list
126 * @pos: the &struct list_head to use as a loop cursor.
127 * @head: the head for your list.
129 #define list_for_each(pos, head) \
130 for (pos = (head)->next; pos != (head); pos = pos->next)
133 * list_for_each_safe - iterate over a list safe against removal of list entry
134 * @pos: the &struct list_head to use as a loop cursor.
135 * @n: another &struct list_head to use as temporary storage
136 * @head: the head for your list.
138 #define list_for_each_safe(pos, n, head) \
139 for (pos = (head)->next, n = pos->next; pos != (head); \
140 pos = n, n = pos->next)
143 * list_for_each_entry - iterate over list of given type
144 * @pos: the type * to use as a loop cursor.
145 * @head: the head for your list.
146 * @member: the name of the list_struct within the struct.
148 #define list_for_each_entry(pos, head, member) \
149 for (pos = list_entry((head)->next, typeof(*pos), member); \
150 &pos->member != (head); \
151 pos = list_entry(pos->member.next, typeof(*pos), member))
153 #endif