]>
git.saurik.com Git - redis.git/blob - deps/jemalloc/src/rtree.c
1 #define JEMALLOC_RTREE_C_
2 #include "jemalloc/internal/jemalloc_internal.h"
5 rtree_new(unsigned bits
)
8 unsigned bits_per_level
, height
, i
;
10 bits_per_level
= ffs(pow2_ceil((RTREE_NODESIZE
/ sizeof(void *)))) - 1;
11 height
= bits
/ bits_per_level
;
12 if (height
* bits_per_level
!= bits
)
14 assert(height
* bits_per_level
>= bits
);
16 ret
= (rtree_t
*)base_alloc(offsetof(rtree_t
, level2bits
) +
17 (sizeof(unsigned) * height
));
20 memset(ret
, 0, offsetof(rtree_t
, level2bits
) + (sizeof(unsigned) *
23 if (malloc_mutex_init(&ret
->mutex
)) {
28 if (bits_per_level
* height
> bits
)
29 ret
->level2bits
[0] = bits
% bits_per_level
;
31 ret
->level2bits
[0] = bits_per_level
;
32 for (i
= 1; i
< height
; i
++)
33 ret
->level2bits
[i
] = bits_per_level
;
35 ret
->root
= (void**)base_alloc(sizeof(void *) << ret
->level2bits
[0]);
36 if (ret
->root
== NULL
) {
38 * We leak the rtree here, since there's no generic base
43 memset(ret
->root
, 0, sizeof(void *) << ret
->level2bits
[0]);
49 rtree_prefork(rtree_t
*rtree
)
52 malloc_mutex_prefork(&rtree
->mutex
);
56 rtree_postfork_parent(rtree_t
*rtree
)
59 malloc_mutex_postfork_parent(&rtree
->mutex
);
63 rtree_postfork_child(rtree_t
*rtree
)
66 malloc_mutex_postfork_child(&rtree
->mutex
);