Changes in kernel/generic/include/adt/list.h [b76ce3f:e98f1c3e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/list.h
rb76ce3f re98f1c3e 37 37 #define KERN_LIST_H_ 38 38 39 #include <assert.h> 40 #include <stdbool.h> 41 #include <stddef.h> 39 #include <debug.h> 40 #include <typedefs.h> 42 41 #include <trace.h> 43 42 … … 53 52 } list_t; 54 53 54 55 55 extern bool list_member(const link_t *, const list_t *); 56 56 extern void list_splice(list_t *, link_t *); 57 57 extern unsigned long list_count(const list_t *); 58 58 59 59 60 /** Declare and initialize statically allocated list. 60 61 * … … 63 64 */ 64 65 #define LIST_INITIALIZE(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 { \ 66 list_t name = { \ 84 67 .head = { \ 85 68 .prev = &(name).head, \ … … 104 87 105 88 /** Unlike list_foreach(), allows removing items while traversing a list. 106 * 89 * 107 90 * @code 108 91 * list_t mylist; … … 134 117 iterator = next_iter, next_iter = iterator->next) 135 118 119 136 120 #define assert_link_not_used(link) \ 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 } 121 ASSERT(!link_used(link)) 144 122 145 123 /** Initialize doubly-linked circular list link … … 268 246 * 269 247 */ 270 static inline link_t *list_last( constlist_t *list)271 { 272 return ( list->head.prev == &list->head) ? NULL : list->head.prev;248 static inline link_t *list_last(list_t *list) 249 { 250 return ((list->head.prev == &list->head) ? NULL : list->head.prev); 273 251 } 274 252 … … 280 258 * @return Next item or NULL if @a link is the last item. 281 259 */ 282 static inline link_t *list_next( constlink_t *link, const list_t *list)260 static inline link_t *list_next(link_t *link, const list_t *list) 283 261 { 284 262 return (link->next == &list->head) ? NULL : link->next; … … 292 270 * @return Previous item or NULL if @a link is the first item. 293 271 */ 294 static inline link_t *list_prev( constlink_t *link, const list_t *list)272 static inline link_t *list_prev(link_t *link, const list_t *list) 295 273 { 296 274 return (link->prev == &list->head) ? NULL : link->prev; … … 375 353 * 376 354 */ 377 static inline link_t *list_nth( constlist_t *list, unsigned long n)355 static inline link_t *list_nth(list_t *list, unsigned long n) 378 356 { 379 357 unsigned long cnt = 0; 380 381 link_t *link = list_first(list); 358 link_t *link; 359 360 link = list_first(list); 382 361 while (link != NULL) { 383 362 if (cnt == n) … … 410 389 return false; 411 390 412 assert(link->prev != NULL && link->next != NULL);391 ASSERT(link->prev != NULL && link->next != NULL); 413 392 return true; 414 393 }
Note:
See TracChangeset
for help on using the changeset viewer.