Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cleanup the way moddata are destroyed at the end of the time
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 14 Nov 2006 18:38:50 +0000 (18:38 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 14 Nov 2006 18:38:50 +0000 (18:38 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2930 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/Virtu/gras_module.c
src/gras/Virtu/process.c
src/gras/Virtu/virtu_interface.h
src/gras/gras.c

index 401742f..7f426c3 100644 (file)
@@ -125,12 +125,18 @@ void gras_module_add(const char *name, unsigned int datasize, int *ID,
   }
 
   if (found) {
   }
 
   if (found) {
-    xbt_assert1(mod->init_f == init_f, "Module %s reregistered with a different init_f!", name);
-    xbt_assert1(mod->exit_f == exit_f, "Module %s reregistered with a different exit_f!", name);
-    xbt_assert1(mod->join_f == join_f, "Module %s reregistered with a different join_f!", name);
-    xbt_assert1(mod->leave_f == leave_f, "Module %s reregistered with a different leave_f!", name);
-    xbt_assert1(mod->datasize == datasize, "Module %s reregistered with a different datasize!", name);
-    xbt_assert1(mod->p_id == ID, "Module %s reregistered with a different p_id field!", name);
+    xbt_assert1(mod->init_f == init_f, 
+               "Module %s reregistered with a different init_f!", name);
+    xbt_assert1(mod->exit_f == exit_f,
+               "Module %s reregistered with a different exit_f!", name);
+    xbt_assert1(mod->join_f == join_f,
+               "Module %s reregistered with a different join_f!", name);
+    xbt_assert1(mod->leave_f == leave_f,
+               "Module %s reregistered with a different leave_f!", name);
+    xbt_assert1(mod->datasize == datasize, 
+               "Module %s reregistered with a different datasize!", name);
+    xbt_assert1(mod->p_id == ID,
+               "Module %s reregistered with a different p_id field!", name);
     
     DEBUG1("Module %s already registered. Ignoring re-registration",name);
     return;
     
     DEBUG1("Module %s already registered. Ignoring re-registration",name);
     return;
@@ -154,14 +160,25 @@ void gras_module_add(const char *name, unsigned int datasize, int *ID,
   xbt_set_add(_gras_modules,(void*)mod,gras_module_freep);
 }
 
   xbt_set_add(_gras_modules,(void*)mod,gras_module_freep);
 }
 
-/* Removes & frees a moddata */
+/* shutdown the module mechanism (world-wide cleanups) */
+void gras_moddata_exit(void) {
+  xbt_set_free(&_gras_modules);
+}
+
+/* frees the moddata on this host (process-wide cleanups) */
+void gras_moddata_leave(void) {
+  gras_procdata_t *pd=gras_procdata_get();
+
+  xbt_dynar_free(&pd->moddata);
+}
+
+/* Removes & frees a given moddata from the current host */
 static void moddata_freep(void *p) {
   gras_procdata_t *pd=gras_procdata_get();
   int id = xbt_dynar_search (pd->moddata, p);
   gras_module_t mod = (gras_module_t)xbt_set_get_by_id(_gras_modules, id);
 
 static void moddata_freep(void *p) {
   gras_procdata_t *pd=gras_procdata_get();
   int id = xbt_dynar_search (pd->moddata, p);
   gras_module_t mod = (gras_module_t)xbt_set_get_by_id(_gras_modules, id);
 
-  (*mod->leave_f)(p);
-  free(p);
+  (*mod->leave_f)(gras_moddata_by_id(id));
 }
 
 void gras_module_join(const char *name) {
 }
 
 void gras_module_join(const char *name) {
@@ -186,8 +203,7 @@ void gras_module_join(const char *name) {
   /* JOIN */
   pd=gras_procdata_get();
 
   /* JOIN */
   pd=gras_procdata_get();
 
-
-  if (!pd->moddata) /* Damn. I must be the first module on this process. Scary ;) */
+  if (!pd->moddata) /* Damn. I must be the first module on this process. Scary ;)*/
     pd->moddata   = xbt_dynar_new(sizeof(gras_module_t),&moddata_freep);
 
   moddata = xbt_malloc(mod->datasize);
     pd->moddata   = xbt_dynar_new(sizeof(gras_module_t),&moddata_freep);
 
   moddata = xbt_malloc(mod->datasize);
index b620f84..f1883e6 100644 (file)
@@ -54,6 +54,7 @@ int gras_procdata_add(const char *name, pvoid_f_void_t constructor,void_f_pvoid_
    fab->name        = xbt_strdup(name);
    fab->constructor = constructor;
    fab->destructor  = destructor;
    fab->name        = xbt_strdup(name);
    fab->constructor = constructor;
    fab->destructor  = destructor;
+   
    return xbt_dynar_length(_gras_procdata_fabrics)-1;
 }
 
    return xbt_dynar_length(_gras_procdata_fabrics)-1;
 }
 
index 8aa2e75..f738c96 100644 (file)
 #include "gras/virtu.h"
 #include "gras/process.h"
 
 #include "gras/virtu.h"
 #include "gras/process.h"
 
+/* shutdown the module mechanism (world-wide cleanups) */
+XBT_PUBLIC void gras_moddata_exit(void);
+/* shutdown this process wrt module mecanism (process-wide cleanups) */
+XBT_PUBLIC void gras_moddata_leave(void);
+
+/* This is the old interface (deprecated) */
+
+
 /* declare a new process specific data 
    (used by gras_<module>_register to make sure that gras_process_init will create it) */
 /* declare a new process specific data 
    (used by gras_<module>_register to make sure that gras_process_init will create it) */
-
 XBT_PUBLIC int gras_procdata_add(const char *name, pvoid_f_void_t creator,void_f_pvoid_t destructor);
 XBT_PUBLIC int gras_procdata_add(const char *name, pvoid_f_void_t creator,void_f_pvoid_t destructor);
+
 XBT_PUBLIC void *gras_libdata_by_name(const char *name);
 XBT_PUBLIC void *gras_libdata_by_id(int id);
 
 XBT_PUBLIC void *gras_libdata_by_name(const char *name);
 XBT_PUBLIC void *gras_libdata_by_id(int id);
 
index b2a8c92..58c8045 100644 (file)
 #include "xbt/log.h"
 #include "xbt/module.h" /* xbt_init/exit */
 
 #include "xbt/log.h"
 #include "xbt/module.h" /* xbt_init/exit */
 
+#include "Virtu/virtu_interface.h" /* Module mechanism FIXME: deplace&rename */
 #include "gras_modinter.h"   /* module init/exit */
 #include "amok/amok_modinter.h"   /* module init/exit */
 #include "xbt_modinter.h"   /* module init/exit */
 
 #include "gras.h"
 #include "gras/process.h" /* FIXME: killme and put process_init in modinter */
 #include "gras_modinter.h"   /* module init/exit */
 #include "amok/amok_modinter.h"   /* module init/exit */
 #include "xbt_modinter.h"   /* module init/exit */
 
 #include "gras.h"
 #include "gras/process.h" /* FIXME: killme and put process_init in modinter */
-
+  
 #include "portable.h" /* hexa_*(); signalling stuff */
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras,XBT_LOG_ROOT_CAT,"All GRAS categories (cf. section \ref GRAS_API)");
 #include "portable.h" /* hexa_*(); signalling stuff */
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras,XBT_LOG_ROOT_CAT,"All GRAS categories (cf. section \ref GRAS_API)");
@@ -84,11 +85,13 @@ void gras_init(int *argc,char **argv) {
 void gras_exit(void) {
   INFO0("Exiting GRAS");
   amok_exit();
 void gras_exit(void) {
   INFO0("Exiting GRAS");
   amok_exit();
+  gras_moddata_leave();
   if (--gras_running_process == 0) {
     gras_msg_exit();
     gras_trp_exit();
     gras_datadesc_exit();
     gras_emul_exit();
   if (--gras_running_process == 0) {
     gras_msg_exit();
     gras_trp_exit();
     gras_datadesc_exit();
     gras_emul_exit();
+    gras_moddata_exit();
   }
   gras_process_exit();
   xbt_exit();
   }
   gras_process_exit();
   xbt_exit();