Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
list.h
Go to the documentation of this file.
1 #ifndef LIST_H
2 #define LIST_H
3 
4 /*
5  * Copied from include/linux/...
6  */
7 
8 #undef offsetof
9 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
10 
18 #define container_of(ptr, type, member) ({ \
19  const typeof( ((type *)0)->member ) *__mptr = (ptr); \
20  (type *)( (char *)__mptr - offsetof(type,member) );})
21 
22 
23 struct list_head {
24  struct list_head *next, *prev;
25 };
26 
27 
28 #define LIST_HEAD_INIT(name) { &(name), &(name) }
29 
30 #define LIST_HEAD(name) \
31  struct list_head name = LIST_HEAD_INIT(name)
32 
39 #define list_entry(ptr, type, member) \
40  container_of(ptr, type, member)
41 
48 #define list_for_each_entry(pos, head, member) \
49  for (pos = list_entry((head)->next, typeof(*pos), member); \
50  &pos->member != (head); \
51  pos = list_entry(pos->member.next, typeof(*pos), member))
52 
57 static inline int list_empty(const struct list_head *head)
58 {
59  return head->next == head;
60 }
61 
62 /*
63  * Insert a new entry between two known consecutive entries.
64  *
65  * This is only for internal list manipulation where we know
66  * the prev/next entries already!
67  */
68 static inline void __list_add(struct list_head *_new,
69  struct list_head *prev,
70  struct list_head *next)
71 {
72  next->prev = _new;
73  _new->next = next;
74  _new->prev = prev;
75  prev->next = _new;
76 }
77 
86 static inline void list_add_tail(struct list_head *_new, struct list_head *head)
87 {
88  __list_add(_new, head->prev, head);
89 }
90 
91 #endif