LMMS
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * Linux kernel header adapted for user-mode
4 * The 2.6.17-rt1 version was used.
5 *
6 * Original copyright holders of this code are unknown, they were not
7 * mentioned in the original file.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 *****************************************************************************/
23
24#ifndef LINUX_LIST_H_INCLUDED
25#define LINUX_LIST_H_INCLUDED
26
27/* This file is from Linux Kernel (include/linux/list.h)
28 * and modified by removing hardware prefetching of list items
29 * and added list_split_tail* functions.
30 *
31 * Here by copyright, credits attributed to wherever they belong.
32 * Filipe Coelho (aka falkTX <falktx@falktx.com>)
33 */
34
35#ifdef __cplusplus
36# include <cstddef>
37#else
38# include <stddef.h>
39#endif
40
41#ifndef offsetof
42# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
43#endif
44
52#define container_of(ptr, type, member) ({ \
53 typeof( ((type *)0)->member ) *__mptr = (ptr); \
54 (type *)( (char *)__mptr - offsetof(type, member) );})
55
56#define container_of_const(ptr, type, member) ({ \
57 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
58 (const type *)( (const char *)__mptr - offsetof(type, member) );})
59
60#define prefetch(x) (x = x)
61
62/*
63 * These are non-NULL pointers that will result in page faults
64 * under normal circumstances, used to verify that nobody uses
65 * non-initialized list entries.
66 */
67#define LIST_POISON1 ((void *) 0x00100100)
68#define LIST_POISON2 ((void *) 0x00200200)
69
70/*
71 * Simple doubly linked list implementation.
72 *
73 * Some of the internal functions ("__xxx") are useful when
74 * manipulating whole lists rather than single entries, as
75 * sometimes we already know the next/prev entries and we can
76 * generate better code by using them directly rather than
77 * using the generic single-entry routines.
78 */
79
80struct list_head {
81 struct list_head *next, *prev;
82};
83
84#define LIST_HEAD_INIT(name) { &(name), &(name) }
85
86#define LIST_HEAD(name) \
87 struct list_head name = LIST_HEAD_INIT(name)
88
89static inline void INIT_LIST_HEAD(struct list_head *list)
90{
91 list->next = list;
92 list->prev = list;
93}
94
95/*
96 * Insert a new entry between two known consecutive entries.
97 *
98 * This is only for internal list manipulation where we know
99 * the prev/next entries already!
100 */
101static inline void __list_add(struct list_head *new_, struct list_head *prev, struct list_head *next)
102{
103 next->prev = new_;
104 new_->next = next;
105 new_->prev = prev;
106 prev->next = new_;
107}
108
117static inline void list_add(struct list_head *new_, struct list_head *head)
118{
119 __list_add(new_, head, head->next);
120}
121
130static inline void list_add_tail(struct list_head *new_, struct list_head *head)
131{
132 __list_add(new_, head->prev, head);
133}
134
135/*
136 * Delete a list entry by making the prev/next entries
137 * point to each other.
138 *
139 * This is only for internal list manipulation where we know
140 * the prev/next entries already!
141 */
142static inline void __list_del(struct list_head *prev, struct list_head *next)
143{
144 next->prev = prev;
145 prev->next = next;
146}
147
154static inline void list_del(struct list_head *entry)
155{
156 __list_del(entry->prev, entry->next);
157 entry->next = (struct list_head*)LIST_POISON1;
158 entry->prev = (struct list_head*)LIST_POISON2;
159}
160
165static inline void list_del_init(struct list_head *entry)
166{
167 __list_del(entry->prev, entry->next);
168 INIT_LIST_HEAD(entry);
169}
170
176static inline void list_move(struct list_head *list, struct list_head *head)
177{
178 __list_del(list->prev, list->next);
179 list_add(list, head);
180}
181
187static inline void list_move_tail(struct list_head *list, struct list_head *head)
188{
189 __list_del(list->prev, list->next);
190 list_add_tail(list, head);
191}
192
197static inline int list_empty(const struct list_head *head)
198{
199 return head->next == head;
200}
201
214static inline int list_empty_careful(const struct list_head *head)
215{
216 struct list_head *next = head->next;
217 return (next == head) && (next == head->prev);
218}
219
220static inline void __list_splice(struct list_head *list, struct list_head *head)
221{
222 struct list_head *first = list->next;
223 struct list_head *last = list->prev;
224 struct list_head *at = head->next;
225
226 first->prev = head;
227 head->next = first;
228
229 last->next = at;
230 at->prev = last;
231}
232
233static inline void __list_splice_tail(struct list_head *list, struct list_head *head)
234{
235 struct list_head *first = list->next;
236 struct list_head *last = list->prev;
237 struct list_head *at = head->prev;
238
239 first->prev = at;
240 at->next = first;
241
242 last->next = head;
243 head->prev = last;
244}
245
251static inline void list_splice(struct list_head *list, struct list_head *head)
252{
253 if (!list_empty(list))
254 __list_splice(list, head);
255}
256
264static inline void list_splice_tail(struct list_head *list, struct list_head *head)
265{
266 if (!list_empty(list))
268}
269
277static inline void list_splice_init(struct list_head *list, struct list_head *head)
278{
279 if (!list_empty(list)) {
280 __list_splice(list, head);
281 INIT_LIST_HEAD(list);
282 }
283}
284
293static inline void list_splice_tail_init(struct list_head *list, struct list_head *head)
294{
295 if (!list_empty(list)) {
297 INIT_LIST_HEAD(list);
298 }
299}
300
307#if (defined(__GNUC__) || defined(__clang__)) && ! defined(__STRICT_ANSI__)
308# define list_entry(ptr, type, member) \
309 container_of(ptr, type, member)
310# define list_entry_const(ptr, type, member) \
311 container_of_const(ptr, type, member)
312#else
313# define list_entry(ptr, type, member) \
314 ((type *)((char *)(ptr)-offsetof(type, member)))
315# define list_entry_const(ptr, type, member) \
316 ((const type *)((const char *)(ptr)-offsetof(type, member)))
317#endif
318
324#define list_for_each(pos, head) \
325 for (pos = (head)->next; prefetch(pos->next), pos != (head); \
326 pos = pos->next)
327
338#define __list_for_each(pos, head) \
339 for (pos = (head)->next; pos != (head); pos = pos->next)
340
346#define list_for_each_prev(pos, head) \
347 for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
348 pos = pos->prev)
349
356#define list_for_each_safe(pos, n, head) \
357 for (pos = (head)->next, n = pos->next; pos != (head); \
358 pos = n, n = pos->next)
359
366#define list_for_each_entry(pos, head, member) \
367 for (pos = list_entry((head)->next, typeof(*pos), member); \
368 prefetch(pos->member.next), &pos->member != (head); \
369 pos = list_entry(pos->member.next, typeof(*pos), member))
370
377#define list_for_each_entry_reverse(pos, head, member) \
378 for (pos = list_entry((head)->prev, typeof(*pos), member); \
379 prefetch(pos->member.prev), &pos->member != (head); \
380 pos = list_entry(pos->member.prev, typeof(*pos), member))
381
388#define list_prepare_entry(pos, head, member) \
389 ((pos) ? : list_entry(head, typeof(*pos), member))
390
397#define list_for_each_entry_continue(pos, head, member) \
398 for (pos = list_entry(pos->member.next, typeof(*pos), member); \
399 prefetch(pos->member.next), &pos->member != (head); \
400 pos = list_entry(pos->member.next, typeof(*pos), member))
401
408#define list_for_each_entry_from(pos, head, member) \
409 for (; prefetch(pos->member.next), &pos->member != (head); \
410 pos = list_entry(pos->member.next, typeof(*pos), member))
411
419#define list_for_each_entry_safe(pos, n, head, member) \
420 for (pos = list_entry((head)->next, typeof(*pos), member), \
421 n = list_entry(pos->member.next, typeof(*pos), member); \
422 &pos->member != (head); \
423 pos = n, n = list_entry(n->member.next, typeof(*n), member))
424
432#define list_for_each_entry_safe_continue(pos, n, head, member) \
433 for (pos = list_entry(pos->member.next, typeof(*pos), member), \
434 n = list_entry(pos->member.next, typeof(*pos), member); \
435 &pos->member != (head); \
436 pos = n, n = list_entry(n->member.next, typeof(*n), member))
437
445#define list_for_each_entry_safe_from(pos, n, head, member) \
446 for (n = list_entry(pos->member.next, typeof(*pos), member); \
447 &pos->member != (head); \
448 pos = n, n = list_entry(n->member.next, typeof(*n), member))
449
457#define list_for_each_entry_safe_reverse(pos, n, head, member) \
458 for (pos = list_entry((head)->prev, typeof(*pos), member), \
459 n = list_entry(pos->member.prev, typeof(*pos), member); \
460 &pos->member != (head); \
461 pos = n, n = list_entry(n->member.prev, typeof(*n), member))
462
463#endif // LINUX_LIST_H_INCLUDED
static void list_splice_tail_init(struct list_head *list, struct list_head *head)
Definition list.h:293
static void list_move_tail(struct list_head *list, struct list_head *head)
Definition list.h:187
static void __list_del(struct list_head *prev, struct list_head *next)
Definition list.h:142
static void __list_splice(struct list_head *list, struct list_head *head)
Definition list.h:220
static void list_splice(struct list_head *list, struct list_head *head)
Definition list.h:251
#define LIST_POISON2
Definition list.h:68
static void list_add_tail(struct list_head *new_, struct list_head *head)
Definition list.h:130
static void list_add(struct list_head *new_, struct list_head *head)
Definition list.h:117
static int list_empty(const struct list_head *head)
Definition list.h:197
static void list_splice_init(struct list_head *list, struct list_head *head)
Definition list.h:277
#define LIST_POISON1
Definition list.h:67
static void __list_add(struct list_head *new_, struct list_head *prev, struct list_head *next)
Definition list.h:101
static void list_del(struct list_head *entry)
Definition list.h:154
static int list_empty_careful(const struct list_head *head)
Definition list.h:214
static void list_del_init(struct list_head *entry)
Definition list.h:165
static void list_splice_tail(struct list_head *list, struct list_head *head)
Definition list.h:264
static void __list_splice_tail(struct list_head *list, struct list_head *head)
Definition list.h:233
static void INIT_LIST_HEAD(struct list_head *list)
Definition list.h:89
static void list_move(struct list_head *list, struct list_head *head)
Definition list.h:176
Definition misc.c:36
Definition list.h:80
struct list_head * prev
Definition list.h:81
struct list_head * next
Definition list.h:81