Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move maestro to EngineImpl. breaks a unit-test
[simgrid.git] / src / kernel / EngineImpl.cpp
index 3a2ba74..c1b511a 100644 (file)
@@ -34,32 +34,64 @@ EngineImpl* EngineImpl::instance_ = nullptr; /* That singleton is awful too. */
 
 config::Flag<double> cfg_breakpoint{"debug/breakpoint",
                                     "When non-negative, raise a SIGTRAP after given (simulated) time", -1.0};
+
+EngineImpl::EngineImpl(int* argc, char** argv)
+{
+  EngineImpl::instance_ = this;
+}
+
+EngineImpl::~EngineImpl()
+{
+  /* Since hosts_ is a std::map, the hosts are destroyed in the lexicographic order, which ensures that the output is
+   * reproducible.
+   */
+  while (not hosts_.empty())
+    hosts_.begin()->second->destroy();
+
+  /* Also delete the other data */
+  delete netzone_root_;
+  for (auto const& kv : netpoints_)
+    delete kv.second;
+
+  for (auto const& kv : links_)
+    if (kv.second)
+      kv.second->destroy();
+
+  for (auto const& kv : mailboxes_)
+    delete kv.second;
+
+    /* Free the remaining data structures */
+#if SIMGRID_HAVE_MC
+  xbt_dynar_free(&actors_vector_);
+  xbt_dynar_free(&dead_actors_vector_);
+#endif
+  /* clear models before freeing handle, network models can use external callback defined in the handle */
+  models_prio_.clear();
+}
+
 void EngineImpl::shutdown()
 {
   static bool already_cleaned_up = false;
   if (already_cleaned_up)
     return; // to avoid double cleaning by java and C
   already_cleaned_up = true;
-  if (not EngineImpl::instance_) {
-    simix_global->destroy_maestro();
+  if (not instance_) {
     simix_global->destroy_context_factory();
     return; // Nothing more to shutdown
   }
   XBT_DEBUG("EngineImpl::shutdown() called. Simulation's over.");
-
-  /* Kill all actors (but maestro) */
-  simix_global->get_maestro()->kill_all();
-  instance_->run_all_actors();
-  instance_->empty_trash();
-
   if (instance_->has_actors_to_run() && simgrid_get_clock() <= 0.0) {
     XBT_CRITICAL("   ");
-    XBT_CRITICAL("The time is still 0, and you still have %lu processes ready to run.",
-                 instance_->get_actor_to_run_count());
+    XBT_CRITICAL("The time is still 0, and you still have processes ready to run.");
     XBT_CRITICAL("It seems that you forgot to run the simulation that you setup.");
     xbt_die("Bailing out to avoid that stop-before-start madness. Please fix your code.");
   }
 
+  /* Kill all actors (but maestro) */
+  instance_->maestro_->kill_all();
+  instance_->run_all_actors();
+  instance_->empty_trash();
+
 #if HAVE_SMPI
   if (not instance_->actor_list_.empty()) {
     if (smpi_process()->initialized()) {
@@ -72,7 +104,7 @@ void EngineImpl::shutdown()
 #endif
 
   /* Let's free maestro now */
-  simix_global->destroy_maestro();
+  instance_->destroy_maestro();
 
   /* Finish context module and SURF */
   simix_global->destroy_context_factory();
@@ -84,38 +116,10 @@ void EngineImpl::shutdown()
 
   tmgr_finalize();
   sg_platf_exit();
-  simgrid::s4u::Engine::shutdown();
 
   simix_global = nullptr;
-}
-
-EngineImpl::~EngineImpl()
-{
-  /* Since hosts_ is a std::map, the hosts are destroyed in the lexicographic order, which ensures that the output is
-   * reproducible.
-   */
-  while (not hosts_.empty())
-    hosts_.begin()->second->destroy();
-
-  /* Also delete the other data */
-  delete netzone_root_;
-  for (auto const& kv : netpoints_)
-    delete kv.second;
-
-  for (auto const& kv : links_)
-    if (kv.second)
-      kv.second->destroy();
-
-  for (auto const& kv : mailboxes_)
-    delete kv.second;
-
-    /* Free the remaining data structures */
-#if SIMGRID_HAVE_MC
-  xbt_dynar_free(&actors_vector_);
-  xbt_dynar_free(&dead_actors_vector_);
-#endif
-  /* clear models before freeing handle, network models can use external callback defined in the handle */
-  models_prio_.clear();
+  delete instance_;
+  instance_ = nullptr;
 }
 
 void EngineImpl::load_platform(const std::string& platf)
@@ -429,7 +433,7 @@ void EngineImpl::run()
       if (actor_list_.size() == daemons_.size())
         for (auto const& dmon : daemons_) {
           XBT_DEBUG("Kill %s", dmon->get_cname());
-          simix_global->get_maestro()->kill(dmon);
+          maestro_->kill(dmon);
         }
     }
 
@@ -469,7 +473,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->get_maestro()->kill(kv.second);
+        maestro_->kill(kv.second);
       }
     }
   } while (time > -1.0 || has_actors_to_run());