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


Ignore:
Timestamp:
2019-06-27T08:51:20Z (7 years ago)
Author:
Jaroslav Jindrak <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8add15e0
Parents:
ad40b74b (diff), aeba767 (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:

cpp: merge and resolve conflicts

File:
1 edited

Legend:

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

    rad40b74b rbc73be3  
    3434 */
    3535
    36 #ifndef LIBC_LIST_H_
    37 #define LIBC_LIST_H_
     36#ifndef _LIBC_LIST_H_
     37#define _LIBC_LIST_H_
    3838
    3939#include <assert.h>
     
    4242#include <stdint.h>
    4343#include <trace.h>
    44 
    45 /** Doubly linked list link. */
    46 typedef struct link {
    47         struct link *prev;  /**< Pointer to the previous item in the list. */
    48         struct link *next;  /**< Pointer to the next item in the list. */
    49 } link_t;
    50 
    51 /** Doubly linked list. */
    52 typedef struct list {
    53         link_t head;  /**< List head. Does not have any data. */
    54 } list_t;
    55 
    56 extern bool list_member(const link_t *, const list_t *);
    57 extern void list_splice(list_t *, link_t *);
    58 extern unsigned long list_count(const list_t *);
     44#include <_bits/decls.h>
     45
     46#ifndef __cplusplus
     47
     48/**
     49 * We don't define the macros in C++ to avoid polluting headers with
     50 * namespaceless names. We don't actually need them, so this is fine.
     51 * We still allow including the rest of the file (in `helenos` namespace)
     52 * so that we can expose publicly visible types that have list_t members.
     53 */
    5954
    6055/** Declare and initialize statically allocated list.
     
    138133        assert(!link_used(link))
    139134
     135#define list_pop(list, type, member) \
     136        ((type *) list_pop_internal(list, \
     137            (list_link_to_void(&(((type *) NULL)->member)) - NULL)))
     138
     139#endif  /* !__cplusplus */
     140
     141__HELENOS_DECLS_BEGIN;
     142
     143/** Doubly linked list link. */
     144typedef struct __adt_list_link {
     145        struct __adt_list_link *prev;  /**< Pointer to the previous item in the list. */
     146        struct __adt_list_link *next;  /**< Pointer to the next item in the list. */
     147} link_t;
     148
     149/** Doubly linked list. */
     150typedef struct {
     151        link_t head;  /**< List head. Does not have any data. */
     152} list_t;
     153
     154extern bool list_member(const link_t *, const list_t *);
     155extern void list_splice(list_t *, link_t *);
     156extern unsigned long list_count(const list_t *);
     157
    140158/** Returns true if the link is definitely part of a list. False if not sure. */
    141159static inline bool link_in_use(const link_t *link)
     
    151169 *
    152170 */
    153 NO_TRACE static inline void link_initialize(link_t *link)
     171_NO_TRACE static inline void link_initialize(link_t *link)
    154172{
    155173        link->prev = NULL;
     
    164182 *
    165183 */
    166 NO_TRACE static inline void list_initialize(list_t *list)
     184_NO_TRACE static inline void list_initialize(list_t *list)
    167185{
    168186        list->head.prev = &list->head;
     
    200218 *
    201219 */
    202 NO_TRACE static inline void list_prepend(link_t *link, list_t *list)
     220_NO_TRACE static inline void list_prepend(link_t *link, list_t *list)
    203221{
    204222        list_insert_after(link, &list->head);
     
    213231 *
    214232 */
    215 NO_TRACE static inline void list_append(link_t *link, list_t *list)
     233_NO_TRACE static inline void list_append(link_t *link, list_t *list)
    216234{
    217235        list_insert_before(link, &list->head);
     
    226244 *
    227245 */
    228 NO_TRACE static inline void list_remove(link_t *link)
     246_NO_TRACE static inline void list_remove(link_t *link)
    229247{
    230248        if ((link->prev != NULL) && (link->next != NULL)) {
     
    243261 *
    244262 */
    245 NO_TRACE static inline bool list_empty(const list_t *list)
     263_NO_TRACE static inline bool list_empty(const list_t *list)
    246264{
    247265        return (list->head.next == &list->head);
     
    311329 *
    312330 */
    313 NO_TRACE static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
     331_NO_TRACE static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
    314332{
    315333        part1->prev->next = part2;
     
    332350 *
    333351 */
    334 NO_TRACE static inline void headless_list_split(link_t *part1, link_t *part2)
     352_NO_TRACE static inline void headless_list_split(link_t *part1, link_t *part2)
    335353{
    336354        headless_list_split_or_concat(part1, part2);
     
    347365 *
    348366 */
    349 NO_TRACE static inline void headless_list_concat(link_t *part1, link_t *part2)
     367_NO_TRACE static inline void headless_list_concat(link_t *part1, link_t *part2)
    350368{
    351369        headless_list_split_or_concat(part1, part2);
     
    362380 *
    363381 */
    364 NO_TRACE static inline void list_concat(list_t *list1, list_t *list2)
     382_NO_TRACE static inline void list_concat(list_t *list1, list_t *list2)
    365383{
    366384        list_splice(list2, list1->head.prev);
     
    425443}
    426444
    427 #define list_pop(list, type, member) \
    428         ((type *) list_pop_internal(list, \
    429             (list_link_to_void(&(((type *) NULL)->member)) - NULL)))
     445__HELENOS_DECLS_END;
    430446
    431447#endif
Note: See TracChangeset for help on using the changeset viewer.