From 2343d9876dca65b2503f2c6c65a59b6d98d1ca41 Mon Sep 17 00:00:00 2001 From: Marcel Smit Date: Thu, 15 Apr 2021 18:42:46 +0200 Subject: [PATCH] Add missing methods to Linux Clock implementation. --- include/ableton/platforms/linux/Clock.hpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/include/ableton/platforms/linux/Clock.hpp b/include/ableton/platforms/linux/Clock.hpp index 0cc4d9ac..5f650731 100644 --- a/include/ableton/platforms/linux/Clock.hpp +++ b/include/ableton/platforms/linux/Clock.hpp @@ -39,12 +39,30 @@ template class Clock { public: - std::chrono::microseconds micros() const + using Ticks = std::uint64_t; + using Micros = std::chrono::microseconds; + + Micros ticksToMicros(const Ticks ticks) const + { + return Micros{llround(ticks / 1000ULL)}; + } + + Ticks microsToTicks(const Micros micros) const + { + return static_cast(micros.count() * 1000ULL); + } + + Ticks ticks() const { ::timespec ts; ::clock_gettime(CLOCK, &ts); std::uint64_t ns = ts.tv_sec * 1000000000ULL + ts.tv_nsec; - return std::chrono::microseconds(ns / 1000ULL); + return ns; + } + + std::chrono::microseconds micros() const + { + return ticksToMicros(ticks()); } };