Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify parameter passing between EngineImpl and ContextFactory
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 13 Mar 2022 14:28:21 +0000 (15:28 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 13 Mar 2022 14:59:29 +0000 (15:59 +0100)
Indeed, it's easier to pass the object as a parameter instead of
having the called getting it afterward through a call back to the
caller.

src/bindings/java/JavaContext.cpp
src/bindings/java/JavaContext.hpp
src/kernel/EngineImpl.cpp
src/kernel/context/Context.hpp
src/kernel/context/ContextSwapped.cpp
src/kernel/context/ContextSwapped.hpp
src/kernel/context/ContextThread.cpp
src/kernel/context/ContextThread.hpp

index c7c5168..58933cf 100644 (file)
@@ -39,9 +39,9 @@ Context* JavaContextFactory::create_context(std::function<void()>&& code, actor:
   return this->new_context<JavaContext>(std::move(code), actor);
 }
 
-void JavaContextFactory::run_all()
+void JavaContextFactory::run_all(std::vector<actor::ActorImpl*> const& actors)
 {
-  SerialThreadContext::run_all();
+  SerialThreadContext::run_all(actors);
 }
 
 JavaContext::JavaContext(std::function<void()>&& code, smx_actor_t actor)
index 8af830e..30c7bad 100644 (file)
@@ -41,7 +41,7 @@ public:
   JavaContextFactory();
   ~JavaContextFactory() override;
   Context* create_context(std::function<void()>&& code, actor::ActorImpl* actor) override;
-  void run_all() override;
+  void run_all(std::vector<actor::ActorImpl*> const& actors) override;
 };
 
 XBT_PRIVATE ContextFactory* java_factory();
index 79f12ec..76a938d 100644 (file)
@@ -451,7 +451,7 @@ void EngineImpl::wake_all_waiting_actors() const
  */
 void EngineImpl::run_all_actors()
 {
-  instance_->get_context_factory()->run_all();
+  instance_->get_context_factory()->run_all(actors_to_run_);
 
   for (auto const& actor : actors_to_run_)
     if (actor->to_be_freed())
index f7dc07d..b0c22c2 100644 (file)
@@ -33,7 +33,7 @@ public:
   /** Turn the current thread into maestro (the old maestro becomes a regular actor) */
   virtual Context* create_maestro(std::function<void()>&& code, actor::ActorImpl* actor);
 
-  virtual void run_all() = 0;
+  virtual void run_all(std::vector<actor::ActorImpl*> const& actors_list) = 0;
 
 protected:
   template <class T, class... Args> T* new_context(Args&&... args)
index 868c19b..26f6738 100644 (file)
@@ -197,7 +197,7 @@ void SwappedContext::swap_into(SwappedContext* to)
 }
 
 /** Maestro wants to run all ready actors */
-void SwappedContextFactory::run_all()
+void SwappedContextFactory::run_all(std::vector<actor::ActorImpl*> const& actors_list)
 {
   const auto* engine = EngineImpl::get_instance();
   /* This function is called by maestro at the beginning of a scheduling round to get all working threads executing some
@@ -220,9 +220,9 @@ void SwappedContextFactory::run_all()
           auto* context = static_cast<SwappedContext*>(actor->context_.get());
           context->resume();
         },
-        engine->get_actors_to_run());
+        actors_list);
   } else { // sequential execution
-    if (not engine->has_actors_to_run())
+    if (actors_list.empty())
       return;
 
     /* maestro is already saved in the first slot of workers_context_ */
index 7902de7..29063ec 100644 (file)
@@ -32,7 +32,7 @@ public:
   SwappedContextFactory()                             = default;
   SwappedContextFactory(const SwappedContextFactory&) = delete;
   SwappedContextFactory& operator=(const SwappedContextFactory&) = delete;
-  void run_all() override;
+  void run_all(std::vector<actor::ActorImpl*> const& actors) override;
 
 private:
   /* For the sequential execution */
index f5a1f7a..eb9b4bd 100644 (file)
@@ -46,15 +46,13 @@ ThreadContext* ThreadContextFactory::create_context(std::function<void()>&& code
     return this->new_context<SerialThreadContext>(std::move(code), actor, maestro);
 }
 
-void ThreadContextFactory::run_all()
-{
-  if (is_parallel()) {
-    // Parallel execution
-    ParallelThreadContext::run_all();
-  } else {
-    // Serial execution
-    SerialThreadContext::run_all();
-  }
+void ThreadContextFactory::run_all(std::vector<actor::ActorImpl*> const& actors_list)
+{
+  if (is_parallel())
+    ParallelThreadContext::run_all(actors_list);
+
+  else
+    SerialThreadContext::run_all(actors_list);
 }
 
 // ThreadContext
@@ -166,10 +164,9 @@ void ThreadContext::attach_stop()
 
 // SerialThreadContext
 
-void SerialThreadContext::run_all()
+void SerialThreadContext::run_all(std::vector<actor::ActorImpl*> const& actors_list)
 {
-  const auto& to_run = EngineImpl::get_instance()->get_actors_to_run();
-  for (smx_actor_t const& actor : to_run) {
+  for (smx_actor_t const& actor : actors_list) {
     XBT_DEBUG("Handling %p", actor);
     auto* context = static_cast<ThreadContext*>(actor->context_.get());
     context->release();
@@ -192,13 +189,12 @@ void ParallelThreadContext::finalize()
   thread_sem_ = nullptr;
 }
 
-void ParallelThreadContext::run_all()
+void ParallelThreadContext::run_all(std::vector<actor::ActorImpl*> const& actors_list)
 {
-  const auto& to_release = EngineImpl::get_instance()->get_actors_to_run();
-  for (smx_actor_t const& actor : to_release)
+  for (smx_actor_t const& actor : actors_list)
     static_cast<ThreadContext*>(actor->context_.get())->release();
-  const auto& to_wait = EngineImpl::get_instance()->get_actors_to_run();
-  for (smx_actor_t const& actor : to_wait)
+
+  for (smx_actor_t const& actor : actors_list)
     static_cast<ThreadContext*>(actor->context_.get())->wait();
 }
 
index a61a9f9..6602a1f 100644 (file)
@@ -54,7 +54,7 @@ public:
   {
   }
 
-  static void run_all();
+  static void run_all(std::vector<actor::ActorImpl*> const& actors_list);
 };
 
 class ParallelThreadContext : public ThreadContext {
@@ -66,7 +66,7 @@ public:
 
   static void initialize();
   static void finalize();
-  static void run_all();
+  static void run_all(std::vector<actor::ActorImpl*> const& actors_list);
 
 private:
   static xbt::OsSemaphore* thread_sem_;
@@ -86,7 +86,7 @@ public:
     bool maestro = not code;
     return create_context(std::move(code), actor, maestro);
   }
-  void run_all() override;
+  void run_all(std::vector<actor::ActorImpl*> const& actors) override;
 
   // Optional methods:
   ThreadContext* attach(actor::ActorImpl* actor) override