Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix bug #14412 (Killing a SIMIX process just after migrate won't work)
[simgrid.git] / src / simix / smx_process.c
index b9d8f8d..18656fa 100644 (file)
@@ -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);
   }
@@ -582,7 +584,7 @@ void SIMIX_post_process_sleep(smx_action_t action)
 
     switch(surf_workstation_model->action_state_get(action->sleep.surf_sleep)){
       case SURF_ACTION_FAILED:
-        state = SIMIX_SRC_HOST_FAILURE;
+       SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
         break;
 
       case SURF_ACTION_DONE:
@@ -636,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);
@@ -652,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 */
@@ -711,3 +713,28 @@ xbt_dynar_t SIMIX_processes_as_dynar(void) {
   }
   return res;
 }
+void SIMIX_process_on_exit_runall(smx_process_t process) {
+  int cpt;
+  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(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 ?");
+
+  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);
+}