-/* 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
#include <xbt/functional.hpp>
#include <xbt/future.hpp>
#include <xbt/signal.hpp>
+#include <xbt/utility.hpp>
#include <boost/heap/fibonacci_heap.hpp>
#include <string>
* 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:
// 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();
namespace simgrid {
namespace simix {
-
-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)) {}
}
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