| 1 |
struct list_head { |
| 2 |
struct list_head *next; |
| 3 |
}; |
| 4 |
|
| 5 |
#define LIST_HEAD(name) \ |
| 6 |
struct list_head name = { &(name) } |
| 7 |
|
| 8 |
static inline int list_empty(const struct list_head *head) |
| 9 |
{ |
| 10 |
return head->next == head; |
| 11 |
} |
| 12 |
|
| 13 |
static inline void list_add(struct list_head *new, struct list_head *head) |
| 14 |
{ |
| 15 |
new->next = head->next; |
| 16 |
head->next = new; |
| 17 |
} |
| 18 |
|
| 19 |
static inline void list_del(struct list_head *entry, struct list_head *prev) |
| 20 |
{ |
| 21 |
prev->next = entry->next; |
| 22 |
entry->next = entry; |
| 23 |
} |
| 24 |
|
| 25 |
#define list_for_each_safe(pos, n, head) \ |
| 26 |
for (n = (head), pos = (head)->next; pos != (head); \ |
| 27 |
n = pos, pos = n->next) |
| 28 |
|
| 29 |
#undef offsetof |
| 30 |
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
| 31 |
|
| 32 |
#define container_of(ptr, type, member) ({ \ |
| 33 |
const __typeof__( ((type *)0)->member ) *__mptr = (ptr);\ |
| 34 |
(type *)( (char *)__mptr - offsetof(type,member) );}) |
| 35 |
|
| 36 |
#ifdef DEBUG |
| 37 |
#define pynl_dbg(fmt, ...) \ |
| 38 |
fprintf(stderr, "%s: " fmt, __func__, __VA_ARGS__) |
| 39 |
#else |
| 40 |
#define pynl_dbg(fmt, ...) |
| 41 |
#endif |