Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
The mallocators of dict and fifo are created in pre-init, ie before we know whether...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 8 May 2010 14:32:49 +0000 (14:32 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 8 May 2010 14:32:49 +0000 (14:32 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7725 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/surf/surf_config.c
src/xbt/dict.c
src/xbt/fifo.c
src/xbt/xbt_main.c
src/xbt_modinter.h

index 68fb17e..455a5a9 100644 (file)
@@ -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
index d71f11b..8d9fa7e 100644 (file)
@@ -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)
 {
index f2f95ca..a11b416 100644 (file)
@@ -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,
index df635b1..16d5d75 100644 (file)
@@ -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();
index 425a010..ad4100a 100644 (file)
@@ -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);