~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/usb/usbip/libsrc/list.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LIST_H
  3 #define _LIST_H
  4 
  5 /* Stripped down implementation of linked list taken
  6  * from the Linux Kernel.
  7  */
  8 
  9 /*
 10  * Simple doubly linked list implementation.
 11  *
 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.
 17  */
 18 
 19 struct list_head {
 20         struct list_head *next, *prev;
 21 };
 22 
 23 #define LIST_HEAD_INIT(name) { &(name), &(name) }
 24 
 25 #define LIST_HEAD(name) \
 26         struct list_head name = LIST_HEAD_INIT(name)
 27 
 28 static inline void INIT_LIST_HEAD(struct list_head *list)
 29 {
 30         list->next = list;
 31         list->prev = list;
 32 }
 33 
 34 /*
 35  * Insert a new entry between two known consecutive entries.
 36  *
 37  * This is only for internal list manipulation where we know
 38  * the prev/next entries already!
 39  */
 40 static inline void __list_add(struct list_head *new,
 41                               struct list_head *prev,
 42                               struct list_head *next)
 43 {
 44         next->prev = new;
 45         new->next = next;
 46         new->prev = prev;
 47         prev->next = new;
 48 }
 49 
 50 /**
 51  * list_add - add a new entry
 52  * @new: new entry to be added
 53  * @head: list head to add it after
 54  *
 55  * Insert a new entry after the specified head.
 56  * This is good for implementing stacks.
 57  */
 58 static inline void list_add(struct list_head *new, struct list_head *head)
 59 {
 60         __list_add(new, head, head->next);
 61 }
 62 
 63 /*
 64  * Delete a list entry by making the prev/next entries
 65  * point to each other.
 66  *
 67  * This is only for internal list manipulation where we know
 68  * the prev/next entries already!
 69  */
 70 static inline void __list_del(struct list_head * prev, struct list_head * next)
 71 {
 72         next->prev = prev;
 73         prev->next = next;
 74 }
 75 
 76 #define POISON_POINTER_DELTA 0
 77 #define LIST_POISON1  ((void *) 0x00100100 + POISON_POINTER_DELTA)
 78 #define LIST_POISON2  ((void *) 0x00200200 + POISON_POINTER_DELTA)
 79 
 80 static inline void __list_del_entry(struct list_head *entry)
 81 {
 82         __list_del(entry->prev, entry->next);
 83 }
 84 
 85 /**
 86  * list_del - deletes entry from list.
 87  * @entry: the element to delete from the list.
 88  * Note: list_empty() on entry does not return true after this, the entry is
 89  * in an undefined state.
 90  */
 91 static inline void list_del(struct list_head *entry)
 92 {
 93         __list_del(entry->prev, entry->next);
 94         entry->next = LIST_POISON1;
 95         entry->prev = LIST_POISON2;
 96 }
 97 
 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.
103  */
104 #define list_entry(ptr, type, member) \
105         container_of(ptr, type, member)
106 /**
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.
110  */
111 #define list_for_each(pos, head) \
112         for (pos = (head)->next; pos != (head); pos = pos->next)
113 
114 /**
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.
119  */
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)
123 
124 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
125 
126 /**
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.
131  *
132  */
133 #define container_of(ptr, type, member) ({                      \
134         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
135         (type *)( (char *)__mptr - offsetof(type,member) );})
136 
137 #endif
138 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php