Split rtree_elm_t into rtree_{node,leaf}_elm_t.

This allows leaf elements to differ in size from internal node elements.

In principle it would be more correct to use a different type for each
level of the tree, but due to implementation details related to atomic
operations, we use casts anyway, thus counteracting the value of
additional type correctness.  Furthermore, such a scheme would require
function code generation (via cpp macros), as well as either unwieldy
type names for leaves or type aliases, e.g.

  typedef struct rtree_elm_d2_s rtree_leaf_elm_t;

This alternate strategy would be more correct, and with less code
duplication, but probably not worth the complexity.
This commit is contained in:
Jason Evans
2017-03-16 09:46:42 -07:00
parent f50d6009fe
commit 944c8a3383
9 changed files with 459 additions and 258 deletions

View File

@@ -1,18 +1,21 @@
#ifndef JEMALLOC_INTERNAL_RTREE_STRUCTS_H
#define JEMALLOC_INTERNAL_RTREE_STRUCTS_H
struct rtree_elm_s {
/* Either "rtree_elm_t *child;" or "extent_t *extent;". */
atomic_p_t child_or_extent;
struct rtree_node_elm_s {
atomic_p_t child;
};
struct rtree_elm_witness_s {
const rtree_elm_t *elm;
struct rtree_leaf_elm_s {
atomic_p_t extent;
};
struct rtree_leaf_elm_witness_s {
const rtree_leaf_elm_t *elm;
witness_t witness;
};
struct rtree_elm_witness_tsd_s {
rtree_elm_witness_t witnesses[RTREE_ELM_ACQUIRE_MAX];
struct rtree_leaf_elm_witness_tsd_s {
rtree_leaf_elm_witness_t witnesses[RTREE_ELM_ACQUIRE_MAX];
};
struct rtree_level_s {
@@ -26,8 +29,8 @@ struct rtree_level_s {
};
struct rtree_ctx_cache_elm_s {
uintptr_t leafkey;
rtree_elm_t *leaf;
uintptr_t leafkey;
rtree_leaf_elm_t *leaf;
};
struct rtree_ctx_s {
@@ -38,7 +41,7 @@ struct rtree_ctx_s {
};
struct rtree_s {
/* An rtree_elm_t *. */
/* An rtree_{internal,leaf}_elm_t *. */
atomic_p_t root;
malloc_mutex_t init_lock;
};