WIP FPC-III support
[linux/fpc-iii.git] / tools / usb / usbip / libsrc / list.h
bloba941671e4900d8ab34db78607e221ef600c5ac2e
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LIST_H
3 #define _LIST_H
5 /* Stripped down implementation of linked list taken
6 * from the Linux Kernel.
7 */
9 /*
10 * Simple doubly linked list implementation.
12 * Some of the internal functions ("__xxx") are useful when
13 * manipulating whole lists rather than single entries, as
14 * sometimes we already know the next/prev entries and we can
15 * generate better code by using them directly rather than
16 * using the generic single-entry routines.
19 struct list_head {
20 struct list_head *next, *prev;
23 #define LIST_HEAD_INIT(name) { &(name), &(name) }
25 #define LIST_HEAD(name) \
26 struct list_head name = LIST_HEAD_INIT(name)
28 static inline void INIT_LIST_HEAD(struct list_head *list)
30 list->next = list;
31 list->prev = list;
35 * Insert a new entry between two known consecutive entries.
37 * This is only for internal list manipulation where we know
38 * the prev/next entries already!
40 static inline void __list_add(struct list_head *new,
41 struct list_head *prev,
42 struct list_head *next)
44 next->prev = new;
45 new->next = next;
46 new->prev = prev;
47 prev->next = new;
50 /**
51 * list_add - add a new entry
52 * @new: new entry to be added
53 * @head: list head to add it after
55 * Insert a new entry after the specified head.
56 * This is good for implementing stacks.
58 static inline void list_add(struct list_head *new, struct list_head *head)
60 __list_add(new, head, head->next);
64 * Delete a list entry by making the prev/next entries
65 * point to each other.
67 * This is only for internal list manipulation where we know
68 * the prev/next entries already!
70 static inline void __list_del(struct list_head * prev, struct list_head * next)
72 next->prev = prev;
73 prev->next = next;
76 #define POISON_POINTER_DELTA 0
77 #define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
78 #define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80 /**
81 * list_del - deletes entry from list.
82 * @entry: the element to delete from the list.
83 * Note: list_empty() on entry does not return true after this, the entry is
84 * in an undefined state.
86 static inline void __list_del_entry(struct list_head *entry)
88 __list_del(entry->prev, entry->next);
91 static inline void list_del(struct list_head *entry)
93 __list_del(entry->prev, entry->next);
94 entry->next = LIST_POISON1;
95 entry->prev = LIST_POISON2;
98 /**
99 * list_entry - get the struct for this entry
100 * @ptr: the &struct list_head pointer.
101 * @type: the type of the struct this is embedded in.
102 * @member: the name of the list_head within the struct.
104 #define list_entry(ptr, type, member) \
105 container_of(ptr, type, member)
107 * list_for_each - iterate over a list
108 * @pos: the &struct list_head to use as a loop cursor.
109 * @head: the head for your list.
111 #define list_for_each(pos, head) \
112 for (pos = (head)->next; pos != (head); pos = pos->next)
115 * list_for_each_safe - iterate over a list safe against removal of list entry
116 * @pos: the &struct list_head to use as a loop cursor.
117 * @n: another &struct list_head to use as temporary storage
118 * @head: the head for your list.
120 #define list_for_each_safe(pos, n, head) \
121 for (pos = (head)->next, n = pos->next; pos != (head); \
122 pos = n, n = pos->next)
124 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
127 * container_of - cast a member of a structure out to the containing structure
128 * @ptr: the pointer to the member.
129 * @type: the type of the container struct this is embedded in.
130 * @member: the name of the member within the struct.
133 #define container_of(ptr, type, member) ({ \
134 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
135 (type *)( (char *)__mptr - offsetof(type,member) );})
137 #endif