X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6760cb07d6b57be16928d95339d71e57c4e24f36..4a858f824d2969b164b967ae3e320593af0a9f9d:/src/xbt/dict.c diff --git a/src/xbt/dict.c b/src/xbt/dict.c index 150bf69d00..8d9fa7e222 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -40,18 +40,6 @@ xbt_dict_t xbt_dict_new(void) { xbt_dict_t dict; - if (dict_mallocator == NULL) { - /* first run */ - dict_mallocator = xbt_mallocator_new(256, - dict_mallocator_new_f, - dict_mallocator_free_f, - dict_mallocator_reset_f); - dict_elm_mallocator = xbt_mallocator_new(256, - dict_elm_mallocator_new_f, - dict_elm_mallocator_free_f, - dict_elm_mallocator_reset_f); - } - dict = xbt_mallocator_get(dict_mallocator); dict->table_size = 127; dict->table = xbt_new0(xbt_dictelm_t, dict->table_size + 1); @@ -747,11 +735,33 @@ void xbt_dict_dump_sizes(xbt_dict_t dict) xbt_dynar_free(&sizes); } +/** + * Create the dict mallocators. + * This is an internal XBT function called during the lib initialization. + * It can be used several times to recreate the mallocator, for example when you switch to MC mode + */ +void xbt_dict_preinit(void) { + if (dict_mallocator != NULL) { + /* Already created. I guess we want to switch to MC mode, so kill the previously created mallocator */ + xbt_mallocator_free(dict_mallocator); + xbt_mallocator_free(dict_elm_mallocator); + } + + dict_mallocator = xbt_mallocator_new(256, + dict_mallocator_new_f, + dict_mallocator_free_f, + dict_mallocator_reset_f); + dict_elm_mallocator = xbt_mallocator_new(256, + dict_elm_mallocator_new_f, + dict_elm_mallocator_free_f, + dict_elm_mallocator_reset_f); +} + /** * Destroy the dict mallocators. - * This is an internal XBT function called by xbt_exit(). + * This is an internal XBT function during the lib initialization */ -void xbt_dict_exit(void) +void xbt_dict_postexit(void) { if (dict_mallocator != NULL) { xbt_mallocator_free(dict_mallocator);