From: SUTER Frederic Date: Wed, 26 May 2021 10:37:29 +0000 (+0200) Subject: prepare transition of context_factory: make it private X-Git-Tag: v3.28~227 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/289295b516f9d71a4085af90fcce8db803779937 prepare transition of context_factory: make it private --- diff --git a/src/include/xbt/parmap.hpp b/src/include/xbt/parmap.hpp index 1d23673478..ae03c0cd45 100644 --- a/src/include/xbt/parmap.hpp +++ b/src/include/xbt/parmap.hpp @@ -288,7 +288,8 @@ template void Parmap::worker_main(ThreadData* data) { Parmap& parmap = data->parmap; unsigned round = 0; - kernel::context::Context* context = simix_global->context_factory->create_context(std::function(), nullptr); + kernel::context::Context* context = + simix_global->get_context_factory()->create_context(std::function(), nullptr); kernel::context::Context::set_current(context); XBT_CDEBUG(xbt_parmap, "New worker thread created"); diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 97e95b0cef..6b10f2a9b6 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -122,7 +122,7 @@ void EngineImpl::wake_all_waiting_actors() const */ void EngineImpl::run_all_actors() { - simix_global->context_factory->run_all(); + simix_global->get_context_factory()->run_all(); actors_to_run_.swap(actors_that_ran_); actors_to_run_.clear(); diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index a54c8c7f42..b4852cd955 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -101,7 +101,7 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h XBT_VERB("Create context %s", actor->get_cname()); xbt_assert(simix_global != nullptr, "simix is not initialized, please call MSG_init first"); - actor->context_.reset(simix_global->context_factory->attach(actor)); + actor->context_.reset(simix_global->get_context_factory()->attach(actor)); /* Add the actor to it's host actor list */ host->get_impl()->add_actor(actor); @@ -470,7 +470,7 @@ ActorImpl* ActorImpl::start(const ActorCode& code) this->code_ = code; XBT_VERB("Create context %s", get_cname()); - context_.reset(simix_global->context_factory->create_context(ActorCode(code), this)); + context_.reset(simix_global->get_context_factory()->create_context(ActorCode(code), this)); XBT_DEBUG("Start context '%s'", get_cname()); @@ -509,9 +509,9 @@ void create_maestro(const std::function& code) auto* maestro = new ActorImpl(xbt::string(""), /*host*/ nullptr); if (not code) { - maestro->context_.reset(simix_global->context_factory->create_context(ActorCode(), maestro)); + maestro->context_.reset(simix_global->get_context_factory()->create_context(ActorCode(), maestro)); } else { - maestro->context_.reset(simix_global->context_factory->create_maestro(ActorCode(code), maestro)); + maestro->context_.reset(simix_global->get_context_factory()->create_maestro(ActorCode(code), maestro)); } maestro->simcall_.issuer_ = maestro; diff --git a/src/kernel/context/Context.hpp b/src/kernel/context/Context.hpp index e26bb2e027..b467843118 100644 --- a/src/kernel/context/Context.hpp +++ b/src/kernel/context/Context.hpp @@ -108,5 +108,4 @@ XBT_PRIVATE ContextFactory* boost_factory(); } // namespace simgrid XBT_PRIVATE void SIMIX_context_mod_init(); -XBT_PRIVATE void SIMIX_context_mod_exit(); #endif diff --git a/src/simix/smx_context.cpp b/src/simix/smx_context.cpp index 58516d8ba7..783ffab84b 100644 --- a/src/simix/smx_context.cpp +++ b/src/simix/smx_context.cpp @@ -58,7 +58,7 @@ static e_xbt_parmap_mode_t smx_parallel_synchronization_mode = XBT_PARMAP_DEFAUL */ void SIMIX_context_mod_init() { - xbt_assert(simix_global->context_factory == nullptr); + xbt_assert(not simix_global->has_context_factory()); #if HAVE_SMPI && (defined(__APPLE__) || defined(__NetBSD__)) smpi_init_options(); @@ -79,17 +79,17 @@ void SIMIX_context_mod_init() /* select the context factory to use to create the contexts */ if (simgrid::kernel::context::factory_initializer != nullptr) { // Give Java a chance to hijack the factory mechanism - simix_global->context_factory = simgrid::kernel::context::factory_initializer(); + simix_global->set_context_factory(simgrid::kernel::context::factory_initializer()); return; } /* use the factory specified by --cfg=contexts/factory:value */ for (auto const& factory : context_factories) if (context_factory_name == factory.first) { - simix_global->context_factory = factory.second(); + simix_global->set_context_factory(factory.second()); break; } - if (simix_global->context_factory == nullptr) { + if (not simix_global->has_context_factory()) { XBT_ERROR("Invalid context factory specified. Valid factories on this machine:"); #if HAVE_RAW_CONTEXTS XBT_ERROR(" raw: high performance context factory implemented specifically for SimGrid"); @@ -111,15 +111,6 @@ void SIMIX_context_mod_init() } } -/** - * This function is called by SIMIX_clean() to finalize the context module. - */ -void SIMIX_context_mod_exit() -{ - delete simix_global->context_factory; - simix_global->context_factory = nullptr; -} - /** @brief Returns whether some parallel threads are used for the user contexts. */ int SIMIX_context_is_parallel() { return smx_parallel_contexts > 1; diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 79256d4894..bf12e24bd9 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -230,7 +230,7 @@ void SIMIX_clean() simix_global->maestro_ = nullptr; /* Finish context module and SURF */ - SIMIX_context_mod_exit(); + simix_global->destroy_context_factory(); surf_exit(); diff --git a/src/simix/smx_private.hpp b/src/simix/smx_private.hpp index 054f2ecdf0..a57df81100 100644 --- a/src/simix/smx_private.hpp +++ b/src/simix/smx_private.hpp @@ -16,11 +16,18 @@ namespace simgrid { namespace simix { class Global { -public: + kernel::context::ContextFactory* context_factory_ = nullptr; - kernel::context::ContextFactory* context_factory = nullptr; +public: kernel::actor::ActorImpl* 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; } + void destroy_context_factory() + { + delete context_factory_; + context_factory_ = nullptr; + } }; } }