From aa252590f8b8836497d92ebda9afd9a8fa192e13 Mon Sep 17 00:00:00 2001 From: mquinson Date: Sat, 8 May 2010 14:32:49 +0000 Subject: [PATCH] The mallocators of dict and fifo are created in pre-init, ie before we know whether to use MC. So, tell these guys to recreate their mallocators when switching to MC so that they really use a desactivated mallocator in that case git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7725 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/surf/surf_config.c | 4 ++++ src/xbt/dict.c | 36 +++++++++++++++++++++++------------- src/xbt/fifo.c | 6 ++++++ src/xbt/xbt_main.c | 1 + src/xbt_modinter.h | 1 + 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index 68fb17efe1..455a5a92e3 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -142,10 +142,14 @@ static void _surf_cfg_cb__surf_path(const char *name, int pos) { } /* callback to decide if we want to use the model-checking */ +#include "xbt_modinter.h" int _surf_do_model_check = 0; /* this variable is used accros the lib */ static void _surf_cfg_cb_model_check(const char *name, int pos) { _surf_do_model_check = 1; + /* Tell modules using mallocators that they shouldn't. MC don't like them */ + xbt_fifo_preinit(); + xbt_dict_preinit(); } #ifdef HAVE_GTNETS diff --git a/src/xbt/dict.c b/src/xbt/dict.c index d71f11b4f9..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,9 +735,31 @@ 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_postexit(void) { diff --git a/src/xbt/fifo.c b/src/xbt/fifo.c index f2f95ca958..a11b4168bb 100644 --- a/src/xbt/fifo.c +++ b/src/xbt/fifo.c @@ -507,8 +507,14 @@ xbt_fifo_item_t xbt_fifo_getPrevItem(xbt_fifo_item_t i) /* Module init/exit handling the fifo item mallocator * These are internal XBT functions called by xbt_preinit/postexit(). + * It can be used several times to recreate the mallocator, for example when you switch to MC mode */ void xbt_fifo_preinit(void) { + if (item_mallocator != NULL) { + /* Already created. I guess we want to switch to MC mode, so kill the previously created mallocator */ + xbt_mallocator_free(item_mallocator); + } + item_mallocator = xbt_mallocator_new(256, fifo_item_mallocator_new_f, fifo_item_mallocator_free_f, diff --git a/src/xbt/xbt_main.c b/src/xbt/xbt_main.c index df635b1584..16d5d75033 100644 --- a/src/xbt/xbt_main.c +++ b/src/xbt/xbt_main.c @@ -107,6 +107,7 @@ static void xbt_preinit(void) { XBT_LOG_CONNECT(xbt_sync_os, xbt); xbt_fifo_preinit(); + xbt_dict_preinit(); xbt_backtrace_preinit(); xbt_os_thread_mod_preinit(); diff --git a/src/xbt_modinter.h b/src/xbt_modinter.h index 425a010c97..ad4100a7a9 100644 --- a/src/xbt_modinter.h +++ b/src/xbt_modinter.h @@ -20,6 +20,7 @@ void xbt_log_postexit(void); void xbt_fifo_preinit(void); void xbt_fifo_postexit(void); +void xbt_dict_preinit(void); void xbt_dict_postexit(void); void xbt_os_thread_mod_preinit(void); -- 2.20.1