Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way IO activities are initiated
[simgrid.git] / include / simgrid / simix.hpp
index 685e8eb..dbafbfa 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2020. The SimGrid Team.
+/* Copyright (c) 2007-2021. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -11,6 +11,7 @@
 #include <xbt/functional.hpp>
 #include <xbt/future.hpp>
 #include <xbt/signal.hpp>
+#include <xbt/utility.hpp>
 
 #include <boost/heap/fibonacci_heap.hpp>
 #include <string>
@@ -42,7 +43,7 @@ namespace actor {
  * you may need to wait for that mutex to be unlocked by its current owner.
  * Potentially blocking simcall must be issued using simcall_blocking(), right below in this file.
  */
-template <class F> typename std::result_of<F()>::type simcall(F&& code, mc::SimcallInspector* t = nullptr)
+template <class F> typename std::result_of_t<F()> simcall(F&& code, mc::SimcallInspector* t = nullptr)
 {
   // If we are in the maestro, we take the fast path and execute the
   // code directly without simcall marshalling/unmarshalling/dispatch:
@@ -52,7 +53,7 @@ template <class F> typename std::result_of<F()>::type simcall(F&& code, mc::Simc
   // If we are in the application, pass the code to the maestro which
   // executes it for us and reports the result. We use a std::future which
   // conveniently handles the success/failure value for us.
-  typedef typename std::result_of<F()>::type R;
+  using R = typename std::result_of_t<F()>;
   simgrid::xbt::Result<R> result;
   simcall_run_kernel([&result, &code] { simgrid::xbt::fulfill_promise(result, std::forward<F>(code)); }, t);
   return result.get();
@@ -95,28 +96,24 @@ template <class R, class F> R simcall_blocking(F&& code, mc::SimcallInspector* t
 namespace simgrid {
 namespace simix {
 
-// What's executed as SIMIX actor code:
-typedef std::function<void()> ActorCode;
-
-// Create an ActorCode based on a std::string
-typedef std::function<ActorCode(std::vector<std::string> args)> ActorCodeFactory;
-
-XBT_PUBLIC void register_function(const std::string& name, const ActorCodeFactory& factory);
-
-typedef std::pair<double, Timer*> TimerQelt;
-static boost::heap::fibonacci_heap<TimerQelt, boost::heap::compare<xbt::HeapComparator<TimerQelt>>> simix_timers;
+inline auto& simix_timers() // avoid static initialization order fiasco
+{
+  using TimerQelt = std::pair<double, Timer*>;
+  static boost::heap::fibonacci_heap<TimerQelt, boost::heap::compare<xbt::HeapComparator<TimerQelt>>> value;
+  return value;
+}
 
 /** @brief Timer datatype */
 class Timer {
   double date = 0.0;
 
 public:
-  decltype(simix_timers)::handle_type handle_;
+  std::remove_reference_t<decltype(simix_timers())>::handle_type handle_;
 
   Timer(double date, simgrid::xbt::Task<void()>&& callback) : date(date), callback(std::move(callback)) {}
 
   simgrid::xbt::Task<void()> callback;
-  double get_date() { return date; }
+  double get_date() const { return date; }
   void remove();
 
   template <class F> static inline Timer* set(double date, F callback)
@@ -125,14 +122,10 @@ public:
   }
 
   static Timer* set(double date, simgrid::xbt::Task<void()>&& callback);
-  static double next() { return simix_timers.empty() ? -1.0 : simix_timers.top().first; }
+  static double next() { return simix_timers().empty() ? -1.0 : simix_timers().top().first; }
 };
 
 } // namespace simix
 } // namespace simgrid
 
-XBT_PUBLIC smx_actor_t simcall_process_create(const std::string& name, const simgrid::simix::ActorCode& code,
-                                              void* data, sg_host_t host,
-                                              std::unordered_map<std::string, std::string>* properties);
-
 #endif