Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / simix / SynchroExec.cpp
index 02ce125..8ab8f2e 100644 (file)
@@ -5,7 +5,21 @@
 
 #include "src/simix/SynchroExec.hpp"
 #include "src/surf/surf_interface.hpp"
+#include "src/simix/smx_host_private.h"
 
+simgrid::simix::Exec::Exec(const char*name, sg_host_t hostarg)
+{
+  if (name)
+    this->name = name;
+  this->state = SIMIX_RUNNING;
+  this->host = hostarg;
+}
+
+simgrid::simix::Exec::~Exec()
+{
+  if (surf_exec)
+    surf_exec->unref();
+}
 void simgrid::simix::Exec::suspend()
 {
   if (surf_exec)
@@ -26,14 +40,25 @@ double simgrid::simix::Exec::remains()
   return 0;
 }
 
-void simgrid::simix::Exec::unref()
+void simgrid::simix::Exec::post()
 {
-  refcount--;
-  if (refcount > 0)
-    return;
+  if (host && host->isOff()) {/* FIMXE: handle resource failure for parallel tasks too */
+    /* If the host running the synchro failed, notice it. This way, the asking
+     * process can be killed if it runs on that host itself */
+    state = SIMIX_FAILED;
+  } else if (surf_exec->getState() == simgrid::surf::Action::State::failed) {
+    /* If the host running the synchro didn't fail, then the synchro was canceled */
+    state = SIMIX_CANCELED;
+  } else {
+    state = SIMIX_DONE;
+  }
 
-  if (surf_exec)
+  if (surf_exec) {
     surf_exec->unref();
+    surf_exec = NULL;
+  }
 
-  delete this;
+  /* If there are simcalls associated with the synchro, then answer them */
+  if (!simcalls.empty())
+    SIMIX_execution_finish(this);
 }