From 4e7df12e1e81b2ff9212175628873d6d880b6630 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 1 Nov 2019 17:56:56 +0100 Subject: [PATCH] Reduce number of direct accesses to simix_global. --- src/kernel/actor/ActorImpl.cpp | 8 ++------ src/s4u/s4u_Actor.cpp | 9 ++------- src/s4u/s4u_Host.cpp | 10 ++-------- src/simix/smx_global.cpp | 6 ++++-- src/simix/smx_private.hpp | 2 -- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 78be44fcf9..5f5bb5958e 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -222,6 +222,7 @@ void ActorImpl::exit() void ActorImpl::kill(ActorImpl* actor) { + xbt_assert(actor != simix_global->maestro_process, "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()); @@ -553,12 +554,7 @@ void SIMIX_process_self_set_data(void* data) by exceptions and logging events */ const char* SIMIX_process_self_get_name() { - - smx_actor_t process = SIMIX_process_self(); - if (process == nullptr || process == simix_global->maestro_process) - return "maestro"; - - return process->get_cname(); + return SIMIX_is_maestro() ? "maestro" : SIMIX_process_self()->get_cname(); } /** diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 154d5fbf78..80cd55af9b 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -13,7 +13,6 @@ #include "src/include/mc/mc.h" #include "src/kernel/activity/ExecImpl.hpp" #include "src/mc/mc_replay.hpp" -#include "src/simix/smx_private.hpp" #include "src/surf/HostImpl.hpp" #include @@ -219,10 +218,7 @@ double Actor::get_kill_time() void Actor::kill() { kernel::actor::ActorImpl* self = SIMIX_process_self(); - kernel::actor::simcall([this, self] { - xbt_assert(pimpl_ != simix_global->maestro_process, "Killing maestro is a rather bad idea"); - self->kill(pimpl_); - }); + kernel::actor::simcall([this, self] { self->kill(pimpl_); }); } // ***** Static functions ***** @@ -278,8 +274,7 @@ namespace this_actor { */ bool is_maestro() { - kernel::actor::ActorImpl* self = SIMIX_process_self(); - return self == nullptr || self == simix_global->maestro_process; + return SIMIX_is_maestro(); } void sleep_for(double duration) diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 881f96748a..71710c4e0f 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -9,7 +9,6 @@ #include "simgrid/s4u/Exec.hpp" #include "simgrid/s4u/VirtualMachine.hpp" #include "src/plugins/vm/VirtualMachineImpl.hpp" -#include "src/simix/smx_private.hpp" #include "src/surf/HostImpl.hpp" #include @@ -655,18 +654,13 @@ void sg_host_get_actor_list(sg_host_t host, xbt_dynar_t whereto) sg_host_t sg_host_self() { - simgrid::kernel::actor::ActorImpl* self = SIMIX_process_self(); - return (self == nullptr) ? nullptr : self->get_host(); + return SIMIX_is_maestro() ? nullptr : SIMIX_process_self()->get_host(); } /* needs to be public and without simcall for exceptions and logging events */ const char* sg_host_self_get_name() { - sg_host_t host = sg_host_self(); - if (host == nullptr || SIMIX_process_self() == simix_global->maestro_process) - return ""; - - return host->get_cname(); + return SIMIX_is_maestro() ? "" : SIMIX_process_self()->get_host()->get_cname(); } double sg_host_load(sg_host_t host) diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index a00699793c..04673e2276 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -600,6 +600,8 @@ void SIMIX_display_process_status() int SIMIX_is_maestro() { - smx_actor_t self = SIMIX_process_self(); - return simix_global == nullptr /*SimDag*/ || self == nullptr || self == simix_global->maestro_process; + if (simix_global == nullptr) // SimDag + return true; + simgrid::kernel::actor::ActorImpl* self = SIMIX_process_self(); + return self == nullptr || self == simix_global->maestro_process; } diff --git a/src/simix/smx_private.hpp b/src/simix/smx_private.hpp index 26893347ab..18b0131af8 100644 --- a/src/simix/smx_private.hpp +++ b/src/simix/smx_private.hpp @@ -21,8 +21,6 @@ namespace simgrid { namespace simix { class Global { - friend XBT_PUBLIC bool simgrid::s4u::this_actor::is_maestro(); - public: bool execute_tasks(); /** -- 2.20.1