forked from lichao2014/fcontext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.h
53 lines (42 loc) · 1.48 KB
/
list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef _LIST_H_INCLUDED
#define _LIST_H_INCLUDED
#ifndef offsetof
#define offsetof(type, member) ((size_t)&((type *)NULL)->member)
#endif
#ifndef container_of
#define container_of(ptr, type, member) (type *)((char *)ptr - offsetof(type, member))
#endif
struct list_node_t {
struct list_node_t *prev;
struct list_node_t *next;
};
typedef struct list_node_t list_t;
#define list_init(L) \
do { \
(L)->prev = (L); \
(L)->next = (L); \
} while (0)
#define list_empty(L) ((L)->next == (L))
#define list_push_back(L, other) \
do { \
(other)->next = (L); \
(other)->prev = (L)->prev; \
(L)->prev->next = (other); \
(L)->prev = (other); \
} while (0)
#define list_push_front(L, other) \
do { \
(other)->next = (L)->next; \
(other)->prev = (L); \
(L)->next->prev = (other); \
(L)->next = (other); \
} while (0)
#define list_erase(node) \
do { \
(node)->prev->next = (node)->next; \
(node)->next->prev = (node)->prev; \
(node)->prev = NULL; \
(node)->next = NULL; \
} while (0)
#define list_of(ptr, type, member) container_of(ptr, type, member)
#endif //!_LIST_H_INCLUDED