Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
migrate execute_tasks from simix::Global to kernel::EngineImpl
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 17 May 2021 09:33:28 +0000 (11:33 +0200)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 17 May 2021 10:52:33 +0000 (12:52 +0200)
src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
src/kernel/future.cpp
src/simix/smx_global.cpp
src/simix/smx_private.hpp

index 257d84f..1e2c129 100644 (file)
@@ -97,6 +97,28 @@ void EngineImpl::wake_all_waiting_actors() const
   }
 }
 
+/** Execute all the tasks that are queued, e.g. `.then()` callbacks of futures. */
+bool EngineImpl::execute_tasks()
+{
+  xbt_assert(tasksTemp.empty());
+
+  if (tasks.empty())
+    return false;
+
+  do {
+    // We don't want the callbacks to modify the vector we are iterating over:
+    tasks.swap(tasksTemp);
+
+    // Execute all the queued tasks:
+    for (auto& task : tasksTemp)
+      task();
+
+    tasksTemp.clear();
+  } while (not tasks.empty());
+
+  return true;
+}
+
 void EngineImpl::run()
 {
   if (MC_record_replay_is_active()) {
@@ -119,7 +141,7 @@ void EngineImpl::run()
 #endif
     }
 
-    simix_global->execute_tasks();
+    execute_tasks();
 
     while (not simix_global->actors_to_run.empty()) {
       XBT_DEBUG("New Sub-Schedule Round; size(queue)=%zu", simix_global->actors_to_run.size());
@@ -195,10 +217,10 @@ void EngineImpl::run()
         }
       }
 
-      simix_global->execute_tasks();
+      execute_tasks();
       do {
         wake_all_waiting_actors();
-      } while (simix_global->execute_tasks());
+      } while (execute_tasks());
 
       /* If only daemon processes remain, cancel their actions, mark them to die and reschedule them */
       if (simix_global->process_list.size() == simix_global->daemons.size())
@@ -223,7 +245,7 @@ void EngineImpl::run()
     bool again = false;
     do {
       again = timer::Timer::execute_all();
-      if (simix_global->execute_tasks())
+      if (execute_tasks())
         again = true;
       wake_all_waiting_actors();
     } while (again);
index dcce9a6..8efbc76 100644 (file)
@@ -10,6 +10,7 @@
 #include <simgrid/s4u/Engine.hpp>
 #include <simgrid/s4u/NetZone.hpp>
 #include <simgrid/simix.hpp>
+#include <xbt/functional.hpp>
 
 #include <map>
 #include <string>
@@ -28,6 +29,9 @@ class EngineImpl {
   std::unordered_map<std::string, std::shared_ptr<resource::Model>> models_prio_;
   routing::NetZoneImpl* netzone_root_ = nullptr;
 
+  std::vector<xbt::Task<void()>> tasks;
+  std::vector<xbt::Task<void()>> tasksTemp;
+
   friend s4u::Engine;
 
 public:
@@ -63,6 +67,8 @@ public:
       return res->second;
   }
 
+  bool execute_tasks();
+  void add_task(xbt::Task<void()>&& t) { tasks.push_back(std::move(t)); }
   void wake_all_waiting_actors() const;
   void display_all_actor_status() const;
 
index 88a8461..1104a66 100644 (file)
@@ -8,15 +8,15 @@
 
 #include <simgrid/kernel/future.hpp>
 
-#include "src/simix/smx_private.hpp"
+#include "src/kernel/EngineImpl.hpp"
 
 namespace simgrid {
 namespace kernel {
 
 void FutureStateBase::schedule(simgrid::xbt::Task<void()>&& job) const
 {
-  simix_global->tasks.push_back(std::move(job));
+  EngineImpl::get_instance()->add_task(std::move(job));
 }
 
-}
-}
+} // namespace kernel
+} // namespace simgrid
index a45b862..7d9d47b 100644 (file)
@@ -149,28 +149,6 @@ static void install_segvhandler()
 namespace simgrid {
 namespace simix {
 
-/** Execute all the tasks that are queued, e.g. `.then()` callbacks of futures. */
-bool Global::execute_tasks()
-{
-  xbt_assert(tasksTemp.empty());
-
-  if (tasks.empty())
-    return false;
-
-  do {
-    // We don't want the callbacks to modify the vector we are iterating over:
-    tasks.swap(tasksTemp);
-
-    // Execute all the queued tasks:
-    for (auto& task : tasksTemp)
-      task();
-
-    tasksTemp.clear();
-  } while (not tasks.empty());
-
-  return true;
-}
-
 void Global::empty_trash()
 {
   while (not actors_to_destroy.empty()) {
index d50f70b..4034620 100644 (file)
@@ -22,7 +22,6 @@ namespace simix {
 
 class Global {
 public:
-  bool execute_tasks();
   /**
    * Garbage collection
    *
@@ -56,9 +55,6 @@ public:
 
   std::mutex mutex;
 
-  std::vector<xbt::Task<void()>> tasks;
-  std::vector<xbt::Task<void()>> tasksTemp;
-
   std::vector<kernel::actor::ActorImpl*> daemons;
 };
 }