Changeset 72ac106 in mainline


Ignore:
Timestamp:
2023-03-21T17:31:07Z (20 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3118355
Parents:
7cf5ddb
Message:

Add list_swap() for swapping lists

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/adt/list.h

    r7cf5ddb r72ac106  
    315315_NO_TRACE static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
    316316{
     317        if (part1 == NULL || part2 == NULL)
     318                return;
     319
    317320        part1->prev->next = part2;
    318321        part2->prev->next = part1;
     
    354357}
    355358
     359/** Swap the contents of two lists.
     360 *
     361 * @param list1
     362 * @param list2
     363 */
     364static inline void list_swap(list_t *list1, list_t *list2)
     365{
     366        link_t *first1 = list_first(list1);
     367        link_t *first2 = list_first(list2);
     368
     369        /* Detach both lists from their heads. */
     370        headless_list_split(&list1->head, first1);
     371        headless_list_split(&list2->head, first2);
     372
     373        /* Attach both lists to their new heads. */
     374        headless_list_concat(&list1->head, first2);
     375        headless_list_concat(&list2->head, first1);
     376}
     377
    356378/** Concatenate two lists
    357379 *
  • uspace/lib/c/include/adt/list.h

    r7cf5ddb r72ac106  
    332332_NO_TRACE static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
    333333{
     334        if (part1 == NULL || part2 == NULL)
     335                return;
     336
    334337        part1->prev->next = part2;
    335338        part2->prev->next = part1;
     
    371374}
    372375
     376/** Swap the contents of two lists.
     377 *
     378 * @param list1
     379 * @param list2
     380 */
     381static inline void list_swap(list_t *list1, list_t *list2)
     382{
     383        link_t *first1 = list_first(list1);
     384        link_t *first2 = list_first(list2);
     385
     386        /* Detach both lists from their heads. */
     387        headless_list_split(&list1->head, first1);
     388        headless_list_split(&list2->head, first2);
     389
     390        /* Attach both lists to their new heads. */
     391        headless_list_concat(&list1->head, first2);
     392        headless_list_concat(&list2->head, first1);
     393}
     394
    373395/** Concatenate two lists
    374396 *
Note: See TracChangeset for help on using the changeset viewer.