Buddy Allocator  0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
list.h
Go to the documentation of this file.
1 #ifndef __LIST_H
2 #define __LIST_H
3 /* from Linux kernel */
4 
5 /* This file is from Linux Kernel (include/linux/list.h)
6  * and modified by simply removing hardware prefetching of list items.
7  * Here by copyright, credits attributed to wherever they belong.
8  * Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
9  */
10 
11 /*
12  * Simple doubly linked list implementation.
13  *
14  * Some of the internal functions ("__xxx") are useful when
15  * manipulating whole lists rather than single entries, as
16  * sometimes we already know the next/prev entries and we can
17  * generate better code by using them directly rather than
18  * using the generic single-entry routines.
19  */
20 
21 struct list_head {
22  struct list_head *next, *prev;
23 };
24 
25 #define LIST_HEAD_INIT(name) { &(name), &(name) }
26 
27 #define LIST_HEAD(name) \
28  struct list_head name = LIST_HEAD_INIT(name)
29 
30 #define INIT_LIST_HEAD(ptr) do { \
31  (ptr)->next = (ptr); (ptr)->prev = (ptr); \
32 } while (0)
33 
34 /*
35  * Insert a new entry between two known consecutive entries.
36  *
37  * This is only for internal list manipulation where we know
38  * the prev/next entries already!
39  */
40 static inline void __list_add(struct list_head *new,
41  struct list_head *prev,
42  struct list_head *next)
43 {
44  next->prev = new;
45  new->next = next;
46  new->prev = prev;
47  prev->next = new;
48 }
49 
58 static inline void list_add(struct list_head *new, struct list_head *head)
59 {
60  __list_add(new, head, head->next);
61 }
62 
71 static inline void list_add_tail(struct list_head *new, struct list_head *head)
72 {
73  __list_add(new, head->prev, head);
74 }
75 
76 /*
77  * Delete a list entry by making the prev/next entries
78  * point to each other.
79  *
80  * This is only for internal list manipulation where we know
81  * the prev/next entries already!
82  */
83 static inline void __list_del(struct list_head *prev, struct list_head *next)
84 {
85  next->prev = prev;
86  prev->next = next;
87 }
88 
94 static inline void list_del(struct list_head *entry)
95 {
96  __list_del(entry->prev, entry->next);
97  entry->next = (void *) 0x1010;
98  entry->prev = (void *) 0x1010;
99 }
100 
105 static inline void list_del_init(struct list_head *entry)
106 {
107  __list_del(entry->prev, entry->next);
108  INIT_LIST_HEAD(entry);
109 }
110 
116 static inline void list_move(struct list_head *list, struct list_head *head)
117 {
118  __list_del(list->prev, list->next);
119  list_add(list, head);
120 }
121 
127 static inline void list_move_tail(struct list_head *list,
128  struct list_head *head)
129 {
130  __list_del(list->prev, list->next);
131  list_add_tail(list, head);
132 }
133 
138 static inline int list_empty(struct list_head *head)
139 {
140  return head->next == head;
141 }
142 
143 static inline void __list_splice(struct list_head *list,
144  struct list_head *head)
145 {
146  struct list_head *first = list->next;
147  struct list_head *last = list->prev;
148  struct list_head *at = head->next;
149 
150  first->prev = head;
151  head->next = first;
152 
153  last->next = at;
154  at->prev = last;
155 }
156 
162 static inline void list_splice(struct list_head *list, struct list_head *head)
163 {
164  if (!list_empty(list))
165  __list_splice(list, head);
166 }
167 
175 static inline void list_splice_init(struct list_head *list,
176  struct list_head *head)
177 {
178  if (!list_empty(list)) {
179  __list_splice(list, head);
180  INIT_LIST_HEAD(list);
181  }
182 }
183 
190 #define list_entry(ptr, type, member) \
191  ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
192 
198 #define list_for_each(pos, head) \
199  for (pos = (head)->next; pos != (head); \
200  pos = pos->next)
201 
206 #define list_for_each_prev(pos, head) \
207  for (pos = (head)->prev; pos != (head); \
208  pos = pos->prev)
209 
216 #define list_for_each_safe(pos, n, head) \
217  for (pos = (head)->next, n = pos->next; pos != (head); \
218  pos = n, n = pos->next)
219 
226 #define list_for_each_entry(pos, head, member) \
227  for (pos = list_entry((head)->next, typeof(*pos), member); \
228  &pos->member != (head); \
229  pos = list_entry(pos->member.next, typeof(*pos), member))
230 
238 #define list_for_each_entry_safe(pos, n, head, member) \
239  for (pos = list_entry((head)->next, typeof(*pos), member), \
240  n = list_entry(pos->member.next, typeof(*pos), member); \
241  &pos->member != (head); \
242  pos = n, n = list_entry(n->member.next, typeof(*n), member))
243 
244 
245 #endif
static void list_add(struct list_head *new, struct list_head *head)
Definition: list.h:58
static void __list_splice(struct list_head *list, struct list_head *head)
Definition: list.h:143
struct list_head * next
Definition: list.h:22
static void list_splice_init(struct list_head *list, struct list_head *head)
Definition: list.h:175
static void list_move(struct list_head *list, struct list_head *head)
Definition: list.h:116
struct list_head * prev
Definition: list.h:22
Definition: list.h:21
static void list_del(struct list_head *entry)
Definition: list.h:94
static void list_add_tail(struct list_head *new, struct list_head *head)
Definition: list.h:71
static void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
Definition: list.h:40
static int list_empty(struct list_head *head)
Definition: list.h:138
static void list_move_tail(struct list_head *list, struct list_head *head)
Definition: list.h:127
static void __list_del(struct list_head *prev, struct list_head *next)
Definition: list.h:83
#define INIT_LIST_HEAD(ptr)
Definition: list.h:30
static void list_del_init(struct list_head *entry)
Definition: list.h:105
static void list_splice(struct list_head *list, struct list_head *head)
Definition: list.h:162