From 6b89334bd957e8d02b2fd66f3fd6650957e99387 Mon Sep 17 00:00:00 2001 From: donassbr Date: Sat, 3 Oct 2009 16:41:49 +0000 Subject: [PATCH] As in MSG where we need to know which action the process is waiting for, we need to save the action on which the process is blocked. For example, when we use the xbt_cond_wait_timeout, it creates a sleep action on SURF to control the timeout while the process is sleeping. If we kill the process, we need to destroy this action. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6687 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/simix/private.h | 1 + src/simix/smx_process.c | 11 +++++++++++ src/simix/smx_synchro.c | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/src/simix/private.h b/src/simix/private.h index 210e01d388..2b344a057a 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -72,6 +72,7 @@ extern SIMIX_Global_t simix_global; int iwannadie : 1; smx_mutex_t mutex; /* mutex on which the process is blocked */ smx_cond_t cond; /* cond on which the process is blocked */ + smx_action_t waiting_action; xbt_dict_t properties; void *data; /* kept for compatibility, it should be replaced with moddata */ diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 49df074f35..30c76db052 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -158,6 +158,10 @@ void SIMIX_process_kill(smx_process_t process) if (process->cond) xbt_swag_remove(process, process->cond->sleeping); + if (process->waiting_action) { + SIMIX_unregister_action_to_condition(process->waiting_action, process->cond); + SIMIX_action_destroy(process->waiting_action); + } SIMIX_context_stop(process->context); } else { DEBUG2("%p here! killing %p", simix_global->current_process, process); @@ -168,6 +172,11 @@ void SIMIX_process_kill(smx_process_t process) if (process->cond) xbt_swag_remove(process, process->cond->sleeping); + + if (process->waiting_action) { + SIMIX_unregister_action_to_condition(process->waiting_action, process->cond); + SIMIX_action_destroy(process->waiting_action); + } } } @@ -301,9 +310,11 @@ void SIMIX_process_suspend(smx_process_t process) cond = SIMIX_cond_init(); dummy = SIMIX_action_execute(SIMIX_process_get_host(process), name, 0); + SIMIX_process_self()->waiting_action = dummy; surf_workstation_model->suspend(dummy->surf_action); SIMIX_register_action_to_condition(dummy, cond); __SIMIX_cond_wait(cond); + SIMIX_process_self()->waiting_action = NULL; SIMIX_unregister_action_to_condition(dummy, cond); SIMIX_action_destroy(dummy); SIMIX_cond_destroy(cond); diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index dbebbcbb2e..a54d30cd0c 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -185,8 +185,10 @@ void SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex) /* always create an action null in case there is a host failure */ /* if (xbt_fifo_size(cond->actions) == 0) { */ act_sleep = SIMIX_action_sleep(SIMIX_host_self(), -1); + SIMIX_process_self()->waiting_action = act_sleep; SIMIX_register_action_to_condition(act_sleep, cond); __SIMIX_cond_wait(cond); + SIMIX_process_self()->waiting_action = NULL; SIMIX_unregister_action_to_condition(act_sleep, cond); SIMIX_action_destroy(act_sleep); /* } else { */ @@ -244,7 +246,9 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, if (max_duration >= 0) { act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration); SIMIX_register_action_to_condition(act_sleep, cond); + SIMIX_process_self()->waiting_action = act_sleep; __SIMIX_cond_wait(cond); + SIMIX_process_self()->waiting_action = NULL; SIMIX_unregister_action_to_condition(act_sleep, cond); if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { SIMIX_action_destroy(act_sleep); -- 2.20.1