Changeset 95c675b in mainline for uspace/lib/c/include/adt/list.h


Ignore:
Timestamp:
2017-10-17T13:11:35Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
60af4cdb
Parents:
dbf32b1 (diff), a416d070 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/adt/list.h

    rdbf32b1 r95c675b  
    4040#include <stdbool.h>
    4141#include <stddef.h>
     42#include <trace.h>
    4243
    4344/** Doubly linked list link. */
     
    5152        link_t head;  /**< List head. Does not have any data. */
    5253} list_t;
     54
     55extern bool list_member(const link_t *, const list_t *);
     56extern void list_splice(list_t *, link_t *);
     57extern unsigned long list_count(const list_t *);
    5358
    5459/** Declare and initialize statically allocated list.
     
    8893#define list_foreach(list, member, itype, iterator) \
    8994        for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \
    90             for (link_t *_link = (list).head.next; \
    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)
    9398
    9499#define list_foreach_rev(list, member, itype, iterator) \
    95100        for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \
    96             for (link_t *_link = (list).head.prev; \
    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)
    99104
    100105/** Unlike list_foreach(), allows removing items while traversing a list.
     
    125130#define list_foreach_safe(list, iterator, next_iter) \
    126131        for (link_t *iterator = (list).head.next, \
    127                 *next_iter = iterator->next; \
    128                 iterator != &(list).head; \
    129                 iterator = next_iter, next_iter = iterator->next)
     132            *next_iter = iterator->next; \
     133            iterator != &(list).head; \
     134            iterator = next_iter, next_iter = iterator->next)
    130135
    131136#define assert_link_not_used(link) \
     
    145150 *
    146151 */
    147 static inline void link_initialize(link_t *link)
     152NO_TRACE static inline void link_initialize(link_t *link)
    148153{
    149154        link->prev = NULL;
     
    158163 *
    159164 */
    160 static inline void list_initialize(list_t *list)
     165NO_TRACE static inline void list_initialize(list_t *list)
    161166{
    162167        list->head.prev = &list->head;
     
    194199 *
    195200 */
    196 static inline void list_prepend(link_t *link, list_t *list)
     201NO_TRACE static inline void list_prepend(link_t *link, list_t *list)
    197202{
    198203        list_insert_after(link, &list->head);
     
    207212 *
    208213 */
    209 static inline void list_append(link_t *link, list_t *list)
     214NO_TRACE static inline void list_append(link_t *link, list_t *list)
    210215{
    211216        list_insert_before(link, &list->head);
     
    220225 *
    221226 */
    222 static inline void list_remove(link_t *link)
     227NO_TRACE static inline void list_remove(link_t *link)
    223228{
    224229        if ((link->prev != NULL) && (link->next != NULL)) {
     
    237242 *
    238243 */
    239 static inline bool list_empty(const list_t *list)
     244NO_TRACE static inline bool list_empty(const list_t *list)
    240245{
    241246        return (list->head.next == &list->head);
     
    274279 *
    275280 * @return Next item or NULL if @a link is the last item.
    276  *
    277281 */
    278282static inline link_t *list_next(const link_t *link, const list_t *list)
     
    287291 *
    288292 * @return Previous item or NULL if @a link is the first item.
    289  *
    290293 */
    291294static inline link_t *list_prev(const link_t *link, const list_t *list)
     
    307310 *
    308311 */
    309 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
     312NO_TRACE static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
    310313{
    311314        part1->prev->next = part2;
     
    328331 *
    329332 */
    330 static inline void headless_list_split(link_t *part1, link_t *part2)
     333NO_TRACE static inline void headless_list_split(link_t *part1, link_t *part2)
    331334{
    332335        headless_list_split_or_concat(part1, part2);
     
    343346 *
    344347 */
    345 static inline void headless_list_concat(link_t *part1, link_t *part2)
     348NO_TRACE static inline void headless_list_concat(link_t *part1, link_t *part2)
    346349{
    347350        headless_list_split_or_concat(part1, part2);
     351}
     352
     353/** Concatenate two lists
     354 *
     355 * Concatenate lists @a list1 and @a list2, producing a single
     356 * list @a list1 containing items from both (in @a list1, @a list2
     357 * order) and empty list @a list2.
     358 *
     359 * @param list1         First list and concatenated output
     360 * @param list2         Second list and empty output.
     361 *
     362 */
     363NO_TRACE static inline void list_concat(list_t *list1, list_t *list2)
     364{
     365        list_splice(list2, list1->head.prev);
    348366}
    349367
     
    396414}
    397415
    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 
    402416#endif
    403417
Note: See TracChangeset for help on using the changeset viewer.