Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make EngineImpl::tasksTemp a local variable.
[simgrid.git] / src / kernel / EngineImpl.cpp
index 5832916af59ddfe0a0a4935abebc6e21ad0a7c4e..d065c9fa2f668abc510c17c42bf2ce4921561bb4 100644 (file)
@@ -34,7 +34,6 @@ config::Flag<double> cfg_breakpoint{"debug/breakpoint",
                                     "When non-negative, raise a SIGTRAP after given (simulated) time", -1.0};
 EngineImpl::~EngineImpl()
 {
-
   while (not timer::kernel_timers().empty()) {
     delete timer::kernel_timers().top().second;
     timer::kernel_timers().pop();
@@ -65,8 +64,6 @@ EngineImpl::~EngineImpl()
 #endif
   /* clear models before freeing handle, network models can use external callback defined in the handle */
   models_prio_.clear();
-  if (platf_handle_)
-    dlclose(platf_handle_);
 }
 
 void EngineImpl::load_platform(const std::string& platf)
@@ -76,11 +73,11 @@ void EngineImpl::load_platform(const std::string& platf)
 #ifdef _WIN32
     xbt_die("loading platform through shared library isn't supported on windows");
 #else
-    platf_handle_ = dlopen(platf.c_str(), RTLD_LAZY);
-    xbt_assert(platf_handle_, "Impossible to open platform file: %s", platf.c_str());
+    void* handle = dlopen(platf.c_str(), RTLD_LAZY);
+    xbt_assert(handle, "Impossible to open platform file: %s", platf.c_str());
+    platf_handle_           = std::unique_ptr<void, std::function<int(void*)>>(handle, dlclose);
     using load_fct_t = void (*)(const simgrid::s4u::Engine&);
-    dlerror();
-    auto callable           = (load_fct_t)dlsym(platf_handle_, "load_platform");
+    auto callable           = (load_fct_t)dlsym(platf_handle_.get(), "load_platform");
     const char* dlsym_error = dlerror();
     xbt_assert(not dlsym_error, "Error: %s", dlsym_error);
     callable(*simgrid::s4u::Engine::get_instance());
@@ -126,6 +123,11 @@ void EngineImpl::add_model(std::shared_ptr<resource::Model> model, const std::ve
   models_prio_[model_name] = std::move(model);
 }
 
+void EngineImpl::add_split_duplex_link(const std::string& name, std::unique_ptr<resource::SplitDuplexLinkImpl> link)
+{
+  split_duplex_links_[name] = std::move(link);
+}
+
 /** Wake up all actors waiting for a Surf action to finish */
 void EngineImpl::wake_all_waiting_actors() const
 {
@@ -176,11 +178,10 @@ actor::ActorImpl* EngineImpl::get_actor_by_pid(aid_t pid)
 /** Execute all the tasks that are queued, e.g. `.then()` callbacks of futures. */
 bool EngineImpl::execute_tasks()
 {
-  xbt_assert(tasksTemp.empty());
-
   if (tasks.empty())
     return false;
 
+  std::vector<xbt::Task<void()>> tasksTemp;
   do {
     // We don't want the callbacks to modify the vector we are iterating over:
     tasks.swap(tasksTemp);