X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6de9090dd8692387ae343c587b26915f9922d7bd..75b61335a13287f7a038935382966855d3a7098e:/src/simix/smx_process.c diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index b47fe453aa..0020a7ac6d 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -118,6 +118,8 @@ void SIMIX_process_empty_trash(void) xbt_fifo_free(process->comms); + xbt_dynar_free(&process->on_exit); + free(process->name); free(process); } @@ -219,9 +221,6 @@ void SIMIX_process_create(smx_process_t *process, XBT_DEBUG("Start context '%s'", (*process)->name); - /* Build the dynars for the on_exit functions */ - (*process)->on_exit_fun = xbt_dynar_new(sizeof(int_f_pvoid_t),NULL); - (*process)->on_exit_args = xbt_dynar_new(sizeof(void*),NULL); /* Now insert it in the global process list and in the process to run list */ xbt_swag_insert(*process, simix_global->process_list); XBT_DEBUG("Inserting %s(%s) in the to_run list", (*process)->name, host->name); @@ -639,6 +638,11 @@ void SIMIX_process_yield(smx_process_t self) /* Ok, maestro returned control to us */ XBT_DEBUG("Control returned to me: '%s'", self->name); + if (self->new_host) { + SIMIX_process_change_host(self, self->new_host); + self->new_host = NULL; + } + if (self->context->iwannadie){ XBT_DEBUG("I wanna die!"); SIMIX_context_stop(self->context); @@ -655,11 +659,6 @@ void SIMIX_process_yield(smx_process_t self) self->doexception = 0; SMX_THROW(); } - - if (self->new_host) { - SIMIX_process_change_host(self, self->new_host); - self->new_host = NULL; - } } /* callback: context fetching */ @@ -714,20 +713,23 @@ xbt_dynar_t SIMIX_processes_as_dynar(void) { } return res; } -void SIMIX_process_on_exit(smx_process_t process) { - int length = xbt_dynar_length(process->on_exit_fun); - int cpt; - int_f_pvoid_t fun; - void *data; - for (cpt = 0; cpt < length; cpt++) { - fun = xbt_dynar_get_as(process->on_exit_fun,cpt,int_f_pvoid_t); - data = xbt_dynar_get_as(process->on_exit_args,cpt,void*); - (fun)(data); +void SIMIX_process_on_exit_runall(smx_process_t process) { + s_smx_process_exit_fun_t exit_fun; + + while (!xbt_dynar_is_empty(process->on_exit)) { + exit_fun = xbt_dynar_pop_as(process->on_exit,s_smx_process_exit_fun_t); + (exit_fun.fun)(exit_fun.arg); } } -void SIMIX_process_on_exit_add(int_f_pvoid_t fun, void *data) { +void SIMIX_process_on_exit(int_f_pvoid_t fun, void *data) { smx_process_t process = SIMIX_process_self(); xbt_assert(process, "current process not found: are you in maestro context ?"); - xbt_dynar_push_as(process->on_exit_fun,int_f_pvoid_t,fun); - xbt_dynar_push_as(process->on_exit_args,void*,data); + + if (!process->on_exit) { + process->on_exit = xbt_dynar_new(sizeof(s_smx_process_exit_fun_t), NULL); + } + + s_smx_process_exit_fun_t exit_fun = {fun, data}; + + xbt_dynar_push_as(process->on_exit,s_smx_process_exit_fun_t,exit_fun); }