ContainerTracer  0.1
flist.h
Go to the documentation of this file.
1 #ifndef _LINUX_FLIST_H
2 #define _LINUX_FLIST_H
3 
4 #include <stdlib.h>
5 
6 #undef offsetof
7 #ifdef __compiler_offsetof
8 #define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
9 #else
10 #define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER)
11 #endif
12 
13 #define container_of(ptr, type, member) \
14  ({ \
15  const typeof(((type *)0)->member) *__mptr = (ptr); \
16  (type *)((char *)__mptr - offsetof(type, member)); \
17  })
18 
19 /*
20  * Simple doubly linked list implementation.
21  *
22  * Some of the internal functions ("__xxx") are useful when
23  * manipulating whole lists rather than single entries, as
24  * sometimes we already know the next/prev entries and we can
25  * generate better code by using them directly rather than
26  * using the generic single-entry routines.
27  */
28 
29 struct flist_head {
30  struct flist_head *next, *prev;
31 };
32 
33 #define FLIST_HEAD_INIT(name) \
34  { \
35  &(name), &(name) \
36  }
37 
38 #define FLIST_HEAD(name) struct flist_head name = FLIST_HEAD_INIT(name)
39 
40 #define INIT_FLIST_HEAD(ptr) \
41  do { \
42  (ptr)->next = (ptr); \
43  (ptr)->prev = (ptr); \
44  } while (0)
45 
46 /*
47  * Insert a new entry between two known consecutive entries.
48  *
49  * This is only for internal list manipulation where we know
50  * the prev/next entries already!
51  */
52 static inline void __flist_add(struct flist_head *new_entry,
53  struct flist_head *prev, struct flist_head *next)
54 {
55  next->prev = new_entry;
56  new_entry->next = next;
57  new_entry->prev = prev;
58  prev->next = new_entry;
59 }
60 
69 static inline void flist_add(struct flist_head *new_entry,
70  struct flist_head *head)
71 {
72  __flist_add(new_entry, head, head->next);
73 }
74 
75 static inline void flist_add_tail(struct flist_head *new_entry,
76  struct flist_head *head)
77 {
78  __flist_add(new_entry, head->prev, head);
79 }
80 
81 /*
82  * Delete a list entry by making the prev/next entries
83  * point to each other.
84  *
85  * This is only for internal list manipulation where we know
86  * the prev/next entries already!
87  */
88 static inline void __flist_del(struct flist_head *prev, struct flist_head *next)
89 {
90  next->prev = prev;
91  prev->next = next;
92 }
93 
100 static inline void flist_del(struct flist_head *entry)
101 {
102  __flist_del(entry->prev, entry->next);
103  entry->next = NULL;
104  entry->prev = NULL;
105 }
106 
111 static inline void flist_del_init(struct flist_head *entry)
112 {
113  __flist_del(entry->prev, entry->next);
114  INIT_FLIST_HEAD(entry);
115 }
116 
121 static inline int flist_empty(const struct flist_head *head)
122 {
123  return head->next == head;
124 }
125 
126 static inline void __flist_splice(const struct flist_head *list,
127  struct flist_head *prev,
128  struct flist_head *next)
129 {
130  struct flist_head *first = list->next;
131  struct flist_head *last = list->prev;
132 
133  first->prev = prev;
134  prev->next = first;
135 
136  last->next = next;
137  next->prev = last;
138 }
139 
140 static inline void flist_splice(const struct flist_head *list,
141  struct flist_head *head)
142 {
143  if (!flist_empty(list))
144  __flist_splice(list, head, head->next);
145 }
146 
147 static inline void flist_splice_init(struct flist_head *list,
148  struct flist_head *head)
149 {
150  if (!flist_empty(list)) {
151  __flist_splice(list, head, head->next);
152  INIT_FLIST_HEAD(list);
153  }
154 }
155 
162 #define flist_entry(ptr, type, member) container_of(ptr, type, member)
163 
169 #define flist_for_each(pos, head) \
170  for (pos = (head)->next; pos != (head); pos = pos->next)
171 
178 #define flist_for_each_safe(pos, n, head) \
179  for (pos = (head)->next, n = pos->next; pos != (head); \
180  pos = n, n = pos->next)
181 
182 extern void flist_sort(void *priv, struct flist_head *head,
183  int (*cmp)(void *priv, struct flist_head *a,
184  struct flist_head *b));
185 
186 #endif
void flist_sort(void *priv, struct flist_head *head, int(*cmp)(void *priv, struct flist_head *a, struct flist_head *b))
static void flist_del(struct flist_head *entry)
Definition: flist.h:100
static void __flist_splice(const struct flist_head *list, struct flist_head *prev, struct flist_head *next)
Definition: flist.h:126
static int flist_empty(const struct flist_head *head)
Definition: flist.h:121
static void flist_add(struct flist_head *new_entry, struct flist_head *head)
Definition: flist.h:69
Definition: flist.h:29
struct flist_head * prev
Definition: flist.h:30
static void flist_splice(const struct flist_head *list, struct flist_head *head)
Definition: flist.h:140
static void flist_splice_init(struct flist_head *list, struct flist_head *head)
Definition: flist.h:147
static void __flist_add(struct flist_head *new_entry, struct flist_head *prev, struct flist_head *next)
Definition: flist.h:52
static void __flist_del(struct flist_head *prev, struct flist_head *next)
Definition: flist.h:88
#define INIT_FLIST_HEAD(ptr)
Definition: flist.h:40
struct flist_head * next
Definition: flist.h:30
static void flist_add_tail(struct flist_head *new_entry, struct flist_head *head)
Definition: flist.h:75
static void flist_del_init(struct flist_head *entry)
Definition: flist.h:111