Changeset b76ce3f in mainline
- Timestamp:
- 2017-06-27T16:52:59Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 30eab78
- Parents:
- 9e7615d
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/list.h
r9e7615d rb76ce3f 53 53 } list_t; 54 54 55 56 55 extern bool list_member(const link_t *, const list_t *); 57 56 extern void list_splice(list_t *, link_t *); 58 57 extern unsigned long list_count(const list_t *); 59 58 60 61 59 /** Declare and initialize statically allocated list. 62 60 * … … 65 63 */ 66 64 #define LIST_INITIALIZE(name) \ 67 list_t name = { \ 65 list_t name = LIST_INITIALIZER(name) 66 67 /** Initializer for statically allocated list. 68 * 69 * @code 70 * struct named_list { 71 * const char *name; 72 * list_t list; 73 * } var = { 74 * .name = "default name", 75 * .list = LIST_INITIALIZER(name_list.list) 76 * }; 77 * @endcode 78 * 79 * @param name Name of the new statically allocated list. 80 * 81 */ 82 #define LIST_INITIALIZER(name) \ 83 { \ 68 84 .head = { \ 69 85 .prev = &(name).head, \ … … 88 104 89 105 /** Unlike list_foreach(), allows removing items while traversing a list. 90 * 106 * 91 107 * @code 92 108 * list_t mylist; … … 118 134 iterator = next_iter, next_iter = iterator->next) 119 135 120 121 136 #define assert_link_not_used(link) \ 122 137 assert(!link_used(link)) 138 139 /** Returns true if the link is definitely part of a list. False if not sure. */ 140 static inline bool link_in_use(const link_t *link) 141 { 142 return link->prev != NULL && link->next != NULL; 143 } 123 144 124 145 /** Initialize doubly-linked circular list link … … 247 268 * 248 269 */ 249 static inline link_t *list_last( list_t *list)250 { 251 return ( (list->head.prev == &list->head) ? NULL : list->head.prev);270 static inline link_t *list_last(const list_t *list) 271 { 272 return (list->head.prev == &list->head) ? NULL : list->head.prev; 252 273 } 253 274 … … 259 280 * @return Next item or NULL if @a link is the last item. 260 281 */ 261 static inline link_t *list_next( link_t *link, const list_t *list)282 static inline link_t *list_next(const link_t *link, const list_t *list) 262 283 { 263 284 return (link->next == &list->head) ? NULL : link->next; … … 271 292 * @return Previous item or NULL if @a link is the first item. 272 293 */ 273 static inline link_t *list_prev( link_t *link, const list_t *list)294 static inline link_t *list_prev(const link_t *link, const list_t *list) 274 295 { 275 296 return (link->prev == &list->head) ? NULL : link->prev; … … 354 375 * 355 376 */ 356 static inline link_t *list_nth( list_t *list, unsigned long n)377 static inline link_t *list_nth(const list_t *list, unsigned long n) 357 378 { 358 379 unsigned long cnt = 0; 359 link_t *link;360 380 361 link = list_first(list);381 link_t *link = list_first(list); 362 382 while (link != NULL) { 363 383 if (cnt == n) -
uspace/lib/c/include/adt/list.h
r9e7615d rb76ce3f 40 40 #include <stdbool.h> 41 41 #include <stddef.h> 42 #include <trace.h> 42 43 43 44 /** Doubly linked list link. */ … … 51 52 link_t head; /**< List head. Does not have any data. */ 52 53 } list_t; 54 55 extern bool list_member(const link_t *, const list_t *); 56 extern void list_concat(list_t *, list_t *); 57 extern unsigned long list_count(const list_t *); 53 58 54 59 /** Declare and initialize statically allocated list. … … 88 93 #define list_foreach(list, member, itype, iterator) \ 89 94 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 90 91 iterator = list_get_instance(_link, itype, member), \92 _link != &(list).head; _link = _link->next)95 for (link_t *_link = (list).head.next; \ 96 iterator = list_get_instance(_link, itype, member), \ 97 _link != &(list).head; _link = _link->next) 93 98 94 99 #define list_foreach_rev(list, member, itype, iterator) \ 95 100 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 96 97 iterator = list_get_instance(_link, itype, member), \98 _link != &(list).head; _link = _link->prev)101 for (link_t *_link = (list).head.prev; \ 102 iterator = list_get_instance(_link, itype, member), \ 103 _link != &(list).head; _link = _link->prev) 99 104 100 105 /** Unlike list_foreach(), allows removing items while traversing a list. … … 125 130 #define list_foreach_safe(list, iterator, next_iter) \ 126 131 for (link_t *iterator = (list).head.next, \ 127 128 129 132 *next_iter = iterator->next; \ 133 iterator != &(list).head; \ 134 iterator = next_iter, next_iter = iterator->next) 130 135 131 136 #define assert_link_not_used(link) \ … … 145 150 * 146 151 */ 147 static inline void link_initialize(link_t *link)152 NO_TRACE static inline void link_initialize(link_t *link) 148 153 { 149 154 link->prev = NULL; … … 158 163 * 159 164 */ 160 static inline void list_initialize(list_t *list)165 NO_TRACE static inline void list_initialize(list_t *list) 161 166 { 162 167 list->head.prev = &list->head; … … 194 199 * 195 200 */ 196 static inline void list_prepend(link_t *link, list_t *list)201 NO_TRACE static inline void list_prepend(link_t *link, list_t *list) 197 202 { 198 203 list_insert_after(link, &list->head); … … 207 212 * 208 213 */ 209 static inline void list_append(link_t *link, list_t *list)214 NO_TRACE static inline void list_append(link_t *link, list_t *list) 210 215 { 211 216 list_insert_before(link, &list->head); … … 220 225 * 221 226 */ 222 static inline void list_remove(link_t *link)227 NO_TRACE static inline void list_remove(link_t *link) 223 228 { 224 229 if ((link->prev != NULL) && (link->next != NULL)) { … … 237 242 * 238 243 */ 239 static inline bool list_empty(const list_t *list)244 NO_TRACE static inline bool list_empty(const list_t *list) 240 245 { 241 246 return (list->head.next == &list->head); … … 274 279 * 275 280 * @return Next item or NULL if @a link is the last item. 276 *277 281 */ 278 282 static inline link_t *list_next(const link_t *link, const list_t *list) … … 287 291 * 288 292 * @return Previous item or NULL if @a link is the first item. 289 *290 293 */ 291 294 static inline link_t *list_prev(const link_t *link, const list_t *list) … … 307 310 * 308 311 */ 309 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)312 NO_TRACE static inline void headless_list_split_or_concat(link_t *part1, link_t *part2) 310 313 { 311 314 part1->prev->next = part2; … … 328 331 * 329 332 */ 330 static inline void headless_list_split(link_t *part1, link_t *part2)333 NO_TRACE static inline void headless_list_split(link_t *part1, link_t *part2) 331 334 { 332 335 headless_list_split_or_concat(part1, part2); … … 343 346 * 344 347 */ 345 static inline void headless_list_concat(link_t *part1, link_t *part2)348 NO_TRACE static inline void headless_list_concat(link_t *part1, link_t *part2) 346 349 { 347 350 headless_list_split_or_concat(part1, part2); … … 396 399 } 397 400 398 extern bool list_member(const link_t *, const list_t *);399 extern void list_concat(list_t *, list_t *);400 extern unsigned long list_count(const list_t *);401 401 402 402 #endif
Note:
See TracChangeset
for help on using the changeset viewer.