diff --git a/include/jemalloc/internal/edata.h b/include/jemalloc/internal/edata.h index ac8d647e..58bddd1a 100644 --- a/include/jemalloc/internal/edata.h +++ b/include/jemalloc/internal/edata.h @@ -10,6 +10,7 @@ #include "jemalloc/internal/sc.h" #include "jemalloc/internal/slab_data.h" #include "jemalloc/internal/sz.h" +#include "jemalloc/internal/typed_list.h" enum extent_state_e { extent_state_active = 0, @@ -58,7 +59,6 @@ struct edata_map_info_s { /* Extent (span of pages). Use accessor functions for e_* fields. */ typedef struct edata_s edata_t; -typedef ql_head(edata_t) edata_list_t; typedef ph(edata_t) edata_tree_t; typedef ph(edata_t) edata_heap_t; struct edata_s { @@ -209,6 +209,8 @@ struct edata_s { }; }; +TYPED_LIST(edata_list, edata_t, ql_link) + static inline unsigned edata_arena_ind_get(const edata_t *edata) { unsigned arena_ind = (unsigned)((edata->e_bits & @@ -531,7 +533,6 @@ edata_init(edata_t *edata, unsigned arena_ind, void *addr, size_t size, edata_zeroed_set(edata, zeroed); edata_committed_set(edata, committed); edata_ranged_set(edata, ranged); - ql_elm_new(edata, ql_link); edata_is_head_set(edata, is_head == EXTENT_IS_HEAD); if (config_prof) { edata_prof_tctx_set(edata, NULL); @@ -552,43 +553,6 @@ edata_binit(edata_t *edata, void *addr, size_t bsize, size_t sn) { edata_ranged_set(edata, false); } -static inline void -edata_list_init(edata_list_t *list) { - ql_new(list); -} - -static inline edata_t * -edata_list_first(const edata_list_t *list) { - return ql_first(list); -} - -static inline edata_t * -edata_list_last(const edata_list_t *list) { - return ql_last(list, ql_link); -} - -static inline void -edata_list_append(edata_list_t *list, edata_t *edata) { - ql_tail_insert(list, edata, ql_link); -} - -static inline void -edata_list_prepend(edata_list_t *list, edata_t *edata) { - ql_head_insert(list, edata, ql_link); -} - -static inline void -edata_list_replace(edata_list_t *list, edata_t *to_remove, - edata_t *to_insert) { - ql_after_insert(to_remove, to_insert, ql_link); - ql_remove(list, to_remove, ql_link); -} - -static inline void -edata_list_remove(edata_list_t *list, edata_t *edata) { - ql_remove(list, edata, ql_link); -} - static inline int edata_sn_comp(const edata_t *a, const edata_t *b) { size_t a_sn = edata_sn_get(a); diff --git a/include/jemalloc/internal/typed_list.h b/include/jemalloc/internal/typed_list.h new file mode 100644 index 00000000..7ad2237f --- /dev/null +++ b/include/jemalloc/internal/typed_list.h @@ -0,0 +1,47 @@ +#ifndef JEMALLOC_INTERNAL_TYPED_LIST_H +#define JEMALLOC_INTERNAL_TYPED_LIST_H + +/* + * This wraps the ql module to implement a list class in a way that's a little + * bit easier to use; it handles ql_elm_new calls and provides type safety. + */ + +#define TYPED_LIST(list_type, el_type, linkage) \ +typedef struct { \ + ql_head(el_type) head; \ +} list_type##_t; \ +static inline void \ +list_type##_init(list_type##_t *list) { \ + ql_new(&list->head); \ +} \ +static inline el_type * \ +list_type##_first(const list_type##_t *list) { \ + return ql_first(&list->head); \ +} \ +static inline el_type * \ +list_type##_last(const list_type##_t *list) { \ + return ql_last(&list->head, linkage); \ +} \ +static inline void \ +list_type##_append(list_type##_t *list, el_type *item) { \ + ql_elm_new(item, linkage); \ + ql_tail_insert(&list->head, item, linkage); \ +} \ +static inline void \ +list_type##_prepend(list_type##_t *list, el_type *item) { \ + ql_elm_new(item, linkage); \ + ql_head_insert(&list->head, item, linkage); \ +} \ +static inline void \ +list_type##_replace(list_type##_t *list, el_type *to_remove, \ + el_type *to_insert) { \ + ql_elm_new(to_insert, linkage); \ + ql_after_insert(to_remove, to_insert, linkage); \ + ql_remove(&list->head, to_remove, linkage); \ +} \ +static inline void \ +list_type##_remove(list_type##_t *list, el_type *item) { \ + ql_remove(&list->head, item, linkage); \ +} + +#endif /* JEMALLOC_INTERNAL_TYPED_LIST_H */