Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make simix_global->maestro_ private
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Wed, 26 May 2021 14:39:49 +0000 (16:39 +0200)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Wed, 26 May 2021 15:04:06 +0000 (17:04 +0200)
src/kernel/EngineImpl.cpp
src/kernel/actor/ActorImpl.cpp
src/kernel/context/ContextThread.cpp
src/simix/popping_bodies.cpp
src/simix/simcalls.py
src/simix/smx_global.cpp
src/simix/smx_private.hpp

index 6b10f2a..ab02ceb 100644 (file)
@@ -341,7 +341,7 @@ void EngineImpl::run()
       if (actor_list_.size() == daemons_.size())
         for (auto const& dmon : daemons_) {
           XBT_DEBUG("Kill %s", dmon->get_cname());
-          simix_global->maestro_->kill(dmon);
+          simix_global->get_maestro()->kill(dmon);
         }
     }
 
@@ -381,7 +381,7 @@ void EngineImpl::run()
       simgrid::s4u::Engine::on_deadlock();
       for (auto const& kv : actor_list_) {
         XBT_DEBUG("Kill %s", kv.second->get_cname());
-        simix_global->maestro_->kill(kv.second);
+        simix_global->get_maestro()->kill(kv.second);
       }
     }
   } while (time > -1.0 || has_actors_to_run());
