libosmocore 0.9.6-23.20170220git32ee5af8.fc42
Osmocom core library
Loading...
Searching...
No Matches
linuxlist.h
Go to the documentation of this file.
1#pragma once
2
19#include <stddef.h>
20
21#ifndef inline
22#define inline __inline__
23#endif
24
25static inline void prefetch(const void *x) {;}
26
33#define container_of(ptr, type, member) ({ \
34 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
35 (type *)( (char *)__mptr - offsetof(type, member) );})
36
37
43#define LLIST_POISON1 ((void *) 0x00100100)
44#define LLIST_POISON2 ((void *) 0x00200200)
45
47struct llist_head {
49 struct llist_head *next, *prev;
50};
51
52#define LLIST_HEAD_INIT(name) { &(name), &(name) }
53
59#define LLIST_HEAD(name) \
60 struct llist_head name = LLIST_HEAD_INIT(name)
61
63#define INIT_LLIST_HEAD(ptr) do { \
64 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
65} while (0)
66
72static inline void __llist_add(struct llist_head *_new,
73 struct llist_head *prev,
74 struct llist_head *next)
75{
76 next->prev = _new;
77 _new->next = next;
78 _new->prev = prev;
79 prev->next = _new;
80}
81
89static inline void llist_add(struct llist_head *_new, struct llist_head *head)
90{
91 __llist_add(_new, head, head->next);
92}
93
101static inline void llist_add_tail(struct llist_head *_new, struct llist_head *head)
102{
103 __llist_add(_new, head->prev, head);
104}
105
106/*
107 * Delete a llist entry by making the prev/next entries
108 * point to each other.
109 *
110 * This is only for internal llist manipulation where we know
111 * the prev/next entries already!
112 */
113static inline void __llist_del(struct llist_head * prev, struct llist_head * next)
114{
115 next->prev = prev;
116 prev->next = next;
117}
118
125static inline void llist_del(struct llist_head *entry)
126{
127 __llist_del(entry->prev, entry->next);
128 entry->next = (struct llist_head *)LLIST_POISON1;
129 entry->prev = (struct llist_head *)LLIST_POISON2;
130}
131
135static inline void llist_del_init(struct llist_head *entry)
136{
137 __llist_del(entry->prev, entry->next);
138 INIT_LLIST_HEAD(entry);
139}
140
145static inline void llist_move(struct llist_head *llist, struct llist_head *head)
146{
147 __llist_del(llist->prev, llist->next);
148 llist_add(llist, head);
149}
150
155static inline void llist_move_tail(struct llist_head *llist,
156 struct llist_head *head)
157{
158 __llist_del(llist->prev, llist->next);
159 llist_add_tail(llist, head);
160}
161
166static inline int llist_empty(const struct llist_head *head)
167{
168 return head->next == head;
169}
170
171static inline void __llist_splice(struct llist_head *llist,
172 struct llist_head *head)
173{
174 struct llist_head *first = llist->next;
175 struct llist_head *last = llist->prev;
176 struct llist_head *at = head->next;
177
178 first->prev = head;
179 head->next = first;
180
181 last->next = at;
182 at->prev = last;
183}
184
189static inline void llist_splice(struct llist_head *llist, struct llist_head *head)
190{
191 if (!llist_empty(llist))
192 __llist_splice(llist, head);
193}
194
201static inline void llist_splice_init(struct llist_head *llist,
202 struct llist_head *head)
203{
204 if (!llist_empty(llist)) {
205 __llist_splice(llist, head);
206 INIT_LLIST_HEAD(llist);
207 }
208}
209
215#define llist_entry(ptr, type, member) \
216 container_of(ptr, type, member)
217
222#define llist_for_each(pos, head) \
223 for (pos = (head)->next, prefetch(pos->next); pos != (head); \
224 pos = pos->next, prefetch(pos->next))
225
235#define __llist_for_each(pos, head) \
236 for (pos = (head)->next; pos != (head); pos = pos->next)
237
242#define llist_for_each_prev(pos, head) \
243 for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
244 pos = pos->prev, prefetch(pos->prev))
245
251#define llist_for_each_safe(pos, n, head) \
252 for (pos = (head)->next, n = pos->next; pos != (head); \
253 pos = n, n = pos->next)
254
260#define llist_for_each_entry(pos, head, member) \
261 for (pos = llist_entry((head)->next, typeof(*pos), member), \
262 prefetch(pos->member.next); \
263 &pos->member != (head); \
264 pos = llist_entry(pos->member.next, typeof(*pos), member), \
265 prefetch(pos->member.next))
266
272#define llist_for_each_entry_reverse(pos, head, member) \
273 for (pos = llist_entry((head)->prev, typeof(*pos), member), \
274 prefetch(pos->member.prev); \
275 &pos->member != (head); \
276 pos = llist_entry(pos->member.prev, typeof(*pos), member), \
277 prefetch(pos->member.prev))
278
285#define llist_for_each_entry_continue(pos, head, member) \
286 for (pos = llist_entry(pos->member.next, typeof(*pos), member), \
287 prefetch(pos->member.next); \
288 &pos->member != (head); \
289 pos = llist_entry(pos->member.next, typeof(*pos), member), \
290 prefetch(pos->member.next))
291
299#define llist_for_each_entry_safe(pos, n, head, member) \
300 for (pos = llist_entry((head)->next, typeof(*pos), member), \
301 n = llist_entry(pos->member.next, typeof(*pos), member); \
302 &pos->member != (head); \
303 pos = n, n = llist_entry(n->member.next, typeof(*n), member))
304
310#define llist_for_each_rcu(pos, head) \
311 for (pos = (head)->next, prefetch(pos->next); pos != (head); \
312 pos = pos->next, ({ smp_read_barrier_depends(); 0;}), prefetch(pos->next))
313
314#define __llist_for_each_rcu(pos, head) \
315 for (pos = (head)->next; pos != (head); \
316 pos = pos->next, ({ smp_read_barrier_depends(); 0;}))
317
325#define llist_for_each_safe_rcu(pos, n, head) \
326 for (pos = (head)->next, n = pos->next; pos != (head); \
327 pos = n, ({ smp_read_barrier_depends(); 0;}), n = pos->next)
328
335#define llist_for_each_entry_rcu(pos, head, member) \
336 for (pos = llist_entry((head)->next, typeof(*pos), member), \
337 prefetch(pos->member.next); \
338 &pos->member != (head); \
339 pos = llist_entry(pos->member.next, typeof(*pos), member), \
340 ({ smp_read_barrier_depends(); 0;}), \
341 prefetch(pos->member.next))
342
343
350#define llist_for_each_continue_rcu(pos, head) \
351 for ((pos) = (pos)->next, prefetch((pos)->next); (pos) != (head); \
352 (pos) = (pos)->next, ({ smp_read_barrier_depends(); 0;}), prefetch((pos)->next))
353
361static inline unsigned int llist_count(struct llist_head *head)
362{
363 struct llist_head *entry;
364 unsigned int i = 0;
365 llist_for_each(entry, head)
366 i++;
367 return i;
368}
369
#define LLIST_POISON1
Definition linuxlist.h:43
static void __llist_add(struct llist_head *_new, struct llist_head *prev, struct llist_head *next)
Insert a new entry between two known consecutive entries.
Definition linuxlist.h:72
static void llist_splice(struct llist_head *llist, struct llist_head *head)
Join two llists.
Definition linuxlist.h:189
static void llist_del_init(struct llist_head *entry)
Delete entry from linked list and reinitialize it.
Definition linuxlist.h:135
static void llist_move_tail(struct llist_head *llist, struct llist_head *head)
Delete from one llist and add as another's tail.
Definition linuxlist.h:155
static void llist_splice_init(struct llist_head *llist, struct llist_head *head)
join two llists and reinitialise the emptied llist.
Definition linuxlist.h:201
static void llist_add(struct llist_head *_new, struct llist_head *head)
add a new entry into a linked list (at head)
Definition linuxlist.h:89
static unsigned int llist_count(struct llist_head *head)
count nr of llist items by iterating.
Definition linuxlist.h:361
struct llist_head * next
Pointer to next and previous item.
Definition linuxlist.h:49
static int llist_empty(const struct llist_head *head)
Test whether a linked list is empty.
Definition linuxlist.h:166
static void llist_move(struct llist_head *llist, struct llist_head *head)
Delete from one llist and add as another's head.
Definition linuxlist.h:145
static void llist_del(struct llist_head *entry)
Delete entry from linked list.
Definition linuxlist.h:125
#define llist_for_each(pos, head)
Iterate over a linked list.
Definition linuxlist.h:222
static void llist_add_tail(struct llist_head *_new, struct llist_head *head)
add a new entry into a linked list (at tail)
Definition linuxlist.h:101
#define INIT_LLIST_HEAD(ptr)
initialize a llist_head to point back to self
Definition linuxlist.h:63
(double) linked list header structure
Definition linuxlist.h:47