Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
nothing to do with instr ...
[simgrid.git] / src / s4u / s4u_Comm.cpp
index c77cada..b27c782 100644 (file)
@@ -255,6 +255,15 @@ Actor* Comm::get_sender() const
 } // namespace s4u
 } // namespace simgrid
 /* **************************** Public C interface *************************** */
+void sg_comm_detach(sg_comm_t comm, void (*clean_function)(void*))
+{
+  comm->detach(clean_function);
+  comm->unref();
+}
+void sg_comm_unref(sg_comm_t comm)
+{
+  comm->unref();
+}
 int sg_comm_test(sg_comm_t comm)
 {
   bool finished = comm->test();
@@ -267,8 +276,9 @@ sg_error_t sg_comm_wait(sg_comm_t comm)
 {
   sg_error_t status = SG_OK;
 
+  simgrid::s4u::CommPtr s4u_comm(comm, false);
   try {
-    comm->wait_for(-1);
+    s4u_comm->wait_for(-1);
   } catch (const simgrid::TimeoutException&) {
     status = SG_ERROR_TIMEOUT;
   } catch (const simgrid::CancelException&) {
@@ -276,7 +286,6 @@ sg_error_t sg_comm_wait(sg_comm_t comm)
   } catch (const simgrid::NetworkFailureException&) {
     status = SG_ERROR_NETWORK;
   }
-  comm->unref();
   return status;
 }
 
@@ -284,8 +293,9 @@ sg_error_t sg_comm_wait_for(sg_comm_t comm, double timeout)
 {
   sg_error_t status = SG_OK;
 
+  simgrid::s4u::CommPtr s4u_comm(comm, false);
   try {
-    comm->wait_for(timeout);
+    s4u_comm->wait_for(timeout);
   } catch (const simgrid::TimeoutException&) {
     status = SG_ERROR_TIMEOUT;
   } catch (const simgrid::CancelException&) {
@@ -293,7 +303,6 @@ sg_error_t sg_comm_wait_for(sg_comm_t comm, double timeout)
   } catch (const simgrid::NetworkFailureException&) {
     status = SG_ERROR_NETWORK;
   }
-  comm->unref();
   return status;
 }
 
@@ -301,11 +310,9 @@ void sg_comm_wait_all(sg_comm_t* comms, size_t count)
 {
   std::vector<simgrid::s4u::CommPtr> s4u_comms;
   for (unsigned int i = 0; i < count; i++)
-    s4u_comms.emplace_back(comms[i]);
+    s4u_comms.emplace_back(comms[i], false);
 
   simgrid::s4u::Comm::wait_all(&s4u_comms);
-  for (unsigned int i = 0; i < count; i++)
-    s4u_comms[i]->unref();
 }
 
 int sg_comm_wait_any(sg_comm_t* comms, size_t count)
@@ -316,11 +323,13 @@ int sg_comm_wait_any(sg_comm_t* comms, size_t count)
 int sg_comm_wait_any_for(sg_comm_t* comms, size_t count, double timeout)
 {
   std::vector<simgrid::s4u::CommPtr> s4u_comms;
-  for (unsigned int i = 0; i < count; i++) {
-    s4u_comms.emplace_back(comms[i]);
-  }
+  for (unsigned int i = 0; i < count; i++)
+    s4u_comms.emplace_back(comms[i], false);
+
   int pos = simgrid::s4u::Comm::wait_any_for(&s4u_comms, timeout);
-  if (pos != -1)
-    s4u_comms[pos]->unref();
+  for (unsigned i = 0; i < count; i++) {
+    if (pos != -1 && static_cast<unsigned>(pos) != i)
+      s4u_comms[i]->add_ref();
+  }
   return pos;
 }