Changeset bc73be3 in mainline for uspace/lib/c/include/adt/list.h
- Timestamp:
- 2019-06-27T08:51:20Z (7 years ago)
- 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. - File:
-
- 1 edited
-
uspace/lib/c/include/adt/list.h (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/list.h
rad40b74b rbc73be3 34 34 */ 35 35 36 #ifndef LIBC_LIST_H_37 #define LIBC_LIST_H_36 #ifndef _LIBC_LIST_H_ 37 #define _LIBC_LIST_H_ 38 38 39 39 #include <assert.h> … … 42 42 #include <stdint.h> 43 43 #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 */ 59 54 60 55 /** Declare and initialize statically allocated list. … … 138 133 assert(!link_used(link)) 139 134 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. */ 144 typedef 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. */ 150 typedef struct { 151 link_t head; /**< List head. Does not have any data. */ 152 } list_t; 153 154 extern bool list_member(const link_t *, const list_t *); 155 extern void list_splice(list_t *, link_t *); 156 extern unsigned long list_count(const list_t *); 157 140 158 /** Returns true if the link is definitely part of a list. False if not sure. */ 141 159 static inline bool link_in_use(const link_t *link) … … 151 169 * 152 170 */ 153 NO_TRACE static inline void link_initialize(link_t *link)171 _NO_TRACE static inline void link_initialize(link_t *link) 154 172 { 155 173 link->prev = NULL; … … 164 182 * 165 183 */ 166 NO_TRACE static inline void list_initialize(list_t *list)184 _NO_TRACE static inline void list_initialize(list_t *list) 167 185 { 168 186 list->head.prev = &list->head; … … 200 218 * 201 219 */ 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) 203 221 { 204 222 list_insert_after(link, &list->head); … … 213 231 * 214 232 */ 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) 216 234 { 217 235 list_insert_before(link, &list->head); … … 226 244 * 227 245 */ 228 NO_TRACE static inline void list_remove(link_t *link)246 _NO_TRACE static inline void list_remove(link_t *link) 229 247 { 230 248 if ((link->prev != NULL) && (link->next != NULL)) { … … 243 261 * 244 262 */ 245 NO_TRACE static inline bool list_empty(const list_t *list)263 _NO_TRACE static inline bool list_empty(const list_t *list) 246 264 { 247 265 return (list->head.next == &list->head); … … 311 329 * 312 330 */ 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) 314 332 { 315 333 part1->prev->next = part2; … … 332 350 * 333 351 */ 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) 335 353 { 336 354 headless_list_split_or_concat(part1, part2); … … 347 365 * 348 366 */ 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) 350 368 { 351 369 headless_list_split_or_concat(part1, part2); … … 362 380 * 363 381 */ 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) 365 383 { 366 384 list_splice(list2, list1->head.prev); … … 425 443 } 426 444 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; 430 446 431 447 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
