Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
migrate daemons from simix::Global to kernel::EngineImpl
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 17 May 2021 18:05:49 +0000 (20:05 +0200)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 17 May 2021 18:05:49 +0000 (20:05 +0200)
go from a public vector to a private set (order doesn't matter) in the
process.

src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
src/kernel/actor/ActorImpl.cpp
src/simix/smx_private.hpp

index 1e2c129..515de4d 100644 (file)
@@ -119,6 +119,13 @@ bool EngineImpl::execute_tasks()
   return true;
 }
 
+void EngineImpl::rm_daemon(actor::ActorImpl* actor)
+{
+  auto it = daemons_.find(actor);
+  xbt_assert(it != daemons_.end(), "The dying daemon is not a daemon after all. Please report that bug.");
+  daemons_.erase(it);
+}
+
 void EngineImpl::run()
 {
   if (MC_record_replay_is_active()) {
@@ -223,8 +230,8 @@ void EngineImpl::run()
       } 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())
-        for (auto const& dmon : simix_global->daemons) {
+      if (simix_global->process_list.size() == daemons_.size())
+        for (auto const& dmon : daemons_) {
           XBT_DEBUG("Kill %s", dmon->get_cname());
           simix_global->maestro_->kill(dmon);
         }
@@ -257,7 +264,7 @@ void EngineImpl::run()
               simix_global->actors_to_run.size());
 
     if (time < 0. && simix_global->actors_to_run.empty() && not simix_global->process_list.empty()) {
-      if (simix_global->process_list.size() <= simix_global->daemons.size()) {
+      if (simix_global->process_list.size() <= daemons_.size()) {
         XBT_CRITICAL("Oops! Daemon actors cannot do any blocking activity (communications, synchronization, etc) "
                      "once the simulation is over. Please fix your on_exit() functions.");
       } else {
index 8efbc76..1857b85 100644 (file)
@@ -13,6 +13,7 @@
 #include <xbt/functional.hpp>
 
 #include <map>
+#include <set>
 #include <string>
 #include <unordered_map>
 
@@ -28,6 +29,7 @@ class EngineImpl {
   std::vector<resource::Model*> models_;
   std::unordered_map<std::string, std::shared_ptr<resource::Model>> models_prio_;
   routing::NetZoneImpl* netzone_root_ = nullptr;
+  std::set<kernel::actor::ActorImpl*> daemons_;
 
   std::vector<xbt::Task<void()>> tasks;
   std::vector<xbt::Task<void()>> tasksTemp;
@@ -66,6 +68,8 @@ public:
     else
       return res->second;
   }
+  void add_daemon(actor::ActorImpl* d) { daemons_.insert(d); }
+  void rm_daemon(actor::ActorImpl* d);
 
   bool execute_tasks();
   void add_task(xbt::Task<void()>&& t) { tasks.push_back(std::move(t)); }
index b0f00d2..5c9ee3b 100644 (file)
@@ -7,6 +7,7 @@
 #include "simgrid/Exception.hpp"
 #include "simgrid/s4u/Actor.hpp"
 #include "simgrid/s4u/Exec.hpp"
+#include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/activity/CommImpl.hpp"
 #include "src/kernel/activity/ExecImpl.hpp"
 #include "src/kernel/activity/IoImpl.hpp"
@@ -329,21 +330,15 @@ void ActorImpl::daemonize()
 {
   if (not daemon_) {
     daemon_ = true;
-    simix_global->daemons.push_back(this);
+    EngineImpl::get_instance()->add_daemon(this);
   }
 }
 
 void ActorImpl::undaemonize()
 {
   if (daemon_) {
-    auto& vect = simix_global->daemons;
-    auto it    = std::find(vect.begin(), vect.end(), this);
-    xbt_assert(it != vect.end(), "The dying daemon is not a daemon after all. Please report that bug.");
-    /* Don't move the whole content since we don't really care about the order */
-
-    std::swap(*it, vect.back());
-    vect.pop_back();
     daemon_ = false;
+    EngineImpl::get_instance()->rm_daemon(this);
   }
 }
 
index 4034620..227c83f 100644 (file)
@@ -54,8 +54,6 @@ public:
   kernel::actor::ActorImpl* maestro_ = nullptr;
 
   std::mutex mutex;
-
-  std::vector<kernel::actor::ActorImpl*> daemons;
 };
 }
 }