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) \
10typedef struct { \
11 ql_head(el_type) head; \
12} list_type##_t; \
13static inline void \
14list_type##_init(list_type##_t *list) { \
15 ql_new(&list->head); \
16} \
17static inline el_type * \
18list_type##_first(const list_type##_t *list) { \
19 return ql_first(&list->head); \
20} \
21static inline el_type * \
22list_type##_last(const list_type##_t *list) { \
23 return ql_last(&list->head, linkage); \
24} \
25static inline void \
26list_type##_append(list_type##_t *list, el_type *item) { \
27 ql_elm_new(item, linkage); \
28 ql_tail_insert(&list->head, item, linkage); \
29} \
30static inline void \
31list_type##_prepend(list_type##_t *list, el_type *item) { \
32 ql_elm_new(item, linkage); \
33 ql_head_insert(&list->head, item, linkage); \
34} \
35static inline void \
36list_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} \
42static inline void \
43list_type##_remove(list_type##_t *list, el_type *item) { \
44 ql_remove(&list->head, item, linkage); \
45} \
46static inline bool \
47list_type##_empty(list_type##_t *list) { \
48 return ql_empty(&list->head); \
49} \
50static inline void \
51list_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