]> AND Public Git Repository - simgrid.git/blobdiff - include/simgrid/simix.hpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: simplify initialization and kill api::set_checker()
[simgrid.git] / include / simgrid / simix.hpp
index a75c594261aab9f696f00b26fa4bfe8f6a6f6e43..76fd191006e09c19ed8c44cb5b371d5511ae442c 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <simgrid/simix.h>
 #include <xbt/functional.hpp>
-#include <xbt/future.hpp>
+#include <xbt/promise.hpp>
 #include <xbt/signal.hpp>
 #include <xbt/utility.hpp>
 
@@ -17,8 +17,8 @@
 #include <string>
 #include <unordered_map>
 
-XBT_PUBLIC void simcall_run_kernel(std::function<void()> const& code, simgrid::mc::SimcallInspector* t);
-XBT_PUBLIC void simcall_run_blocking(std::function<void()> const& code, simgrid::mc::SimcallInspector* t);
+XBT_PUBLIC void simcall_run_kernel(std::function<void()> const& code, simgrid::mc::SimcallObserver* t);
+XBT_PUBLIC void simcall_run_blocking(std::function<void()> const& code, simgrid::mc::SimcallObserver* t);
 
 namespace simgrid {
 namespace kernel {
@@ -43,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_t<F()> simcall(F&& code, mc::SimcallInspector* t = nullptr)
+template <class F> typename std::result_of_t<F()> simcall(F&& code, mc::SimcallObserver* t = nullptr)
 {
   // If we are in the maestro, we take the fast path and execute the
   // code directly without simcall marshalling/unmarshalling/dispatch:
@@ -76,7 +76,7 @@ template <class F> typename std::result_of_t<F()> simcall(F&& code, mc::SimcallI
  *
  * If your code never calls actor->simcall_answer() itself, the actor will never return from its simcall.
  */
-template <class R, class F> R simcall_blocking(F&& code, mc::SimcallInspector* t = nullptr)
+template <class R, class F> R simcall_blocking(F&& code, mc::SimcallObserver* t = nullptr)
 {
   // If we are in the maestro, we take the fast path and execute the
   // code directly without simcall marshalling/unmarshalling/dispatch:
@@ -96,15 +96,19 @@ template <class R, class F> R simcall_blocking(F&& code, mc::SimcallInspector* t
 namespace simgrid {
 namespace simix {
 
-using TimerQelt = std::pair<double, Timer*>;
-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)) {}
 
@@ -118,7 +122,7 @@ 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