Rev 2089 | Rev 2446 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2089 | Rev 2106 | ||
---|---|---|---|
Line 45... | Line 45... | ||
45 | 45 | ||
46 | /** Declare and initialize statically allocated list. |
46 | /** Declare and initialize statically allocated list. |
47 | * |
47 | * |
48 | * @param name Name of the new statically allocated list. |
48 | * @param name Name of the new statically allocated list. |
49 | */ |
49 | */ |
- | 50 | #define LIST_INITIALIZE(name) \ |
|
50 | #define LIST_INITIALIZE(name) link_t name = { .prev = &name, .next = &name } |
51 | link_t name = { .prev = &name, .next = &name } |
51 | 52 | ||
52 | /** Initialize doubly-linked circular list link |
53 | /** Initialize doubly-linked circular list link |
53 | * |
54 | * |
54 | * Initialize doubly-linked list link. |
55 | * Initialize doubly-linked list link. |
55 | * |
56 | * |
Line 105... | Line 106... | ||
105 | 106 | ||
106 | /** Remove item from doubly-linked circular list |
107 | /** Remove item from doubly-linked circular list |
107 | * |
108 | * |
108 | * Remove item from doubly-linked circular list. |
109 | * Remove item from doubly-linked circular list. |
109 | * |
110 | * |
110 | * @param link Pointer to link_t structure to be removed from the list it is contained in. |
111 | * @param link Pointer to link_t structure to be removed from the list it is |
- | 112 | * contained in. |
|
111 | */ |
113 | */ |
112 | static inline void list_remove(link_t *link) |
114 | static inline void list_remove(link_t *link) |
113 | { |
115 | { |
114 | link->next->prev = link->prev; |
116 | link->next->prev = link->prev; |
115 | link->prev->next = link->next; |
117 | link->prev->next = link->next; |
Line 133... | Line 135... | ||
133 | * Split or concatenate headless doubly-linked circular list. |
135 | * Split or concatenate headless doubly-linked circular list. |
134 | * |
136 | * |
135 | * Note that the algorithm works both directions: |
137 | * Note that the algorithm works both directions: |
136 | * concatenates splitted lists and splits concatenated lists. |
138 | * concatenates splitted lists and splits concatenated lists. |
137 | * |
139 | * |
138 | * @param part1 Pointer to link_t structure leading the first (half of the headless) list. |
140 | * @param part1 Pointer to link_t structure leading the first (half of the |
- | 141 | * headless) list. |
|
139 | * @param part2 Pointer to link_t structure leading the second (half of the headless) list. |
142 | * @param part2 Pointer to link_t structure leading the second (half of the |
- | 143 | * headless) list. |
|
140 | */ |
144 | */ |
141 | static inline void headless_list_split_or_concat(link_t *part1, link_t *part2) |
145 | static inline void headless_list_split_or_concat(link_t *part1, link_t *part2) |
142 | { |
146 | { |
143 | link_t *hlp; |
147 | link_t *hlp; |
144 | 148 | ||
Line 152... | Line 156... | ||
152 | 156 | ||
153 | /** Split headless doubly-linked circular list |
157 | /** Split headless doubly-linked circular list |
154 | * |
158 | * |
155 | * Split headless doubly-linked circular list. |
159 | * Split headless doubly-linked circular list. |
156 | * |
160 | * |
157 | * @param part1 Pointer to link_t structure leading the first half of the headless list. |
161 | * @param part1 Pointer to link_t structure leading the first half of the |
- | 162 | * headless list. |
|
158 | * @param part2 Pointer to link_t structure leading the second half of the headless list. |
163 | * @param part2 Pointer to link_t structure leading the second half of the |
- | 164 | * headless list. |
|
159 | */ |
165 | */ |
160 | static inline void headless_list_split(link_t *part1, link_t *part2) |
166 | static inline void headless_list_split(link_t *part1, link_t *part2) |
161 | { |
167 | { |
162 | headless_list_split_or_concat(part1, part2); |
168 | headless_list_split_or_concat(part1, part2); |
163 | } |
169 | } |
Line 165... | Line 171... | ||
165 | /** Concatenate two headless doubly-linked circular lists |
171 | /** Concatenate two headless doubly-linked circular lists |
166 | * |
172 | * |
167 | * Concatenate two headless doubly-linked circular lists. |
173 | * Concatenate two headless doubly-linked circular lists. |
168 | * |
174 | * |
169 | * @param part1 Pointer to link_t structure leading the first headless list. |
175 | * @param part1 Pointer to link_t structure leading the first headless list. |
170 | * @param part2 Pointer to link_t structure leading the second headless list. |
176 | * @param part2 Pointer to link_t structure leading the second headless list. |
171 | */ |
177 | */ |
172 | static inline void headless_list_concat(link_t *part1, link_t *part2) |
178 | static inline void headless_list_concat(link_t *part1, link_t *part2) |
173 | { |
179 | { |
174 | headless_list_split_or_concat(part1, part2); |
180 | headless_list_split_or_concat(part1, part2); |
175 | } |
181 | } |
176 | 182 | ||
- | 183 | #define list_get_instance(link,type,member) \ |
|
177 | #define list_get_instance(link,type,member) (type *)(((uint8_t*)(link))-((uint8_t*)&(((type *)NULL)->member))) |
184 | ((type *)(((uint8_t *)(link)) - ((uint8_t *)&(((type *)NULL)->member)))) |
178 | 185 | ||
179 | extern bool list_member(const link_t *link, const link_t *head); |
186 | extern bool list_member(const link_t *link, const link_t *head); |
180 | extern void list_concat(link_t *head1, link_t *head2); |
187 | extern void list_concat(link_t *head1, link_t *head2); |
181 | 188 | ||
182 | #endif |
189 | #endif |