69 #define LIST_HEAD_INIT(name) { &(name), &(name) } 72 #define LIST_HEAD(name) \ 73 struct list_head name = LIST_HEAD_INIT(name) 76 #define INIT_LIST_HEAD(ptr) do { \ 77 (ptr)->next = (ptr); (ptr)->prev = (ptr); \ 89 static inline void __list_add(
struct list_head * _new,
111 __list_add(_new, head, head->next);
126 __list_add(_new, head->prev, head);
138 static inline void __list_del(
struct list_head * prev,
152 __list_del(entry->prev, entry->next);
163 __list_del(entry->prev, entry->next);
164 INIT_LIST_HEAD(entry);
175 return head->next == head;
186 #define list_entry(ptr, type, member) \ 187 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) 195 #define list_for_each(pos, head) \ 196 for (pos = (head)->next; pos != (head); pos = pos->next) 205 #define list_for_each_safe(pos, n, head) \ 206 for (pos = (head)->next, n = pos->next; pos != (head); \ 207 pos = n, n = pos->next) 216 #define list_for_each_ex(pos, head, begin) \ 217 for (pos = (begin)->next; pos != (head); pos = (pos)->next) 228 #define list_for_index(pos, i, head, index) \ 229 for (pos = (head)->next, i=0; (pos != (head) && i < index); pos = pos->next,i++) 232 static inline int list_add_by_index(
struct list_head *_new,
struct list_head *head,
int index)
238 for (pos = (head)->next, i=0; (pos != (head) && i < index); pos = pos->next,i++);
246 #define GETBY_EX(func, head, entrytype, member, datatype, ret, equal_cond) \ 247 void* func (datatype data) \ 253 list_for_each(me, head) { \ 254 pdata = list_entry(me, entrytype, member); \ 261 #define GET_LIST_BY_DATA(func, head, entrytype, member, datamember, datatype) \ 262 GETBY_EX(func, head, entrytype, member, datatype, me, (pdata->datamember == data)) 264 #define GET_ENTRY_BY_DATA(func, head, entrytype, member, datamember, datatype) \ 265 GETBY_EX(func, head, entrytype, member, datatype, pdata, (pdata->datamember == data)) 268 #define GET_LIST_BY_STRING(func, head, entrytype, member, datamember, datatype) \ 269 GETBY_EX(func, head, entrytype, member, datatype, me, (strcmp(pdata->datamember,data)==0)) 271 #define GET_ENTRY_BY_STRING(func, head, entrytype, member, datamember, datatype) \ 272 GETBY_EX(func, head, entrytype, member, datatype, pdata, (strcmp(pdata->datamember,data)==0)) 275 #define GET_ENTRY_BY_INDEX(func, entrytype, member) \ 276 static inline entrytype* func (list_t *head, int index) \ 281 list_for_each(me, head) { \ 283 return list_entry(me, entrytype, member); \ 288 #define GET_ENTRY_INDEX(func, entrytype, member) \ 289 static inline int func (list_t *head, entrytype* entry) \ 294 list_for_each(me, head) { \ 295 if (entry == list_entry(me, entrytype, member)) \ static int list_empty(struct list_head *head)
Tests whether a list is empty.
static void list_add_tail(struct list_head *_new, struct list_head *head)
Add a _new entry, insert a _new entry before the specified head. This is useful for implementing queu...
static void list_add(struct list_head *_new, struct list_head *head)
Add a _new entry, insert a _new entry after the specified head. This is good for implementing stacks...
The structure of double linked list.
static void list_del_init(struct list_head *entry)
Deletes entry from list and reinitialize it.
static void list_del(struct list_head *entry)
Deletes entry from list. Note: list_empty on entry does not return true after this, the entry is in an undefined state.