Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
easy sonar fixes
[simgrid.git] / src / kernel / EngineImpl.cpp
index 8e719a746162f567fa4195f0357d417d1763d011..39f49ee81b52a959b1aed62e0e450df72c47ac58 100644 (file)
@@ -10,6 +10,9 @@
 #include <simgrid/s4u/Host.hpp>
 #include <simgrid/sg_config.hpp>
 
+#define SIMIX_H_NO_DEPRECATED_WARNING // avoid deprecation warning on include (remove with XBT_ATTRIB_DEPRECATED_v332)
+#include <simgrid/simix.h>
+
 #include "mc/mc.h"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/resource/StandardLinkImpl.hpp"
@@ -41,24 +44,6 @@ config::Flag<double> cfg_breakpoint{"debug/breakpoint",
                                     "When non-negative, raise a SIGTRAP after given (simulated) time", -1.0};
 config::Flag<bool> cfg_verbose_exit{"debug/verbose-exit", "Display the actor status at exit", true};
 
-xbt_dynar_t get_actors_addr()
-{
-#if SIMGRID_HAVE_MC
-  return EngineImpl::get_instance()->get_actors_vector();
-#else
-  xbt_die("This function is intended to be used when compiling with MC");
-#endif
-}
-
-xbt_dynar_t get_dead_actors_addr()
-{
-#if SIMGRID_HAVE_MC
-  return EngineImpl::get_instance()->get_dead_actors_vector();
-#else
-  xbt_die("This function is intended to be used when compiling with MC");
-#endif
-}
-
 constexpr std::initializer_list<std::pair<const char*, context::ContextFactoryInitializer>> context_factories = {
 #if HAVE_RAW_CONTEXTS
     {"raw", &context::raw_factory},
@@ -203,7 +188,6 @@ EngineImpl::~EngineImpl()
     /* 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();
@@ -216,9 +200,9 @@ void EngineImpl::initialize(int* argc, char** argv)
   EngineImpl::instance_ = this;
 #if SIMGRID_HAVE_MC
   // The communication initialization is done ASAP, as we need to get some init parameters from the MC for different
-  // layers. But simix_global needs to be created, as we send the address of some of its fields to the MC that wants to
+  // layers. But instance_ needs to be created, as we send the address of some of its fields to the MC that wants to
   // read them directly.
-  simgrid::mc::AppSide::initialize();
+  simgrid::mc::AppSide::initialize(actors_vector_);
 #endif
 
   if (xbt_initialized == 0) {
@@ -349,6 +333,12 @@ void EngineImpl::shutdown()
 
 void EngineImpl::seal_platform() const
 {
+  /* Seal only once */
+  static bool sealed = false;
+  if (sealed)
+    return;
+  sealed = true;
+
   /* sealing resources before run: links */
   for (auto const& kv : links_)
     kv.second->get_iface()->seal();
@@ -463,6 +453,10 @@ void EngineImpl::run_all_actors()
 {
   instance_->get_context_factory()->run_all();
 
+  for (auto const& actor : actors_to_run_)
+    if (actor->context_->to_be_freed())
+      actor->cleanup_from_kernel();
+
   actors_to_run_.swap(actors_that_ran_);
   actors_to_run_.clear();
 }
@@ -531,9 +525,6 @@ void EngineImpl::empty_trash()
     XBT_DEBUG("Getting rid of %s (refcount: %d)", actor->get_cname(), actor->get_refcount());
     intrusive_ptr_release(actor);
   }
-#if SIMGRID_HAVE_MC
-  xbt_dynar_reset(dead_actors_vector_);
-#endif
 }
 
 void EngineImpl::display_all_actor_status() const
@@ -568,7 +559,7 @@ void EngineImpl::display_all_actor_status() const
                actor->waiting_synchro_->get_cname(), actor->waiting_synchro_->get_state_str());
     } else {
       XBT_INFO("Actor %ld (%s@%s) simcall %s", actor->get_pid(), actor->get_cname(), actor->get_host()->get_cname(),
-               SIMIX_simcall_name(actor->simcall_));
+               actor->simcall_.get_cname());
     }
   }
 }
@@ -700,6 +691,15 @@ void EngineImpl::run(double max_date)
 {
   seal_platform();
 
+  if (MC_is_active()) {
+#if SIMGRID_HAVE_MC
+    mc::AppSide::get()->main_loop();
+#else
+    xbt_die("MC_is_active() is not supposed to return true in non-MC settings");
+#endif
+    THROW_IMPOSSIBLE; // main_loop never returns
+  }
+
   if (MC_record_replay_is_active()) {
     mc::RecordTrace::replay(MC_record_path());
     empty_trash();
@@ -753,11 +753,9 @@ void EngineImpl::run(double max_date)
        *   and would thus be a pure waste of time.
        */
 
-      for (auto const& actor : actors_that_ran_) {
-        if (actor->simcall_.call_ != simix::Simcall::NONE) {
+      for (auto const& actor : actors_that_ran_)
+        if (actor->simcall_.call_ != actor::Simcall::Type::NONE)
           actor->simcall_handle(0);
-        }
-      }
 
       execute_tasks();
       do {