Added monotonic_clock class in time.h
Change-Id: Iea80a7cde09a985f7fbf64090c58aeccde38e949
diff --git a/aos/common/time.h b/aos/common/time.h
index a176ba0..40b72b0 100644
--- a/aos/common/time.h
+++ b/aos/common/time.h
@@ -7,12 +7,31 @@
#include <stdint.h>
#include <type_traits>
+#include <chrono>
+#include <thread>
#include <ostream>
#include "aos/common/type_traits.h"
#include "aos/common/macros.h"
namespace aos {
+
+class monotonic_clock {
+ public:
+ typedef ::std::chrono::nanoseconds::rep rep;
+ typedef ::std::chrono::nanoseconds::period period;
+ typedef ::std::chrono::nanoseconds duration;
+ typedef ::std::chrono::time_point<monotonic_clock> time_point;
+
+ static monotonic_clock::time_point now() noexcept;
+ static constexpr bool is_steady = true;
+
+ // Returns the epoch (0).
+ static constexpr monotonic_clock::time_point epoch() {
+ return time_point(duration(0));
+ }
+};
+
namespace time {
// A nice structure for representing times.
@@ -280,4 +299,15 @@
} // namespace time
} // namespace aos
+namespace std {
+namespace this_thread {
+// Template specialization for monotonic_clock, since we can use clock_nanosleep
+// with TIMER_ABSTIME and get very precise absolute time sleeps.
+template <>
+void sleep_until(const ::aos::monotonic_clock::time_point &end_time);
+
+} // namespace this_thread
+} // namespace std
+
+
#endif // AOS_COMMON_TIME_H_