Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6865 | serge | 1 | #ifndef __LINK_H__ |
2 | #define __LINK_H__ |
||
3 | |||
4 | typedef struct link |
||
5 | { |
||
6 | struct link *prev; |
||
7 | struct link *next; |
||
8 | }link_t; |
||
9 | |||
10 | #define LIST_INITIALIZE(name) \ |
||
11 | link_t name = { .prev = &name, .next = &name } |
||
12 | |||
13 | #define list_get_instance(link, type, member) \ |
||
14 | ((type *)(((u8_t *)(link)) - ((u8_t *)&(((type *)NULL)->member)))) |
||
15 | |||
16 | static inline void link_initialize(link_t *link) |
||
17 | { |
||
18 | link->prev = NULL; |
||
19 | link->next = NULL; |
||
20 | } |
||
21 | |||
22 | static inline void list_initialize(link_t *head) |
||
23 | { |
||
24 | head->prev = head; |
||
25 | head->next = head; |
||
26 | } |
||
27 | |||
28 | static inline void list_append(link_t *link, link_t *head) |
||
29 | { |
||
30 | link->prev = head->prev; |
||
31 | link->next = head; |
||
32 | head->prev->next = link; |
||
33 | head->prev = link; |
||
34 | } |
||
35 | |||
36 | static inline void list_remove(link_t *link) |
||
37 | { |
||
38 | link->next->prev = link->prev; |
||
39 | link->prev->next = link->next; |
||
40 | link_initialize(link); |
||
41 | } |
||
42 | |||
43 | static inline int list_empty(link_t *head) |
||
44 | { |
||
45 | return head->next == head ? 1 : 0; |
||
46 | } |
||
47 | |||
48 | static inline void list_prepend(link_t *link, link_t *head) |
||
49 | { |
||
50 | link->next = head->next; |
||
51 | link->prev = head; |
||
52 | head->next->prev = link; |
||
53 | head->next = link; |
||
54 | } |
||
55 | |||
56 | static inline void list_insert(link_t *new, link_t *old) |
||
57 | { |
||
58 | new->prev = old->prev; |
||
59 | new->next = old; |
||
60 | new->prev->next = new; |
||
61 | old->prev = new; |
||
62 | } |
||
63 | |||
64 | #endif /* __LINK_H__ */ |