Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move load_platf to EngineImpl
authorBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 7 Jun 2021 10:49:10 +0000 (12:49 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 7 Jun 2021 10:49:10 +0000 (12:49 +0200)
Keep platf lib opened until end of simulation in case of user is using
some network callback defined in it.

src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
src/s4u/s4u_Engine.cpp

index 79d4709..5832916 100644 (file)
 #include "src/surf/network_interface.hpp"
 #include "src/surf/xml/platf.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here
 
+#include <boost/algorithm/string/predicate.hpp>
+#ifndef _WIN32
+#include <dlfcn.h>
+#endif /* _WIN32 */
+
 XBT_LOG_NEW_DEFAULT_CATEGORY(ker_engine, "Logging specific to Engine (kernel)");
 
 namespace simgrid {
@@ -58,6 +63,34 @@ EngineImpl::~EngineImpl()
   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();
+  if (platf_handle_)
+    dlclose(platf_handle_);
+}
+
+void EngineImpl::load_platform(const std::string& platf)
+{
+  double start = xbt_os_time();
+  if (boost::algorithm::ends_with(platf, ".so") or boost::algorithm::ends_with(platf, ".dylib")) {
+#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());
+    using load_fct_t = void (*)(const simgrid::s4u::Engine&);
+    dlerror();
+    auto callable           = (load_fct_t)dlsym(platf_handle_, "load_platform");
+    const char* dlsym_error = dlerror();
+    xbt_assert(not dlsym_error, "Error: %s", dlsym_error);
+    callable(*simgrid::s4u::Engine::get_instance());
+#endif /* _WIN32 */
+  } else {
+    parse_platform_file(platf);
+  }
+
+  double end = xbt_os_time();
+  XBT_DEBUG("PARSE TIME: %g", (end - start));
 }
 
 void EngineImpl::load_deployment(const std::string& file) const
index a89924b..ef41d57 100644 (file)
@@ -67,6 +67,7 @@ class EngineImpl {
   std::vector<xbt::Task<void()>> tasksTemp;
 
   std::mutex mutex_;
+  void* platf_handle_ = nullptr; //!< handle for platform library
   friend s4u::Engine;
 
 public:
@@ -76,6 +77,7 @@ public:
   EngineImpl& operator=(const EngineImpl&) = delete;
   virtual ~EngineImpl();
 
+  void load_platform(const std::string& platf);
   void load_deployment(const std::string& file) const;
   void register_function(const std::string& name, const actor::ActorCodeFactory& code);
   void register_default(const actor::ActorCodeFactory& code);
index 51975c0..d70eb6e 100644 (file)
 #include "src/mc/mc_replay.hpp"
 #include "src/surf/network_interface.hpp"
 #include "surf/surf.hpp" // routing_platf. FIXME:KILLME. SOON
-#include <boost/algorithm/string/predicate.hpp>
 #include <simgrid/Exception.hpp>
 
 #include <algorithm>
-#ifndef _WIN32
-#include <dlfcn.h>
-#endif /* _WIN32 */
 #include <string>
 
 XBT_LOG_NEW_CATEGORY(s4u, "Log channels of the S4U (Simgrid for you) interface");
@@ -112,27 +108,7 @@ const std::vector<simgrid::kernel::resource::Model*>& Engine::get_all_models() c
  */
 void Engine::load_platform(const std::string& platf) const
 {
-  double start = xbt_os_time();
-  if (boost::algorithm::ends_with(platf, ".so") or boost::algorithm::ends_with(platf, ".dylib")) {
-#ifdef _WIN32
-    xbt_die("loading platform through shared library isn't supported on windows");
-#else
-    void* handle = dlopen(platf.c_str(), RTLD_LAZY);
-    xbt_assert(handle, "Impossible to open platform file: %s", platf.c_str());
-    using load_fct_t = void (*)(const Engine&);
-    dlerror();
-    auto callable           = (load_fct_t)dlsym(handle, "load_platform");
-    const char* dlsym_error = dlerror();
-    xbt_assert(not dlsym_error, "Error: %s", dlsym_error);
-    callable(*this);
-    dlclose(handle);
-#endif /* _WIN32 */
-  } else {
-    parse_platform_file(platf);
-  }
-
-  double end = xbt_os_time();
-  XBT_DEBUG("PARSE TIME: %g", (end - start));
+  pimpl->load_platform(platf);
 }
 
 void Engine::register_function(const std::string& name, int (*code)(int, char**)) // XBT_ATTRIB_DEPRECATED_v329