Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use new/delete for smx_process_arg_t
[simgrid.git] / src / simix / smx_host.cpp
index 800a511..15ffa67 100644 (file)
@@ -16,8 +16,6 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts");
 
-static void SIMIX_execution_finish(smx_synchro_t synchro);
-
 /**
  * \brief Internal function to create a SIMIX host.
  * \param name name of the host to create
@@ -25,9 +23,9 @@ static void SIMIX_execution_finish(smx_synchro_t synchro);
 void SIMIX_host_create(sg_host_t host) // FIXME: braindead prototype. Take sg_host as parameter
 {
   smx_host_priv_t smx_host = xbt_new0(s_smx_host_priv_t, 1);
-  s_smx_process_t proc;
 
   /* Host structure */
+  simgrid::simix::Process proc;
   smx_host->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
 
   /* Update global variables */
@@ -168,7 +166,7 @@ void _SIMIX_host_free_process_arg(void *data)
     xbt_free(arg->argv[i]);
   xbt_free(arg->argv);
   xbt_free(arg->name);
-  xbt_free(arg);
+  delete arg;
 }
 /**
  * \brief Add a process to the list of the processes that the host will restart when it comes back
@@ -190,7 +188,7 @@ void SIMIX_host_add_auto_restart_process(sg_host_t host,
   if (!sg_host_simix(host)->auto_restart_processes) {
     sg_host_simix(host)->auto_restart_processes = xbt_dynar_new(sizeof(smx_process_arg_t),_SIMIX_host_free_process_arg);
   }
-  smx_process_arg_t arg = xbt_new(s_smx_process_arg_t,1);
+  smx_process_arg_t arg = new s_smx_process_arg_t();
   arg->name = xbt_strdup(name);
   arg->code = code;
   arg->data = data;
@@ -332,18 +330,6 @@ smx_synchro_t SIMIX_execution_parallel_start(const char *name,
   return exec;
 }
 
-void SIMIX_execution_destroy(smx_synchro_t synchro)
-{
-  XBT_DEBUG("Destroy synchro %p", synchro);
-  simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
-
-  if (exec->surf_exec) {
-    exec->surf_exec->unref();
-    exec->surf_exec = NULL;
-  }
-  delete exec;
-}
-
 void SIMIX_execution_cancel(smx_synchro_t synchro)
 {
   XBT_DEBUG("Cancel synchro %p", synchro);
@@ -353,22 +339,6 @@ void SIMIX_execution_cancel(smx_synchro_t synchro)
     exec->surf_exec->cancel();
 }
 
-double SIMIX_execution_get_remains(smx_synchro_t synchro)
-{
-  double result = 0.0;
-  simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
-
-  if (synchro->state == SIMIX_RUNNING)
-    result = exec->surf_exec->getRemains();
-
-  return result;
-}
-
-e_smx_state_t SIMIX_execution_get_state(smx_synchro_t synchro)
-{
-  return synchro->state;
-}
-
 void SIMIX_execution_set_priority(smx_synchro_t synchro, double priority)
 {
   simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
@@ -395,7 +365,7 @@ void SIMIX_execution_set_affinity(smx_synchro_t synchro, sg_host_t host, unsigne
 
 void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro)
 {
-
+  simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
   XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro, (int)synchro->state);
 
   /* Associate this simcall to the synchro */
@@ -405,37 +375,23 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro
   /* set surf's synchro */
   if (MC_is_active() || MC_record_replay_is_active()) {
     synchro->state = SIMIX_DONE;
-    SIMIX_execution_finish(synchro);
+    SIMIX_execution_finish(exec);
     return;
   }
 
   /* If the synchro is already finished then perform the error handling */
   if (synchro->state != SIMIX_RUNNING)
-    SIMIX_execution_finish(synchro);
+    SIMIX_execution_finish(exec);
 }
 
-void SIMIX_execution_suspend(smx_synchro_t synchro)
-{
-  simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
-  if(exec->surf_exec)
-    exec->surf_exec->suspend();
-}
-
-void SIMIX_execution_resume(smx_synchro_t synchro)
-{
-  simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
-  if(exec->surf_exec)
-    exec->surf_exec->resume();
-}
-
-void SIMIX_execution_finish(smx_synchro_t synchro)
+void SIMIX_execution_finish(simgrid::simix::Exec *exec)
 {
   xbt_fifo_item_t item;
   smx_simcall_t simcall;
 
-  xbt_fifo_foreach(synchro->simcalls, item, simcall, smx_simcall_t) {
+  xbt_fifo_foreach(exec->simcalls, item, simcall, smx_simcall_t) {
 
-    switch (synchro->state) {
+    switch (exec->state) {
 
       case SIMIX_DONE:
         /* do nothing, synchro done */
@@ -455,51 +411,21 @@ void SIMIX_execution_finish(smx_synchro_t synchro)
 
       default:
         xbt_die("Internal error in SIMIX_execution_finish: unexpected synchro state %d",
-            (int)synchro->state);
+            (int)exec->state);
     }
-    /* check if the host is down */
-    if (simcall->issuer->host->isOff()) {
+    /* Fail the process if the host is down */
+    if (simcall->issuer->host->isOff())
       simcall->issuer->context->iwannadie = 1;
-    }
 
-    simcall->issuer->waiting_synchro =    NULL;
-    simcall_execution_wait__set__result(simcall, synchro->state);
+    simcall->issuer->waiting_synchro = NULL;
+    simcall_execution_wait__set__result(simcall, exec->state);
     SIMIX_simcall_answer(simcall);
   }
 
   /* We no longer need it */
-  SIMIX_execution_destroy(synchro);
+  exec->unref();
 }
 
-
-void SIMIX_post_host_execute(smx_synchro_t synchro)
-{
-  simgrid::simix::Exec *exec = dynamic_cast<simgrid::simix::Exec *>(synchro);
-
-  if (exec != nullptr && exec->host && /* FIMXE: handle resource failure for parallel tasks too */
-      exec->host->isOff()) {
-    /* If the host running the synchro failed, notice it. This way, the asking
-     * process can be killed if it runs on that host itself */
-    synchro->state = SIMIX_FAILED;
-  } else if (exec->surf_exec->getState() == simgrid::surf::Action::State::failed) {
-    /* If the host running the synchro didn't fail, then the synchro was canceled */
-    synchro->state = SIMIX_CANCELED;
-  } else {
-    synchro->state = SIMIX_DONE;
-  }
-
-  if (exec != nullptr && exec->surf_exec) {
-    exec->surf_exec->unref();
-    exec->surf_exec = NULL;
-  }
-
-  /* If there are simcalls associated with the synchro, then answer them */
-  if (xbt_fifo_size(synchro->simcalls)) {
-    SIMIX_execution_finish(synchro);
-  }
-}
-
-
 void SIMIX_set_category(smx_synchro_t synchro, const char *category)
 {
   if (synchro->state != SIMIX_RUNNING) return;