Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move signals "on_(this_)start" and methods "fire_on_*" into Activity_T.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 28 Jun 2023 14:18:04 +0000 (16:18 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 28 Jun 2023 16:31:11 +0000 (18:31 +0200)
include/simgrid/s4u/Activity.hpp
include/simgrid/s4u/Comm.hpp
include/simgrid/s4u/Exec.hpp
include/simgrid/s4u/Io.hpp
src/kernel/activity/CommImpl.cpp
src/s4u/s4u_Comm.cpp
src/s4u/s4u_Exec.cpp
src/s4u/s4u_Io.cpp

index 4f73b17..4f766d4 100644 (file)
@@ -104,14 +104,16 @@ protected:
    * It is forbidden to change the amount of work once the Activity is started */
   Activity* set_remaining(double remains);
 
-  virtual void fire_on_completion() const = 0;
+  virtual void fire_on_start() const           = 0;
+  virtual void fire_on_this_start() const      = 0;
+  virtual void fire_on_completion() const      = 0;
   virtual void fire_on_this_completion() const = 0;
-  virtual void fire_on_suspend() const = 0;
-  virtual void fire_on_this_suspend() const = 0;
-  virtual void fire_on_resume() const = 0;
-  virtual void fire_on_this_resume() const = 0;
-  virtual void fire_on_veto() const = 0;
-  virtual void fire_on_this_veto() const = 0;
+  virtual void fire_on_suspend() const         = 0;
+  virtual void fire_on_this_suspend() const    = 0;
+  virtual void fire_on_resume() const          = 0;
+  virtual void fire_on_this_resume() const     = 0;
+  virtual void fire_on_veto()                  = 0;
+  virtual void fire_on_this_veto()             = 0;
 
 public:
   void start()
@@ -233,7 +235,8 @@ template <class AnyActivity> class Activity_T : public Activity {
   std::string name_             = "unnamed";
   std::string tracing_category_ = "";
 
-protected:
+  inline static xbt::signal<void(AnyActivity const&)> on_start;
+  xbt::signal<void(AnyActivity const&)> on_this_start;
   inline static xbt::signal<void(AnyActivity const&)> on_completion;
   xbt::signal<void(AnyActivity const&)> on_this_completion;
   inline static xbt::signal<void(AnyActivity const&)> on_suspend;
@@ -243,7 +246,23 @@ protected:
   inline static xbt::signal<void(AnyActivity&)> on_veto;
   xbt::signal<void(AnyActivity&)> on_this_veto;
 
+protected:
+  void fire_on_start() const override { on_start(static_cast<const AnyActivity&>(*this)); }
+  void fire_on_this_start() const override { on_this_start(static_cast<const AnyActivity&>(*this)); }
+  void fire_on_completion() const override { on_completion(static_cast<const AnyActivity&>(*this)); }
+  void fire_on_this_completion() const override { on_this_completion(static_cast<const AnyActivity&>(*this)); }
+  void fire_on_suspend() const override { on_suspend(static_cast<const AnyActivity&>(*this)); }
+  void fire_on_this_suspend() const override { on_this_suspend(static_cast<const AnyActivity&>(*this)); }
+  void fire_on_resume() const override { on_resume(static_cast<const AnyActivity&>(*this)); }
+  void fire_on_this_resume() const override { on_this_resume(static_cast<const AnyActivity&>(*this)); }
+  void fire_on_veto() override { on_veto(static_cast<AnyActivity&>(*this)); }
+  void fire_on_this_veto() override { on_this_veto(static_cast<AnyActivity&>(*this)); }
+
 public:
+  /*! \static Add a callback fired when any activity starts (no veto) */
+  static void on_start_cb(const std::function<void(AnyActivity const&)>& cb) { on_start.connect(cb); }
+  /*!  Add a callback fired when this specific activity starts (no veto) */
+  void on_this_start_cb(const std::function<void(AnyActivity const&)>& cb) { on_this_start.connect(cb); }
   /*! \static Add a callback fired when any activity completes (either normally, cancelled or failed) */
   static void on_completion_cb(const std::function<void(AnyActivity const&)>& cb) { on_completion.connect(cb); }
   /*! Add a callback fired when this specific activity completes (either normally, cancelled or failed) */
index e5b8ad4..3b1f417 100644 (file)
@@ -43,8 +43,6 @@ class XBT_PUBLIC Comm : public Activity_T<Comm> {
   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;
 
 protected:
   void fire_on_completion() const override {
@@ -54,15 +52,12 @@ protected:
   }
   void fire_on_this_completion() const override {
     /* The completion signal of a Comm has to be thrown only once and not by the sender AND the receiver.
-       then Comm::on_completion is thrown in the kernel in CommImpl::finish.
+       then Comm::on_this_completion is thrown in the kernel in CommImpl::finish.
      */
   }
-  void fire_on_suspend() const override { on_suspend(*this); }
-  void fire_on_this_suspend() const override { on_this_suspend(*this); }
-  void fire_on_resume() const override { on_resume(*this); }
-  void fire_on_this_resume() const override { on_this_resume(*this); }
-  void fire_on_veto() const override { on_veto(const_cast<Comm&>(*this)); }
-  void fire_on_this_veto() const override { on_this_veto(const_cast<Comm&>(*this)); }
+  /* These ensure that the on_completion signals are really thrown */
+  void fire_on_completion_for_real() const { Activity_T<Comm>::fire_on_completion(); }
+  void fire_on_this_completion_for_real() const { Activity_T<Comm>::fire_on_this_completion(); }
 
 public:
   /*! \static Add a callback fired when the send of any Comm is posted  */
@@ -73,10 +68,6 @@ public:
   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  */
-  void on_this_start_cb(const std::function<void(Comm const&)>& cb) { on_this_start.connect(cb); }
 
   CommPtr set_copy_data_callback(const std::function<void(kernel::activity::CommImpl*, void*, size_t)>& callback);
   XBT_ATTRIB_DEPRECATED_v338("Please manifest if you actually need this function") static void copy_buffer_callback(
index 7de8e8e..b8e728a 100644 (file)
@@ -36,34 +36,17 @@ class XBT_PUBLIC Exec : public Activity_T<Exec> {
 
   bool parallel_ = false;
 
-  inline static xbt::signal<void(Exec const&)> on_start;
-  xbt::signal<void(Exec const&)> on_this_start;
-
 protected:
   explicit Exec(kernel::activity::ExecImplPtr pimpl);
   Exec* do_start() override;
 
   void reset() const;
 
-  void fire_on_completion() const override { on_completion(*this); }
-  void fire_on_this_completion() const override { on_this_completion(*this); }
-  void fire_on_suspend() const override { on_suspend(*this); }
-  void fire_on_this_suspend() const override { on_this_suspend(*this); }
-  void fire_on_resume() const override { on_resume(*this); }
-  void fire_on_this_resume() const override { on_this_resume(*this); }
-  void fire_on_veto() const override { on_veto(const_cast<Exec&>(*this)); }
-  void fire_on_this_veto() const override { on_this_veto(const_cast<Exec&>(*this)); }
-
 public:
 #ifndef DOXYGEN
   Exec(Exec const&) = delete;
   Exec& operator=(Exec const&) = delete;
 #endif
-  /*! \static Signal fired each time that any execution actually starts (no veto) */
-  static void on_start_cb(const std::function<void(Exec const&)>& cb) { on_start.connect(cb); }
-  /*! Signal fired each time that this specific execution actually starts (no veto) */
-  void on_this_start_cb(const std::function<void(Exec const&)>& cb) { on_this_start.connect(cb); }
-
   /*! \static Initiate the creation of an Exec. Setters have to be called afterwards */
   static ExecPtr init();
 
index 3cc28a0..2dc88c6 100644 (file)
@@ -24,29 +24,13 @@ class XBT_PUBLIC Io : public Activity_T<Io> {
   friend kernel::EngineImpl;
 #endif
 
-  inline static xbt::signal<void(Io const&)> on_start;
-  xbt::signal<void(Io const&)> on_this_start;
-
 protected:
   explicit Io(kernel::activity::IoImplPtr pimpl);
   Io* do_start() override;
-  void fire_on_completion() const override { on_completion(*this); }
-  void fire_on_this_completion() const override { on_this_completion(*this); }
-  void fire_on_suspend() const override { on_suspend(*this); }
-  void fire_on_this_suspend() const override { on_this_suspend(*this); }
-  void fire_on_resume() const override { on_resume(*this); }
-  void fire_on_this_resume() const override { on_this_resume(*this); }
-  void fire_on_veto() const override { on_veto(const_cast<Io&>(*this)); }
-  void fire_on_this_veto() const override { on_this_veto(const_cast<Io&>(*this)); }
 
 public:
   enum class OpType { READ, WRITE };
 
-   /*! \static Signal fired each time that any I/O actually starts (no veto) */
-  static void on_start_cb(const std::function<void(Io const&)>& cb) { on_start.connect(cb); }
-   /*! Signal fired each time this specific I/O actually starts (no veto) */
-  void on_this_start_cb(const std::function<void(Io const&)>& cb) { on_this_start.connect(cb); }
-
    /*! \static Initiate the creation of an I/O. Setters have to be called afterwards */
   static IoPtr init();
   /*! \static take a vector of s4u::IoPtr and return when one of them is finished.
index 5615d87..e5c1ddf 100644 (file)
@@ -486,8 +486,8 @@ void CommImpl::finish()
   if (get_iface()) {
     const auto& piface = static_cast<const s4u::Comm&>(*get_iface());
     set_iface(nullptr); // reset iface to protect against multiple trigger of the on_completion signals
-    s4u::Comm::on_completion(piface);
-    piface.on_this_completion(piface);
+    piface.fire_on_completion_for_real();
+    piface.fire_on_this_completion_for_real();
   }
 
   /* Update synchro state */
index 315a2f8..0ef8afb 100644 (file)
@@ -312,8 +312,8 @@ 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_start(*this);
-    on_this_start(*this);
+    fire_on_start();
+    fire_on_this_start();
     kernel::actor::simcall_answered([this] {
       pimpl_->set_state(kernel::activity::State::READY);
       boost::static_pointer_cast<kernel::activity::CommImpl>(pimpl_)->start();
@@ -360,8 +360,8 @@ Comm* Comm::do_start()
     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) {
-      on_start(*this);
-      on_this_start(*this);
+      fire_on_start();
+      fire_on_this_start();
     }
   }
 
index a6fd9cb..49f935e 100644 (file)
@@ -46,8 +46,8 @@ Exec* Exec::do_start()
     pimpl_->suspend();
 
   state_      = State::STARTED;
-  on_start(*this);
-  on_this_start(*this);
+  fire_on_start();
+  fire_on_this_start();
   return this;
 }
 
index 691be4a..7f0e45c 100644 (file)
@@ -89,8 +89,8 @@ Io* Io::do_start()
     pimpl_->suspend();
 
   state_ = State::STARTED;
-  on_start(*this);
-  on_this_start(*this);
+  fire_on_start();
+  fire_on_this_start();
   return this;
 }