Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
don't mix the refcount of s4u::Comm and the one of CommImpl
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 28 May 2017 23:14:33 +0000 (01:14 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 28 May 2017 23:14:33 +0000 (01:14 +0200)
src/s4u/s4u_comm.cpp
src/simix/smx_network.cpp
src/surf/network_cm02.hpp

index 801e9b5..4ecb4e6 100644 (file)
@@ -24,7 +24,7 @@ Comm::~Comm()
     xbt_backtrace_display_current();
   }
   if (pimpl_)
-    pimpl_->unref();
+    SIMIX_comm_unref(pimpl_);
 }
 
 s4u::CommPtr Comm::send_init(s4u::MailboxPtr chan)
@@ -97,11 +97,6 @@ void Comm::start() {
   } else {
     xbt_die("Cannot start a communication before specifying whether we are the sender or the receiver");
   }
-  while (refcount_ > 1) { // Pass all the refcounts we had to the underlying pimpl since we are delegating the
-                          // refcounting to it afterward
-    refcount_--;
-    pimpl_->ref();
-  }
   state_ = started;
 }
 void Comm::wait() {
@@ -197,23 +192,14 @@ bool Comm::test() {
 
 void intrusive_ptr_release(simgrid::s4u::Comm* c)
 {
-  if (c->pimpl_ != nullptr) {
-    if (c->pimpl_->unref()) {
-      c->pimpl_ = nullptr;
-      delete c;
-    }
-  } else if (c->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
+  if (c->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
     std::atomic_thread_fence(std::memory_order_acquire);
     delete c;
   }
 }
 void intrusive_ptr_add_ref(simgrid::s4u::Comm* c)
 {
-  if (c->pimpl_ != nullptr) {
-    c->pimpl_->ref();
-  } else {
-    c->refcount_.fetch_add(1, std::memory_order_relaxed);
-  }
+  c->refcount_.fetch_add(1, std::memory_order_relaxed);
 }
 }
 } // namespaces
index d709632..f1d9614 100644 (file)
@@ -58,7 +58,7 @@ _find_matching_comm(boost::circular_buffer_space_optimized<smx_activity_t>* dequ
       XBT_DEBUG("Found a matching communication synchro %p", comm);
       if (remove_matching)
         deque->erase(it);
-      comm = static_cast<simgrid::kernel::activity::CommImpl*>(SIMIX_comm_ref(comm));
+      SIMIX_comm_ref(comm);
 #if SIMGRID_HAVE_MC
       comm->mbox_cpy = comm->mbox;
 #endif
@@ -465,12 +465,13 @@ static inline void SIMIX_comm_start(smx_activity_t synchro)
     simgrid::s4u::Host* sender   = comm->src_proc->host;
     simgrid::s4u::Host* receiver = comm->dst_proc->host;
 
-    XBT_DEBUG("Starting communication %p from '%s' to '%s'", synchro, sender->cname(), receiver->cname());
-
     comm->surf_comm = surf_network_model->communicate(sender, receiver, comm->task_size, comm->rate);
     comm->surf_comm->setData(synchro);
     comm->state = SIMIX_RUNNING;
 
+    XBT_DEBUG("Starting communication %p from '%s' to '%s' (surf_action: %p)", synchro, sender->cname(),
+              receiver->cname(), comm->surf_comm);
+
     /* If a link is failed, detect it immediately */
     if (comm->surf_comm->getState() == simgrid::surf::Action::State::failed) {
       XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure", sender->cname(),
@@ -527,7 +528,7 @@ void SIMIX_comm_finish(smx_activity_t synchro)
 
     /* If the synchro is still in a rendez-vous point then remove from it */
     if (comm->mbox)
-      comm->mbox->remove(synchro);
+      comm->mbox->remove(comm);
 
     XBT_DEBUG("SIMIX_comm_finish: synchro state = %d", (int)synchro->state);
 
index df834a8..04f6d98 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2013-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2013-2017. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */