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

TOMOYO Linux Cross Reference
Linux/scripts/kconfig/list.h

Version: ~ [ linux-5.15-rc5 ] ~ [ linux-5.14.11 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.72 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.152 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.210 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.250 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.286 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.288 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp