From cecfeed61e8bcb4b53c2ed8e1b26d8c8af38b8e3 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 14 Sep 2019 03:40:47 +0300 Subject: libcamera: Switch to the std::chrono API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the clock_gettime()-based API with durations expressed as integers with the std::chrono API. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- test/timer.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'test/timer.cpp') diff --git a/test/timer.cpp b/test/timer.cpp index c30709d4..af922cb3 100644 --- a/test/timer.cpp +++ b/test/timer.cpp @@ -5,6 +5,7 @@ * timer.cpp - Timer test */ +#include #include #include @@ -28,28 +29,28 @@ public: void start(int msec) { interval_ = msec; - clock_gettime(CLOCK_MONOTONIC, &start_); - expiration_ = { 0, 0 }; + start_ = std::chrono::steady_clock::now(); + expiration_ = std::chrono::steady_clock::time_point(); Timer::start(msec); } int jitter() { - int duration = (expiration_.tv_sec - start_.tv_sec) * 1000; - duration += (expiration_.tv_nsec - start_.tv_nsec) / 1000000; - return abs(duration - interval_); + std::chrono::steady_clock::duration duration = expiration_ - start_; + int msecs = std::chrono::duration_cast(duration).count(); + return abs(msecs - interval_); } private: void timeoutHandler(Timer *timer) { - clock_gettime(CLOCK_MONOTONIC, &expiration_); + expiration_ = std::chrono::steady_clock::now(); } int interval_; - struct timespec start_; - struct timespec expiration_; + std::chrono::steady_clock::time_point start_; + std::chrono::steady_clock::time_point expiration_; }; class TimerTest : public Test -- cgit v1.2.1