Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[doc] Add todo about user .then()
[simgrid.git] / src / simix / SynchroComm.cpp
index 5a5ccb5..e97b18f 100644 (file)
@@ -14,12 +14,30 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_network);
 simgrid::simix::Comm::Comm(e_smx_comm_type_t _type) {
   state = SIMIX_WAITING;
   this->type = _type;
-  refcount = 1;
-  src_data=NULL;
-  dst_data=NULL;
+  src_data=nullptr;
+  dst_data=nullptr;
 
   XBT_DEBUG("Create communicate synchro %p", this);
 }
+
+simgrid::simix::Comm::~Comm()
+{
+  XBT_DEBUG("Really free communication %p", this);
+
+  cleanupSurf();
+
+  if (detached && state != SIMIX_DONE) {
+    /* the communication has failed and was detached:
+     * we have to free the buffer */
+    if (clean_fun)
+      clean_fun(src_buff);
+    src_buff = nullptr;
+  }
+
+  if(mbox)
+    SIMIX_mbox_remove(mbox, this);
+
+}
 void simgrid::simix::Comm::suspend()
 {
   /* FIXME: shall we suspend also the timeout synchro? */
@@ -73,49 +91,48 @@ double simgrid::simix::Comm::remains()
   }
 }
 
-void simgrid::simix::Comm::unref()
-{
-  XBT_DEBUG("Destroy synchro %p (refcount: %d), state: %d", this, refcount, (int)state);
-
-  xbt_assert(refcount > 0,
-      "This comm has a negative refcount! You must not call test() or wait() more than once on a given communication.");
-
-  refcount--;
-  if (refcount > 0)
-      return;
-  XBT_DEBUG("Really free communication %p; refcount is now %d", this, refcount);
-
-  cleanupSurf();
-
-  if (detached && state != SIMIX_DONE) {
-    /* the communication has failed and was detached:
-     * we have to free the buffer */
-    if (clean_fun)
-      clean_fun(src_buff);
-    src_buff = NULL;
-  }
-
-  if(mbox)
-    SIMIX_mbox_remove(mbox, this);
-
-  delete this;
-}
-
 /** @brief This is part of the cleanup process, probably an internal command */
 void simgrid::simix::Comm::cleanupSurf()
 {
   if (surf_comm){
     surf_comm->unref();
-    surf_comm = NULL;
+    surf_comm = nullptr;
   }
 
   if (src_timeout){
     src_timeout->unref();
-    src_timeout = NULL;
+    src_timeout = nullptr;
   }
 
   if (dst_timeout){
     dst_timeout->unref();
-    dst_timeout = NULL;
+    dst_timeout = nullptr;
   }
 }
+
+void simgrid::simix::Comm::post()
+{
+  /* Update synchro state */
+  if (src_timeout &&  src_timeout->getState() == simgrid::surf::Action::State::done)
+    state = SIMIX_SRC_TIMEOUT;
+  else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::done)
+    state = SIMIX_DST_TIMEOUT;
+  else if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::failed)
+    state = SIMIX_SRC_HOST_FAILURE;
+  else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::failed)
+    state = SIMIX_DST_HOST_FAILURE;
+  else if (surf_comm && surf_comm->getState() == simgrid::surf::Action::State::failed) {
+    state = SIMIX_LINK_FAILURE;
+  } else
+    state = SIMIX_DONE;
+
+  XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d",
+            this, (int)state, src_proc, dst_proc, detached);
+
+  /* destroy the surf actions associated with the Simix communication */
+  cleanupSurf();
+
+  /* if there are simcalls associated with the synchro, then answer them */
+  if (!simcalls.empty())
+    SIMIX_comm_finish(this);
+}