From: SUTER Frederic Date: Wed, 26 May 2021 14:39:49 +0000 (+0200) Subject: make simix_global->maestro_ private X-Git-Tag: v3.28~222 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cb305a8cc20cc267f909dca81b06a7036f3bc639 make simix_global->maestro_ private --- diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 6b10f2a9b6..ab02cebdd3 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -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()); diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index b4852cd955..edfd15cfb2 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -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& code) } maestro->simcall_.issuer_ = maestro; - simix_global->maestro_ = maestro; + simix_global->set_maestro(maestro); } } // namespace actor diff --git a/src/kernel/context/ContextThread.cpp b/src/kernel/context/ContextThread.cpp index 7b25fc6d9c..a29203fae6 100644 --- a/src/kernel/context/ContextThread.cpp +++ b/src/kernel/context/ContextThread.cpp @@ -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(simix_global->maestro_->context_.get()); + auto* maestro = static_cast(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(simix_global->maestro_->context_.get()); + auto* maestro = static_cast(simix_global->get_maestro()->context_.get()); maestro->end_.acquire(); Context::set_current(nullptr); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index 6948f46442..d9be2217f8 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -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 { diff --git a/src/simix/simcalls.py b/src/simix/simcalls.py index 2ed634dc3f..fb346f8d8f 100755 --- a/src/simix/simcalls.py +++ b/src/simix/simcalls.py @@ -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 { diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index bf12e24bd9..40055f0ef5 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -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); } diff --git a/src/simix/smx_private.hpp b/src/simix/smx_private.hpp index a57df81100..6945526db1 100644 --- a/src/simix/smx_private.hpp +++ b/src/simix/smx_private.hpp @@ -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; }