Add init function support to tsd members.
This will facilitate embedding tcache into tsd, which will require proper initialization cannot be done via the static initializer. Make tsd->rtree_ctx to be initialized via rtree_ctx_data_init().
This commit is contained in:
11
src/rtree.c
11
src/rtree.c
@@ -424,3 +424,14 @@ rtree_leaf_elm_witness_release(tsdn_t *tsdn, const rtree_t *rtree,
|
||||
witness_unlock(tsdn, witness);
|
||||
rtree_leaf_elm_witness_dalloc(tsdn_tsd(tsdn), witness, elm);
|
||||
}
|
||||
|
||||
bool
|
||||
rtree_ctx_data_init(rtree_ctx_t *ctx) {
|
||||
for (unsigned i = 0; i < RTREE_CTX_NCACHE; i++) {
|
||||
rtree_ctx_cache_elm_t *cache = &ctx->cache[i];
|
||||
cache->leafkey = RTREE_LEAFKEY_INVALID;
|
||||
cache->leaf = NULL;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
19
src/tsd.c
19
src/tsd.c
@@ -60,6 +60,23 @@ malloc_tsd_cleanup_register(bool (*f)(void)) {
|
||||
ncleanups++;
|
||||
}
|
||||
|
||||
bool
|
||||
tsd_data_init(void *arg) {
|
||||
tsd_t *tsd = (tsd_t *)arg;
|
||||
#define MALLOC_TSD_init_yes(n, t) \
|
||||
if (n##_data_init(&tsd->n)) { \
|
||||
return true; \
|
||||
}
|
||||
#define MALLOC_TSD_init_no(n, t)
|
||||
#define O(n, t, gs, i, c) \
|
||||
MALLOC_TSD_init_##i(n, t)
|
||||
MALLOC_TSD
|
||||
#undef MALLOC_TSD_init_yes
|
||||
#undef MALLOC_TSD_init_no
|
||||
#undef O
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
tsd_cleanup(void *arg) {
|
||||
tsd_t *tsd = (tsd_t *)arg;
|
||||
@@ -72,7 +89,7 @@ tsd_cleanup(void *arg) {
|
||||
#define MALLOC_TSD_cleanup_yes(n, t) \
|
||||
n##_cleanup(tsd);
|
||||
#define MALLOC_TSD_cleanup_no(n, t)
|
||||
#define O(n, t, gs, c) \
|
||||
#define O(n, t, gs, i, c) \
|
||||
MALLOC_TSD_cleanup_##c(n, t)
|
||||
MALLOC_TSD
|
||||
#undef MALLOC_TSD_cleanup_yes
|
||||
|
Reference in New Issue
Block a user