From: mquinson Date: Tue, 14 Nov 2006 18:38:50 +0000 (+0000) Subject: Cleanup the way moddata are destroyed at the end of the time X-Git-Tag: v3.3~2429 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3e500d98fef79a7b1bbe5e4f096dce8eef1a3d49 Cleanup the way moddata are destroyed at the end of the time git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2930 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/gras/Virtu/gras_module.c b/src/gras/Virtu/gras_module.c index 401742fb8d..7f426c3160 100644 --- a/src/gras/Virtu/gras_module.c +++ b/src/gras/Virtu/gras_module.c @@ -125,12 +125,18 @@ void gras_module_add(const char *name, unsigned int datasize, int *ID, } 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; @@ -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); } -/* 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); - (*mod->leave_f)(p); - free(p); + (*mod->leave_f)(gras_moddata_by_id(id)); } void gras_module_join(const char *name) { @@ -186,8 +203,7 @@ void gras_module_join(const char *name) { /* 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); diff --git a/src/gras/Virtu/process.c b/src/gras/Virtu/process.c index b620f84af3..f1883e667a 100644 --- a/src/gras/Virtu/process.c +++ b/src/gras/Virtu/process.c @@ -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; + return xbt_dynar_length(_gras_procdata_fabrics)-1; } diff --git a/src/gras/Virtu/virtu_interface.h b/src/gras/Virtu/virtu_interface.h index 8aa2e75431..f738c96430 100644 --- a/src/gras/Virtu/virtu_interface.h +++ b/src/gras/Virtu/virtu_interface.h @@ -19,10 +19,18 @@ #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__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 void *gras_libdata_by_name(const char *name); XBT_PUBLIC void *gras_libdata_by_id(int id); diff --git a/src/gras/gras.c b/src/gras/gras.c index b2a8c922b2..58c8045551 100644 --- a/src/gras/gras.c +++ b/src/gras/gras.c @@ -11,13 +11,14 @@ #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 "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(); + gras_moddata_leave(); 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();