memory/jemalloc/src/src/rtree.c

Thu, 15 Jan 2015 21:13:52 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:13:52 +0100
branch
TOR_BUG_9701
changeset 12
7540298fafa1
permissions
-rw-r--r--

Remove forgotten relic of ABI crash risk averse overloaded method change.

michael@0 1 #define JEMALLOC_RTREE_C_
michael@0 2 #include "jemalloc/internal/jemalloc_internal.h"
michael@0 3
michael@0 4 rtree_t *
michael@0 5 rtree_new(unsigned bits)
michael@0 6 {
michael@0 7 rtree_t *ret;
michael@0 8 unsigned bits_per_level, height, i;
michael@0 9
michael@0 10 bits_per_level = ffs(pow2_ceil((RTREE_NODESIZE / sizeof(void *)))) - 1;
michael@0 11 height = bits / bits_per_level;
michael@0 12 if (height * bits_per_level != bits)
michael@0 13 height++;
michael@0 14 assert(height * bits_per_level >= bits);
michael@0 15
michael@0 16 ret = (rtree_t*)base_alloc(offsetof(rtree_t, level2bits) +
michael@0 17 (sizeof(unsigned) * height));
michael@0 18 if (ret == NULL)
michael@0 19 return (NULL);
michael@0 20 memset(ret, 0, offsetof(rtree_t, level2bits) + (sizeof(unsigned) *
michael@0 21 height));
michael@0 22
michael@0 23 if (malloc_mutex_init(&ret->mutex)) {
michael@0 24 /* Leak the rtree. */
michael@0 25 return (NULL);
michael@0 26 }
michael@0 27 ret->height = height;
michael@0 28 if (bits_per_level * height > bits)
michael@0 29 ret->level2bits[0] = bits % bits_per_level;
michael@0 30 else
michael@0 31 ret->level2bits[0] = bits_per_level;
michael@0 32 for (i = 1; i < height; i++)
michael@0 33 ret->level2bits[i] = bits_per_level;
michael@0 34
michael@0 35 ret->root = (void**)base_alloc(sizeof(void *) << ret->level2bits[0]);
michael@0 36 if (ret->root == NULL) {
michael@0 37 /*
michael@0 38 * We leak the rtree here, since there's no generic base
michael@0 39 * deallocation.
michael@0 40 */
michael@0 41 return (NULL);
michael@0 42 }
michael@0 43 memset(ret->root, 0, sizeof(void *) << ret->level2bits[0]);
michael@0 44
michael@0 45 return (ret);
michael@0 46 }
michael@0 47
michael@0 48 void
michael@0 49 rtree_prefork(rtree_t *rtree)
michael@0 50 {
michael@0 51
michael@0 52 malloc_mutex_prefork(&rtree->mutex);
michael@0 53 }
michael@0 54
michael@0 55 void
michael@0 56 rtree_postfork_parent(rtree_t *rtree)
michael@0 57 {
michael@0 58
michael@0 59 malloc_mutex_postfork_parent(&rtree->mutex);
michael@0 60 }
michael@0 61
michael@0 62 void
michael@0 63 rtree_postfork_child(rtree_t *rtree)
michael@0 64 {
michael@0 65
michael@0 66 malloc_mutex_postfork_child(&rtree->mutex);
michael@0 67 }

mercurial