1 | #ifndef JEMALLOC_INTERNAL_TYPED_LIST_H |
2 | #define JEMALLOC_INTERNAL_TYPED_LIST_H |
3 | |
4 | /* |
5 | * This wraps the ql module to implement a list class in a way that's a little |
6 | * bit easier to use; it handles ql_elm_new calls and provides type safety. |
7 | */ |
8 | |
9 | #define TYPED_LIST(list_type, el_type, linkage) \ |
10 | typedef struct { \ |
11 | ql_head(el_type) head; \ |
12 | } list_type##_t; \ |
13 | static inline void \ |
14 | list_type##_init(list_type##_t *list) { \ |
15 | ql_new(&list->head); \ |
16 | } \ |
17 | static inline el_type * \ |
18 | list_type##_first(const list_type##_t *list) { \ |
19 | return ql_first(&list->head); \ |
20 | } \ |
21 | static inline el_type * \ |
22 | list_type##_last(const list_type##_t *list) { \ |
23 | return ql_last(&list->head, linkage); \ |
24 | } \ |
25 | static inline void \ |
26 | list_type##_append(list_type##_t *list, el_type *item) { \ |
27 | ql_elm_new(item, linkage); \ |
28 | ql_tail_insert(&list->head, item, linkage); \ |
29 | } \ |
30 | static inline void \ |
31 | list_type##_prepend(list_type##_t *list, el_type *item) { \ |
32 | ql_elm_new(item, linkage); \ |
33 | ql_head_insert(&list->head, item, linkage); \ |
34 | } \ |
35 | static inline void \ |
36 | list_type##_replace(list_type##_t *list, el_type *to_remove, \ |
37 | el_type *to_insert) { \ |
38 | ql_elm_new(to_insert, linkage); \ |
39 | ql_after_insert(to_remove, to_insert, linkage); \ |
40 | ql_remove(&list->head, to_remove, linkage); \ |
41 | } \ |
42 | static inline void \ |
43 | list_type##_remove(list_type##_t *list, el_type *item) { \ |
44 | ql_remove(&list->head, item, linkage); \ |
45 | } \ |
46 | static inline bool \ |
47 | list_type##_empty(list_type##_t *list) { \ |
48 | return ql_empty(&list->head); \ |
49 | } \ |
50 | static inline void \ |
51 | list_type##_concat(list_type##_t *list_a, list_type##_t *list_b) { \ |
52 | ql_concat(&list_a->head, &list_b->head, linkage); \ |
53 | } |
54 | |
55 | #endif /* JEMALLOC_INTERNAL_TYPED_LIST_H */ |
56 | |