Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow operation to execute more than one function at start and end
authorFred Suter <suterf@ornl.gov>
Tue, 23 May 2023 07:55:06 +0000 (03:55 -0400)
committerFred Suter <suterf@ornl.gov>
Tue, 23 May 2023 07:55:06 +0000 (03:55 -0400)
include/simgrid/plugins/operation.hpp
src/plugins/operation.cpp

index 303b0d1..a537a83 100644 (file)
@@ -48,8 +48,8 @@ protected:
   int count_        = 0;
   bool working_     = false;
   s4u::ActivityPtr current_activity_;
-  std::function<void(Operation*)> end_func_;
-  std::function<void(Operation*)> start_func_;
+  std::vector<std::function<void(Operation*)>> end_func_handlers_;
+  std::vector<std::function<void(Operation*)>> start_func_handlers_;
   explicit Operation(const std::string& name);
   virtual ~Operation()   = default;
   virtual void execute() = 0;
index e7802a0..963bce0 100644 (file)
@@ -100,8 +100,8 @@ void Operation::complete()
     working_ = false;
     count_++;
   });
-  if (end_func_)
-    end_func_(this);
+  for (auto end_func : end_func_handlers_)
+    end_func(this);
   Operation::on_end(this);
   for (auto const& op : successors_)
     op->receive(this);
@@ -191,7 +191,7 @@ void Operation::remove_all_successors()
  */
 void Operation::on_this_start(const std::function<void(Operation*)>& func)
 {
-  simgrid::kernel::actor::simcall_answered([this, &func] { start_func_ = func; });
+  simgrid::kernel::actor::simcall_answered([this, &func] { start_func_handlers_.push_back(func); });
 }
 
 /** @ingroup plugin_operation
@@ -201,7 +201,7 @@ void Operation::on_this_start(const std::function<void(Operation*)>& func)
  */
 void Operation::on_this_end(const std::function<void(Operation*)>& func)
 {
-  simgrid::kernel::actor::simcall_answered([this, &func] { end_func_ = func; });
+  simgrid::kernel::actor::simcall_answered([this, &func] { end_func_handlers_.push_back(func); });
 }
 
 /** @ingroup plugin_operation
@@ -240,8 +240,8 @@ ExecOpPtr ExecOp::init(const std::string& name, double flops, s4u::Host* host)
  */
 void ExecOp::execute()
 {
-  if (start_func_)
-    start_func_(this);
+  for (auto start_func : start_func_handlers_)
+    start_func(this);
   Operation::on_start(this);
   kernel::actor::simcall_answered([this] {
     working_      = true;
@@ -305,8 +305,8 @@ CommOpPtr CommOp::init(const std::string& name, double bytes, s4u::Host* source,
  */
 void CommOp::execute()
 {
-  if (start_func_)
-    start_func_(this);
+  for (auto start_func : start_func_handlers_)
+    start_func(this);
   Operation::on_start(this);
   kernel::actor::simcall_answered([this] {
     working_      = true;