Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
prepare transition of context_factory: make it private
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Wed, 26 May 2021 10:37:29 +0000 (12:37 +0200)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Wed, 26 May 2021 10:37:36 +0000 (12:37 +0200)
src/include/xbt/parmap.hpp
src/kernel/EngineImpl.cpp
src/kernel/actor/ActorImpl.cpp
src/kernel/context/Context.hpp
src/simix/smx_context.cpp
src/simix/smx_global.cpp
src/simix/smx_private.hpp

index 1d23673..ae03c0c 100644 (file)
@@ -288,7 +288,8 @@ template <typename T> void Parmap<T>::worker_main(ThreadData* data)
 {
   Parmap<T>& parmap     = data->parmap;
   unsigned round        = 0;
-  kernel::context::Context* context = simix_global->context_factory->create_context(std::function<void()>(), nullptr);
+  kernel::context::Context* context =
+      simix_global->get_context_factory()->create_context(std::function<void()>(), nullptr);
   kernel::context::Context::set_current(context);
 
   XBT_CDEBUG(xbt_parmap, "New worker thread created");
index 97e95b0..6b10f2a 100644 (file)
@@ -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();
index a54c8c7..b4852cd 100644 (file)
@@ -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<void()>& 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;
index e26bb2e..b467843 100644 (file)
@@ -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
index 58516d8..783ffab 100644 (file)
@@ -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;
index 79256d4..bf12e24 100644 (file)
@@ -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();
 
index 054f2ec..a57df81 100644 (file)
@@ -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;
+  }
 };
 }
 }