X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/294f95a39505231ba48a99c4c4a9f4ecaeed7e40..301a28e1a96c21b0581abc2dd632952e3c5d0ff8:/src/gras/Virtu/gras_module.c diff --git a/src/gras/Virtu/gras_module.c b/src/gras/Virtu/gras_module.c index a9b49b7ddd..8969f5eac1 100644 --- a/src/gras/Virtu/gras_module.c +++ b/src/gras/Virtu/gras_module.c @@ -75,10 +75,10 @@ typedef struct s_gras_module { loading/unloading */ int *p_id; /* where the module stores the libdata ID (a global somewhere), to tweak it on need */ - void_f_void_t *init_f; /* First time the module is referenced. */ - void_f_void_t *exit_f; /* When last process referencing it stops doing so. */ - void_f_pvoid_t *join_f; /* Called by each process in initialization phase (init_f called once for all processes) */ - void_f_pvoid_t *leave_f; /* Called by each process in finalization phase. Should free moddata passed */ + void_f_void_t init_f; /* First time the module is referenced. */ + void_f_void_t exit_f; /* When last process referencing it stops doing so. */ + void_f_pvoid_t join_f; /* Called by each process in initialization phase (init_f called once for all processes) */ + void_f_pvoid_t leave_f; /* Called by each process in finalization phase. Should free moddata passed */ } s_gras_module_t, *gras_module_t; static xbt_set_t _gras_modules = NULL; /* content: s_gras_module_t */ @@ -106,11 +106,11 @@ static void gras_module_freep(void *p) { */ void gras_module_add(const char *name, unsigned int datasize, int *ID, - void_f_void_t *init_f, void_f_void_t *exit_f, - void_f_pvoid_t *join_f, void_f_pvoid_t *leave_f) { - gras_module_t mod; + void_f_void_t init_f, void_f_void_t exit_f, + void_f_pvoid_t join_f, void_f_pvoid_t leave_f) { + gras_module_t mod=NULL; xbt_ex_t e; - int found = 0; + volatile int found = 0; if (!_gras_modules) _gras_modules = xbt_set_new(); @@ -125,12 +125,18 @@ void gras_module_add(const char *name, unsigned int datasize, int *ID, } if (found) { - xbt_assert(mod->init_f == init_f); - xbt_assert(mod->exit_f == exit_f); - xbt_assert(mod->join_f == join_f); - xbt_assert(mod->leave_f == leave_f); - xbt_assert(mod->datasize == datasize); - xbt_assert(mod->p_id == ID); + 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; @@ -149,23 +155,35 @@ void gras_module_add(const char *name, unsigned int datasize, int *ID, mod->leave_f = leave_f; mod->refcount = 0; - *mod->p_id = xbt_set_length(_gras_modules); 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) { + gras_procdata_t *pd; + void *moddata; gras_module_t mod = (gras_module_t)xbt_set_get_by_name(_gras_modules, name); VERB2("Join to module %s (%p)",name,mod); @@ -183,10 +201,9 @@ void gras_module_join(const char *name) { mod->refcount++; /* JOIN */ - gras_procdata_t *pd=gras_procdata_get(); - void *moddata; + 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); @@ -198,12 +215,13 @@ void gras_module_join(const char *name) { DEBUG2("Module %s joined successfully (ID=%d)", name,*(mod->p_id)); } void gras_module_leave(const char *name) { + void *moddata; gras_module_t mod = (gras_module_t)xbt_set_get_by_name(_gras_modules, name); VERB1("Leave module %s",name); /* LEAVE */ - void *moddata = gras_moddata_by_id( *(mod->p_id) ); + moddata = gras_moddata_by_id( *(mod->p_id) ); (*mod->leave_f)(moddata); /* EXIT */