From: Samuel Lepetit Date: Thu, 21 Jun 2012 08:29:54 +0000 (+0200) Subject: Fix commit 825fb3d5095e6cce48885d1d04ab1ec3823dae6c X-Git-Tag: v3_8~532 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d9e3a85686463be06864f1ed310765a91dee2803?ds=sidebyside Fix commit 825fb3d5095e6cce48885d1d04ab1ec3823dae6c --- diff --git a/include/msg/msg.h b/include/msg/msg.h index 80fae8ff17..2fb6435b6a 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -138,7 +138,7 @@ XBT_PUBLIC(const char *) MSG_process_get_property_value(m_process_t XBT_PUBLIC(MSG_error_t) MSG_process_suspend(m_process_t process); XBT_PUBLIC(MSG_error_t) MSG_process_resume(m_process_t process); XBT_PUBLIC(int) MSG_process_is_suspended(m_process_t process); -XBT_PUBLIC(void) MSG_process_on_exit_add(int_f_pvoid_t fun, void *data); +XBT_PUBLIC(void) MSG_process_on_exit(int_f_pvoid_t fun, void *data); /************************** Task handling ************************************/ XBT_PUBLIC(m_task_t) MSG_task_create(const char *name, diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index edf577780e..872af4a677 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -252,8 +252,8 @@ XBT_PUBLIC(void*) SIMIX_process_self_get_data(smx_process_t self); XBT_PUBLIC(smx_context_t) SIMIX_process_get_context(smx_process_t); XBT_PUBLIC(void) SIMIX_process_set_context(smx_process_t p,smx_context_t c); XBT_PUBLIC(int) SIMIX_process_has_pending_comms(smx_process_t process); -XBT_PUBLIC(void) SIMIX_process_on_exit(smx_process_t process); -XBT_PUBLIC(void) SIMIX_process_on_exit_add(int_f_pvoid_t fun, void *data); +XBT_PUBLIC(void) SIMIX_process_on_exit_runall(smx_process_t process); +XBT_PUBLIC(void) SIMIX_process_on_exit(int_f_pvoid_t fun, void *data); /****************************** Communication *********************************/ XBT_PUBLIC(void) SIMIX_comm_set_copy_data_callback(void (*callback) (smx_action_t, void*, size_t)); diff --git a/src/msg/msg_process.c b/src/msg/msg_process.c index 2834674865..8576f90ff0 100644 --- a/src/msg/msg_process.c +++ b/src/msg/msg_process.c @@ -494,6 +494,6 @@ smx_context_t MSG_process_get_smx_ctx(m_process_t process) { * The on_exit functions are the functions executed when your process is killed. * You should use them to free the data used by your process. */ -void MSG_process_on_exit_add(int_f_pvoid_t fun, void *data) { - SIMIX_process_on_exit_add(fun,data); +void MSG_process_on_exit(int_f_pvoid_t fun, void *data) { + SIMIX_process_on_exit(fun,data); } diff --git a/src/simix/smx_context_base.c b/src/simix/smx_context_base.c index c1622752c4..944dd7a1b5 100644 --- a/src/simix/smx_context_base.c +++ b/src/simix/smx_context_base.c @@ -83,7 +83,7 @@ void smx_ctx_base_free(smx_context_t context) void smx_ctx_base_stop(smx_context_t context) { - SIMIX_process_on_exit(context->data); + SIMIX_process_on_exit_runall(context->data); if (context->cleanup_func) context->cleanup_func(context->data); context->iwannadie = 0; diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index b47fe453aa..cf9f2674eb 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); @@ -714,20 +713,28 @@ 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); +void SIMIX_process_on_exit_runall(smx_process_t process) { 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); + if (!process->on_exit) { + return; + } + + smx_process_exit_fun_t exit_fun; + + for (cpt = xbt_dynar_length(process->on_exit) - 1; cpt >= 0; cpt--) { + exit_fun = xbt_dynar_get_ptr(process->on_exit, cpt); + (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); } diff --git a/src/simix/smx_process_private.h b/src/simix/smx_process_private.h index 8348cb4c86..c6ac97a90f 100644 --- a/src/simix/smx_process_private.h +++ b/src/simix/smx_process_private.h @@ -36,8 +36,7 @@ typedef struct s_smx_process { xbt_dict_t properties; s_smx_simcall_t simcall; void *data; /* kept for compatibility, it should be replaced with moddata */ - xbt_dynar_t on_exit_fun; /* list of functions executed when the process dies */ - xbt_dynar_t on_exit_args; /* arguments (void*) of the functions executed when the process dies */ + xbt_dynar_t on_exit; /* list of functions executed when the process dies */ } s_smx_process_t; typedef struct s_smx_process_arg {