Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
As in MSG where we need to know which action the process is waiting for, we need...
authordonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 3 Oct 2009 16:41:49 +0000 (16:41 +0000)
committerdonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 3 Oct 2009 16:41:49 +0000 (16:41 +0000)
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
src/simix/smx_process.c
src/simix/smx_synchro.c

index 210e01d..2b344a0 100644 (file)
@@ -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  */
        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 */
 
        xbt_dict_t properties;
        void *data;              /* kept for compatibility, it should be replaced with moddata */
 
index 49df074..30c76db 100644 (file)
@@ -158,6 +158,10 @@ void SIMIX_process_kill(smx_process_t process)
 
     if (process->cond)
       xbt_swag_remove(process, process->cond->sleeping);
 
     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);
     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->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);
 
     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);
     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);
     SIMIX_unregister_action_to_condition(dummy, cond);
     SIMIX_action_destroy(dummy);
     SIMIX_cond_destroy(cond);
index dbebbcb..a54d30c 100644 (file)
@@ -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);
   /* 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_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 { */
   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);
   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_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);
     SIMIX_unregister_action_to_condition(act_sleep, cond);
     if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) {
       SIMIX_action_destroy(act_sleep);