Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reorder loop processing in CommWait ex(C) comp
[simgrid.git] / src / s4u / s4u_Comm.cpp
index 376d18de3ab61cae086cc432f5ff31224248e84f..ac97c56ce3bd022ae4175bb61d430d94b5c3cefd 100644 (file)
@@ -21,7 +21,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_comm, s4u_activity, "S4U asynchronous commun
 namespace simgrid::s4u {
 xbt::signal<void(Comm const&)> Comm::on_send;
 xbt::signal<void(Comm const&)> Comm::on_recv;
-xbt::signal<void(Comm const&)> Comm::on_start;
 
 CommPtr Comm::set_copy_data_callback(const std::function<void(kernel::activity::CommImpl*, void*, size_t)>& callback)
 {
@@ -313,14 +312,15 @@ Comm* Comm::do_start()
     xbt_assert(src_buff_ == nullptr && dst_buff_ == nullptr,
                "Direct host-to-host communications cannot carry any data.");
     XBT_DEBUG("host-to-host Comm. Pimpl already created and set, just start it.");
-    on_send(*this);
-    on_recv(*this);
+    on_start(*this);
+    on_this_start(*this);
     kernel::actor::simcall_answered([this] {
       pimpl_->set_state(kernel::activity::State::READY);
       boost::static_pointer_cast<kernel::activity::CommImpl>(pimpl_)->start();
     });
   } else if (src_buff_ != nullptr) { // Sender side
     on_send(*this);
+    on_this_send(*this);
     kernel::actor::CommIsendSimcall observer{sender_,
                                              mailbox_->get_impl(),
                                              remains_,
@@ -337,6 +337,7 @@ Comm* Comm::do_start()
   } else if (dst_buff_ != nullptr) { // Receiver side
     xbt_assert(not detached_, "Receive cannot be detached");
     on_recv(*this);
+    on_this_recv(*this);
     kernel::actor::CommIrecvSimcall observer{receiver_,
                                              mailbox_->get_impl(),
                                              static_cast<unsigned char*>(dst_buff_),
@@ -358,8 +359,10 @@ Comm* Comm::do_start()
     pimpl_->set_iface(this);
     pimpl_->set_actor(sender_);
     // Only throw the signal when both sides are here and the status is READY
-    if (pimpl_->get_state() != kernel::activity::State::WAITING)
+    if (pimpl_->get_state() != kernel::activity::State::WAITING) {
       on_start(*this);
+      on_this_start(*this);
+    }
   }
 
   state_ = State::STARTED;
@@ -405,11 +408,13 @@ Comm* Comm::wait_for(double timeout)
         return start()->wait_for(timeout); // In the case of host2host comm, do it in two simcalls
       } else if (src_buff_ != nullptr) {
         on_send(*this);
+        on_this_send(*this);
         send(sender_, mailbox_, remains_, rate_, src_buff_, src_buff_size_, match_fun_, copy_data_function_,
              get_data<void>(), timeout);
 
       } else { // Receiver
         on_recv(*this);
+        on_this_recv(*this);
         recv(receiver_, mailbox_, dst_buff_, &dst_buff_size_, match_fun_, copy_data_function_, get_data<void>(),
              timeout, rate_);
       }
@@ -463,7 +468,7 @@ ssize_t Comm::wait_any_for(const std::vector<CommPtr>& comms, double timeout)
 void Comm::wait_all(const std::vector<CommPtr>& comms)
 {
   // TODO: this should be a simcall or something
-  for (auto& comm : comms)
+  for (const auto& comm : comms)
     comm->wait();
 }