Changes in uspace/lib/c/include/adt/list.h [639db552:7856d09] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/list.h
r639db552 r7856d09 38 38 39 39 #include <assert.h> 40 #include <stdbool.h> 40 41 #include <unistd.h> 41 42 … … 72 73 iterator = list_get_instance(_link, itype, member), \ 73 74 _link != &(list).head; _link = _link->next) 75 76 #define list_foreach_rev(list, member, itype, iterator) \ 77 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 78 for (link_t *_link = (list).head.prev; \ 79 iterator = list_get_instance(_link, itype, member), \ 80 _link != &(list).head; _link = _link->prev) 74 81 75 82 /** Unlike list_foreach(), allows removing items while traversing a list. … … 105 112 106 113 #define assert_link_not_used(link) \ 107 assert( ((link)->prev == NULL) && ((link)->next == NULL))114 assert(!link_used(link)) 108 115 109 116 /** Returns true if the link is definitely part of a list. False if not sure. */ 110 static inline int link_in_use( constlink_t *link)117 static inline int link_in_use(link_t *link) 111 118 { 112 119 return link->prev != NULL && link->next != NULL; … … 238 245 * 239 246 */ 240 static inline link_t *list_last( constlist_t *list)247 static inline link_t *list_last(list_t *list) 241 248 { 242 249 return (list->head.prev == &list->head) ? NULL : list->head.prev; … … 251 258 * 252 259 */ 253 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) 254 261 { 255 262 return (link->next == &list->head) ? NULL : link->next; … … 264 271 * 265 272 */ 266 static inline link_t *list_prev( constlink_t *link, const list_t *list)273 static inline link_t *list_prev(link_t *link, const list_t *list) 267 274 { 268 275 return (link->prev == &list->head) ? NULL : link->prev; … … 332 339 * 333 340 */ 334 static inline link_t *list_nth( constlist_t *list, unsigned int n)341 static inline link_t *list_nth(list_t *list, unsigned int n) 335 342 { 336 343 unsigned int cnt = 0; … … 357 364 } 358 365 366 /** Determine if link is used. 367 * 368 * @param link Link 369 * @return @c true if link is used, @c false if not. 370 */ 371 static inline bool link_used(link_t *link) 372 { 373 if (link->prev == NULL && link->next == NULL) 374 return false; 375 376 assert(link->prev != NULL && link->next != NULL); 377 return true; 378 } 379 359 380 extern int list_member(const link_t *, const list_t *); 360 381 extern void list_concat(list_t *, list_t *);
Note:
See TracChangeset
for help on using the changeset viewer.