| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef LIST_H |
| 25 |
#define LIST_H |
| 26 |
|
| 27 |
#ifndef NULL |
| 28 |
#include <stddef.h> |
| 29 |
#endif |
| 30 |
|
| 31 |
struct list_head { |
| 32 |
struct list_head *prev; |
| 33 |
struct list_head *next; |
| 34 |
}; |
| 35 |
|
| 36 |
#define LIST_HEAD_INIT(el) { &(el), &(el) } |
| 37 |
|
| 38 |
|
| 39 |
#define list_entry(el, type, member) container_of(el, type, member) |
| 40 |
|
| 41 |
static inline void init_list_head(struct list_head *head) |
| 42 |
{ |
| 43 |
head->prev = head; |
| 44 |
head->next = head; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
static inline void __list_add(struct list_head *el, |
| 49 |
struct list_head *prev, struct list_head *next) |
| 50 |
{ |
| 51 |
prev->next = el; |
| 52 |
el->prev = prev; |
| 53 |
el->next = next; |
| 54 |
next->prev = el; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
static inline void list_add(struct list_head *el, struct list_head *head) |
| 59 |
{ |
| 60 |
__list_add(el, head, head->next); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
static inline void list_add_tail(struct list_head *el, struct list_head *head) |
| 65 |
{ |
| 66 |
__list_add(el, head->prev, head); |
| 67 |
} |
| 68 |
|
| 69 |
static inline void list_del(struct list_head *el) |
| 70 |
{ |
| 71 |
struct list_head *prev, *next; |
| 72 |
prev = el->prev; |
| 73 |
next = el->next; |
| 74 |
prev->next = next; |
| 75 |
next->prev = prev; |
| 76 |
el->prev = NULL; |
| 77 |
el->next = NULL; |
| 78 |
} |
| 79 |
|
| 80 |
static inline int list_empty(struct list_head *el) |
| 81 |
{ |
| 82 |
return el->next == el; |
| 83 |
} |
| 84 |
|
| 85 |
#define list_for_each(el, head) \ |
| 86 |
for(el = (head)->next; el != (head); el = el->next) |
| 87 |
|
| 88 |
#define list_for_each_safe(el, el1, head) \ |
| 89 |
for(el = (head)->next, el1 = el->next; el != (head); \ |
| 90 |
el = el1, el1 = el->next) |
| 91 |
|
| 92 |
#define list_for_each_prev(el, head) \ |
| 93 |
for(el = (head)->prev; el != (head); el = el->prev) |
| 94 |
|
| 95 |
#define list_for_each_prev_safe(el, el1, head) \ |
| 96 |
for(el = (head)->prev, el1 = el->prev; el != (head); \ |
| 97 |
el = el1, el1 = el->prev) |
| 98 |
|
| 99 |
#endif |