Linux 5.0.8
[linux/fpc-iii.git] / scripts / kconfig / list.h
blob45cb237ab7ef7a9f17779647220da6a30afd06fc
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LIST_H
3 #define LIST_H
5 /*
6 * Copied from include/linux/...
7 */
9 #undef offsetof
10 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
12 /**
13 * container_of - cast a member of a structure out to the containing structure
14 * @ptr: the pointer to the member.
15 * @type: the type of the container struct this is embedded in.
16 * @member: the name of the member within the struct.
19 #define container_of(ptr, type, member) ({ \
20 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
21 (type *)( (char *)__mptr - offsetof(type,member) );})
24 struct list_head {
25 struct list_head *next, *prev;
29 #define LIST_HEAD_INIT(name) { &(name), &(name) }
31 #define LIST_HEAD(name) \
32 struct list_head name = LIST_HEAD_INIT(name)
34 /**
35 * list_entry - get the struct for this entry
36 * @ptr: the &struct list_head pointer.
37 * @type: the type of the struct this is embedded in.
38 * @member: the name of the list_head within the struct.
40 #define list_entry(ptr, type, member) \
41 container_of(ptr, type, member)
43 /**
44 * list_for_each_entry - iterate over list of given type
45 * @pos: the type * to use as a loop cursor.
46 * @head: the head for your list.
47 * @member: the name of the list_head within the struct.
49 #define list_for_each_entry(pos, head, member) \
50 for (pos = list_entry((head)->next, typeof(*pos), member); \
51 &pos->member != (head); \
52 pos = list_entry(pos->member.next, typeof(*pos), member))
54 /**
55 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
56 * @pos: the type * to use as a loop cursor.
57 * @n: another type * to use as temporary storage
58 * @head: the head for your list.
59 * @member: the name of the list_head within the struct.
61 #define list_for_each_entry_safe(pos, n, head, member) \
62 for (pos = list_entry((head)->next, typeof(*pos), member), \
63 n = list_entry(pos->member.next, typeof(*pos), member); \
64 &pos->member != (head); \
65 pos = n, n = list_entry(n->member.next, typeof(*n), member))
67 /**
68 * list_empty - tests whether a list is empty
69 * @head: the list to test.
71 static inline int list_empty(const struct list_head *head)
73 return head->next == head;
77 * Insert a new entry between two known consecutive entries.
79 * This is only for internal list manipulation where we know
80 * the prev/next entries already!
82 static inline void __list_add(struct list_head *_new,
83 struct list_head *prev,
84 struct list_head *next)
86 next->prev = _new;
87 _new->next = next;
88 _new->prev = prev;
89 prev->next = _new;
92 /**
93 * list_add_tail - add a new entry
94 * @new: new entry to be added
95 * @head: list head to add it before
97 * Insert a new entry before the specified head.
98 * This is useful for implementing queues.
100 static inline void list_add_tail(struct list_head *_new, struct list_head *head)
102 __list_add(_new, head->prev, head);
106 * Delete a list entry by making the prev/next entries
107 * point to each other.
109 * This is only for internal list manipulation where we know
110 * the prev/next entries already!
112 static inline void __list_del(struct list_head *prev, struct list_head *next)
114 next->prev = prev;
115 prev->next = next;
118 #define LIST_POISON1 ((void *) 0x00100100)
119 #define LIST_POISON2 ((void *) 0x00200200)
121 * list_del - deletes entry from list.
122 * @entry: the element to delete from the list.
123 * Note: list_empty() on entry does not return true after this, the entry is
124 * in an undefined state.
126 static inline void list_del(struct list_head *entry)
128 __list_del(entry->prev, entry->next);
129 entry->next = (struct list_head*)LIST_POISON1;
130 entry->prev = (struct list_head*)LIST_POISON2;
132 #endif