1 /* Copyright (c) 2016. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_CHRONO_HPP
7 #define SIMGRID_CHRONO_HPP
9 /** @file chrono.hpp Time support
11 * Define clock, duration types, time point types compatible with the standard
18 #include <simgrid/simix.h>
22 /** A C++ compatible TrivialClock working with simulated-time */
23 struct SimulationClock {
25 using period = std::ratio<1>;
26 using duration = std::chrono::duration<rep, period>;
27 using time_point = std::chrono::time_point<SimulationClock, duration>;
28 static constexpr bool is_steady = true;
29 static time_point now()
31 return time_point(duration(SIMIX_get_clock()));
35 /** Default duration for simulated time */
36 using SimulationClockDuration = SimulationClock::duration;
38 /** Default time point for simulated time */
39 using SimulationClockTimePoint = SimulationClock::time_point;
41 // Durations based on doubles:
42 using nanoseconds = std::chrono::duration<double, std::nano>;
43 using microseconds = std::chrono::duration<double, std::micro>;
44 using milliseconds = std::chrono::duration<double, std::milli>;
45 using seconds = std::chrono::duration<double>;
46 using minutes = std::chrono::duration<double, std::ratio<60>>;
47 using hours = std::chrono::duration<double, std::ratio<3600>>;
49 /** A time point in the simulated time */
50 template<class Duration>
51 using SimulationTimePoint = std::chrono::time_point<SimulationClock, Duration>;