Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unused type definitions.
[simgrid.git] / src / s4u / s4u_Comm.cpp
index 50eaf00..7aa422a 100644 (file)
@@ -6,6 +6,7 @@
 #include "src/msg/msg_private.hpp"
 #include "xbt/log.h"
 
+#include "simgrid/Exception.hpp"
 #include "simgrid/s4u/Comm.hpp"
 #include "simgrid/s4u/Mailbox.hpp"
 
@@ -145,7 +146,7 @@ Comm* Comm::wait_for(double timeout)
 {
   switch (state_) {
     case State::FINISHED:
-      return this;
+      break;
 
     case State::INITED: // It's not started yet. Do it in one simcall
       if (src_buff_ != nullptr) {
@@ -159,13 +160,16 @@ Comm* Comm::wait_for(double timeout)
                           user_data_, timeout, rate_);
       }
       state_ = State::FINISHED;
-      return this;
+      break;
 
     case State::STARTED:
       simcall_comm_wait(pimpl_, timeout);
       on_completion(Actor::self());
       state_ = State::FINISHED;
-      return this;
+      break;
+
+    case State::CANCELED:
+      throw CancelException(XBT_THROW_POINT, "Communication canceled");
 
     default:
       THROW_IMPOSSIBLE;
@@ -193,7 +197,10 @@ Comm* Comm::detach()
 
 Comm* Comm::cancel()
 {
-  simgrid::simix::simcall([this] { static_cast<kernel::activity::CommImpl*>(pimpl_.get())->cancel(); });
+  simgrid::simix::simcall([this] {
+    if (pimpl_)
+      boost::static_pointer_cast<kernel::activity::CommImpl>(pimpl_)->cancel();
+  });
   state_ = State::CANCELED;
   return this;
 }
@@ -215,11 +222,16 @@ bool Comm::test()
   return false;
 }
 
-MailboxPtr Comm::get_mailbox()
+Mailbox* Comm::get_mailbox()
 {
   return mailbox_;
 }
 
+ActorPtr Comm::get_sender()
+{
+  return sender_ ? sender_->iface() : nullptr;
+}
+
 void intrusive_ptr_release(simgrid::s4u::Comm* c)
 {
   if (c->refcount_.fetch_sub(1, std::memory_order_release) == 1) {