Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add Comm::on_this_send and Comm::on_this_recv
authorFred Suter <suterf@ornl.gov>
Sun, 4 Jun 2023 18:37:18 +0000 (14:37 -0400)
committerFred Suter <suterf@ornl.gov>
Sun, 4 Jun 2023 18:37:18 +0000 (14:37 -0400)
include/simgrid/s4u/Comm.hpp
src/s4u/s4u_Comm.cpp

index 167f70c..2f07115 100644 (file)
@@ -41,7 +41,9 @@ class XBT_PUBLIC Comm : public Activity_T<Comm> {
 
 protected:
   static xbt::signal<void(Comm const&)> on_send;
+  xbt::signal<void(Comm const&)> on_this_send;
   static xbt::signal<void(Comm const&)> on_recv;
+  xbt::signal<void(Comm const&)> on_this_recv;
   inline static xbt::signal<void(Comm const&)> on_start;
   xbt::signal<void(Comm const&)> on_this_start;
 
@@ -65,8 +67,12 @@ protected:
 public:
   /*! \static Add a callback fired when the send of any Comm is posted  */
   static void on_send_cb(const std::function<void(Comm const&)>& cb) { on_send.connect(cb); }
+  /*! Add a callback fired when the send of this specific Comm is posted  */
+  void on_this_send_cb(const std::function<void(Comm const&)>& cb) { on_send.connect(cb); }
   /*! \static Add a callback fired when the recv of any Comm is posted  */
   static void on_recv_cb(const std::function<void(Comm const&)>& cb) { on_recv.connect(cb); }
+  /*! Add a callback fired when the recv of this specific Comm is posted  */
+  void on_this_recv_cb(const std::function<void(Comm const&)>& cb) { on_this_recv.connect(cb); }
   /*! \static Add a callback fired when any Comm starts  */
   static void on_start_cb(const std::function<void(Comm const&)>& cb) { on_start.connect(cb); }
   /*!  Add a callback fired when this specific Comm starts  */
index 9bd5d0f..47a3de6 100644 (file)
@@ -315,13 +315,16 @@ Comm* Comm::do_start()
                "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_this_send(*this);
     on_recv(*this);
+    on_this_recv(*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_,
@@ -338,6 +341,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_),
@@ -408,11 +412,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_);
       }