ReactOS  0.4.12-dev-685-gf36cbf7
list.h
Go to the documentation of this file.
1 #ifndef __LIST_H
2 #define __LIST_H
3 
4 /* This file is from Linux Kernel (include/linux/list.h)
5  * and modified by simply removing hardware prefetching of list items.
6  * Here by copyright, credits attributed to wherever they belong.
7  * Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
8  */
9 
10 /*
11  * Simple doubly linked list implementation.
12  *
13  * Some of the internal functions ("__xxx") are useful when
14  * manipulating whole lists rather than single entries, as
15  * sometimes we already know the next/prev entries and we can
16  * generate better code by using them directly rather than
17  * using the generic single-entry routines.
18  */
19 
20 struct list_head {
21  struct list_head *next, *prev;
22 };
23 
24 #define LIST_HEAD_INIT(name) { &(name), &(name) }
25 
26 #define LIST_HEAD(name) \
27  struct list_head name = LIST_HEAD_INIT(name)
28 
29 #define INIT_LIST_HEAD(ptr) do { \
30  (ptr)->next = (ptr); (ptr)->prev = (ptr); \
31 } while (0)
32 
33 /*
34  * Insert a new entry between two known consecutive entries.
35  *
36  * This is only for internal list manipulation where we know
37  * the prev/next entries already!
38  */
39 static inline void __list_add(struct list_head *New,
40  struct list_head *prev,
41  struct list_head *next)
42 {
43  next->prev = New;
44  New->next = next;
45  New->prev = prev;
46  prev->next = New;
47 }
48 
57 static inline void list_add(struct list_head *New, struct list_head *head)
58 {
59  __list_add(New, head, head->next);
60 }
61 
70 static inline void list_add_tail(struct list_head *New, struct list_head *head)
71 {
72  __list_add(New, head->prev, head);
73 }
74 
75 /*
76  * Delete a list entry by making the prev/next entries
77  * point to each other.
78  *
79  * This is only for internal list manipulation where we know
80  * the prev/next entries already!
81  */
82 static inline void __list_del(struct list_head *prev, struct list_head *next)
83 {
84  next->prev = prev;
85  prev->next = next;
86 }
87 
93 static inline void list_del(struct list_head *entry)
94 {
95  __list_del(entry->prev, entry->next);
96  entry->next = (struct list_head *) 0;
97  entry->prev = (struct list_head *) 0;
98 }
99 
104 static inline void list_del_init(struct list_head *entry)
105 {
106  __list_del(entry->prev, entry->next);
108 }
109 
115 static inline void list_move(struct list_head *list, struct list_head *head)
116 {
118  list_add(list, head);
119 }
120 
126 static inline void list_move_tail(struct list_head *list,
127  struct list_head *head)
128 {
131 }
132 
137 static inline int list_empty(struct list_head *head)
138 {
139  return head->next == head;
140 }
141 
142 static inline void __list_splice(struct list_head *list,
143  struct list_head *head)
144 {
145  struct list_head *first = list->next;
146  struct list_head *last = list->prev;
147  struct list_head *at = head->next;
148 
149  first->prev = head;
150  head->next = first;
151 
152  last->next = at;
153  at->prev = last;
154 }
155 
161 static inline void list_splice(struct list_head *list, struct list_head *head)
162 {
163  if (!list_empty(list))
165 }
166 
174 static inline void list_splice_init(struct list_head *list,
175  struct list_head *head)
176 {
177  if (!list_empty(list)) {
180  }
181 }
182 
189 #ifdef __REACTOS__
190 #define list_entry(ptr, type, member) \
191  ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member)))
192 #else /* __REACTOS__ */
193 #define list_entry(ptr, type, member) \
194  ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
195 #endif /* __REACTOS__ */
196 
202 #define list_for_each(pos, head) \
203  for (pos = (head)->next; pos != (head); \
204  pos = pos->next)
205 
210 #define list_for_each_prev(pos, head) \
211  for (pos = (head)->prev; pos != (head); \
212  pos = pos->prev)
213 
220 #define list_for_each_safe(pos, n, head) \
221  for (pos = (head)->next, n = pos->next; pos != (head); \
222  pos = n, n = pos->next)
223 
230 #define list_for_each_entry(pos, head, member) \
231  for (pos = list_entry((head)->next, typeof(*pos), member); \
232  &pos->member != (head); \
233  pos = list_entry(pos->member.next, typeof(*pos), member))
234 
242 #define list_for_each_entry_safe(pos, n, head, member) \
243  for (pos = list_entry((head)->next, typeof(*pos), member), \
244  n = list_entry(pos->member.next, typeof(*pos), member); \
245  &pos->member != (head); \
246  pos = n, n = list_entry(n->member.next, typeof(*n), member))
247 
248 
249 #endif
struct list * prev
Definition: list.h:39
struct outqueuenode * head
Definition: adnsresfilter.c:66
POINT last
Definition: font.c:46
static void list_add(struct list_head *New, struct list_head *head)
Definition: list.h:57
const GLint * first
Definition: glext.h:5794
uint8_t entry
Definition: isohybrid.c:63
static void __list_add(struct list_head *New, struct list_head *prev, struct list_head *next)
Definition: list.h:39
struct list_head * next
Definition: list.h:16
#define New(t)
Definition: rtf.h:1086
static void list_del_init(struct list_head *entry)
Definition: list.h:104
struct list_head * prev
Definition: list.h:16
Definition: list.h:15
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
static void list_splice(struct list_head *list, struct list_head *head)
Definition: list.h:161
__WINE_SERVER_LIST_INLINE void list_move_tail(struct list *dst, struct list *src)
Definition: list.h:164
struct list * next
Definition: list.h:38
static void list_move(struct list_head *list, struct list_head *head)
Definition: list.h:115
#define INIT_LIST_HEAD(ptr)
Definition: list.h:29
static void list_del(struct list_head *entry)
Definition: list.h:93
Definition: _list.h:228
static void list_splice_init(struct list_head *list, struct list_head *head)
Definition: list.h:174
__WINE_SERVER_LIST_INLINE int list_empty(const struct list *list)
Definition: list.h:143
static unsigned __int64 next
Definition: rand_nt.c:6
static void __list_del(struct list_head *prev, struct list_head *next)
Definition: list.h:82
struct define * next
Definition: wpp.c:35
static void __list_splice(struct list_head *list, struct list_head *head)
Definition: list.h:142