index b4852cd..edfd15c 100644 (file)
@@ -71,7 +71,7 @@ ActorImpl::ActorImpl(xbt::string name, s4u::Host* host) : host_(host), name_(std
 
 ActorImpl::~ActorImpl()
 {
-  if (simix_global != nullptr && this != simix_global->maestro_)
+  if (simix_global != nullptr && not simix_global->is_maestro(this))
     s4u::Actor::on_destruction(*get_ciface());
 }
 
@@ -176,7 +176,7 @@ void ActorImpl::cleanup()
 
   XBT_DEBUG("%s@%s(%ld) should not run anymore", get_cname(), get_host()->get_cname(), get_pid());
 
-  if (this == simix_global->maestro_) /* Do not cleanup maestro */
+  if (simix_global->is_maestro(this)) /* Do not cleanup maestro */
     return;
 
   XBT_DEBUG("Cleanup actor %s (%p), waiting synchro %p", get_cname(), this, waiting_synchro_.get());
@@ -233,7 +233,7 @@ void ActorImpl::exit()
 
 void ActorImpl::kill(ActorImpl* actor) const
 {
-  xbt_assert(actor != simix_global->maestro_, "Killing maestro is a rather bad idea");
+  xbt_assert(not simix_global->is_maestro(actor), "Killing maestro is a rather bad idea");
   if (actor->finished_) {
     XBT_DEBUG("Ignoring request to kill actor %s@%s that is already dead", actor->get_cname(),
               actor->host_->get_cname());
@@ -331,7 +331,7 @@ void ActorImpl::undaemonize()
 
 s4u::Actor* ActorImpl::restart()
 {
-  xbt_assert(this != simix_global->maestro_, "Restarting maestro is not supported");
+  xbt_assert(not simix_global->is_maestro(this), "Restarting maestro is not supported");
 
   XBT_DEBUG("Restarting actor %s on %s", get_cname(), host_->get_cname());
 
@@ -425,7 +425,7 @@ void ActorImpl::throw_exception(std::exception_ptr e)
 
 void ActorImpl::simcall_answer()
 {
-  if (this != simix_global->maestro_) {
+  if (not simix_global->is_maestro(this)) {
     XBT_DEBUG("Answer simcall %s issued by %s (%p)", SIMIX_simcall_name(simcall_), get_cname(), this);
     xbt_assert(simcall_.call_ != simix::Simcall::NONE);
     simcall_.call_ = simix::Simcall::NONE;
@@ -515,7 +515,7 @@ void create_maestro(const std::function<void()>& code)
   }
 
   maestro->simcall_.issuer_     = maestro;
-  simix_global->maestro_        = maestro;
+  simix_global->set_maestro(maestro);
 }
 
 } // namespace actor
index 7b25fc6..a29203f 100644 (file)
@@ -157,7 +157,7 @@ void ThreadContext::suspend()
 void ThreadContext::attach_start()
 {
   // We're breaking the layers here by depending on the upper layer:
-  auto* maestro = static_cast<ThreadContext*>(simix_global->maestro_->context_.get());
+  auto* maestro = static_cast<ThreadContext*>(simix_global->get_maestro()->context_.get());
   maestro->begin_.release();
   xbt_assert(not this->is_maestro());
   this->start();
@@ -168,7 +168,7 @@ void ThreadContext::attach_stop()
   xbt_assert(not this->is_maestro());
   this->yield();
 
-  auto* maestro = static_cast<ThreadContext*>(simix_global->maestro_->context_.get());
+  auto* maestro = static_cast<ThreadContext*>(simix_global->get_maestro()->context_.get());
   maestro->end_.acquire();
 
   Context::set_current(nullptr);
index 6948f46..d9be221 100644 (file)
@@ -31,7 +31,7 @@ inline static R simcall(Simcall call, T const&... t)
 {
   smx_actor_t self = SIMIX_process_self();
   simgrid::simix::marshal(&self->simcall_, call, t...);
-  if (self != simix_global->maestro_) {
+  if (not simix_global->is_maestro(self)) {
     XBT_DEBUG("Yield process '%s' on simcall %s", self->get_cname(), SIMIX_simcall_name(self->simcall_));
     self->yield();
   } else {
index 2ed634d..fb346f8 100755 (executable)
@@ -380,7 +380,7 @@ inline static R simcall(Simcall call, T const&... t)
 {
   smx_actor_t self = SIMIX_process_self();
   simgrid::simix::marshal(&self->simcall_, call, t...);
-  if (self != simix_global->maestro_) {
+  if (not simix_global->is_maestro(self)) {
     XBT_DEBUG("Yield process '%s' on simcall %s", self->get_cname(), SIMIX_simcall_name(self->simcall_));
     self->yield();
   } else {
index bf12e24..40055f0 100644 (file)
@@ -166,7 +166,6 @@ void SIMIX_global_init(int* argc, char** argv)
 
   surf_init(argc, argv); /* Initialize SURF structures */
 
-  simix_global->maestro_ = nullptr;
   SIMIX_context_mod_init();
 
   // Either create a new context with maestro or create
@@ -221,13 +220,12 @@ void SIMIX_clean()
 #endif
 
   /* Kill all processes (but maestro) */
-  simix_global->maestro_->kill_all();
+  simix_global->get_maestro()->kill_all();
   engine->run_all_actors();
   engine->empty_trash();
 
   /* Let's free maestro now */
-  delete simix_global->maestro_;
-  simix_global->maestro_ = nullptr;
+  simix_global->destroy_maestro();
 
   /* Finish context module and SURF */
   simix_global->destroy_context_factory();
@@ -288,6 +286,6 @@ int SIMIX_is_maestro()
 {
   if (simix_global == nullptr) // SimDag
     return true;
-  const simgrid::kernel::actor::ActorImpl* self = SIMIX_process_self();
-  return self == nullptr || self == simix_global->maestro_;
+  simgrid::kernel::actor::ActorImpl* self = SIMIX_process_self();
+  return self == nullptr || simix_global->is_maestro(self);
 }
index a57df81..6945526 100644 (file)
@@ -17,9 +17,18 @@ namespace simix {
 
 class Global {
   kernel::context::ContextFactory* context_factory_ = nullptr;
+  kernel::actor::ActorImpl* maestro_                = nullptr;
 
 public:
-  kernel::actor::ActorImpl* maestro_ = nullptr;
+  bool is_maestro(kernel::actor::ActorImpl* actor) const { return actor == maestro_; }
+  void set_maestro(kernel::actor::ActorImpl* actor) { maestro_ = actor; }
+  kernel::actor::ActorImpl* get_maestro() const { return maestro_; }
+  void destroy_maestro()
+  {
+    delete maestro_;
+    maestro_ = nullptr;
+  }
+
   kernel::context::ContextFactory* get_context_factory() const { return context_factory_; }
   void set_context_factory(kernel::context::ContextFactory* factory) { context_factory_ = factory; }
   bool has_context_factory() const { return context_factory_ != nullptr; }