Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replaced:
[simgrid.git] / src / s4u / s4u_comm.cpp
index 4ecb4e6..17a66b6 100644 (file)
@@ -23,8 +23,6 @@ Comm::~Comm()
       XBT_INFO("pimpl_ is null");
     xbt_backtrace_display_current();
   }
-  if (pimpl_)
-    SIMIX_comm_unref(pimpl_);
 }
 
 s4u::CommPtr Comm::send_init(s4u::MailboxPtr chan)
@@ -90,6 +88,7 @@ void Comm::start() {
         matchFunction_, cleanFunction_, copyDataFunction_,
         userData_, detached_);
   } else if (dstBuff_ != nullptr) { // Receiver side
+    xbt_assert(not detached_, "Receive cannot be detached");
     pimpl_ = simcall_comm_irecv(receiver_, mailbox_->getImpl(), dstBuff_, &dstBuffSize_,
         matchFunction_, copyDataFunction_,
         userData_, rate_);
@@ -118,6 +117,7 @@ void Comm::wait() {
   }
   state_ = finished;
 }
+
 void Comm::wait(double timeout) {
   xbt_assert(state_ == started || state_ == inited);
 
@@ -150,6 +150,7 @@ void Comm::send_detached(MailboxPtr dest, void* data, int simulatedSize)
   res->detached_    = true;
   res->start();
 }
+
 s4u::CommPtr Comm::send_async(MailboxPtr dest, void* data, int simulatedSize)
 {
   s4u::CommPtr res = CommPtr(s4u::Comm::send_init(dest));
@@ -170,19 +171,22 @@ s4u::CommPtr Comm::recv_async(MailboxPtr dest, void** data)
 
 void Comm::cancel()
 {
-  simgrid::kernel::activity::CommImpl* commPimpl = static_cast<simgrid::kernel::activity::CommImpl*>(pimpl_);
+  simgrid::kernel::activity::CommImplPtr commPimpl =
+      boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(pimpl_);
   commPimpl->cancel();
 }
+
 bool Comm::test() {
   xbt_assert(state_ == inited || state_ == started || state_ == finished);
-  
-  if (state_ == finished) 
-    xbt_die("Don't call test on a finished comm.");
-  
+
+  if (state_ == finished) {
+    return true;
+  }
+
   if (state_ == inited) {
     this->start();
   }
-  
+
   if(simcall_comm_test(pimpl_)){
     state_ = finished;
     return true;