From b864bd066393e7a46f42eeffce3e7d3692e7c140 Mon Sep 17 00:00:00 2001 From: Jeff Hatch Date: Thu, 1 Feb 2018 07:57:36 -0600 Subject: Add monoTimeMicros() function --- include/mts/MTS_System.h | 4 ++++ src/MTS_System.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/mts/MTS_System.h b/include/mts/MTS_System.h index a16265c..bd5fa53 100644 --- a/include/mts/MTS_System.h +++ b/include/mts/MTS_System.h @@ -44,6 +44,10 @@ namespace MTS { static uint64_t timeMicros(); static uint64_t precisionTimeMicros(); + //MONOTONIC : number of seconds elapsed since some unspecified starting point. When time is changed by user, timer are unaffected. + + static uint64_t monoTimeMicros(); + static bool isBigEndian(); static void swapBytes(uint8_t* const pBuffer, const uint32_t iSize); diff --git a/src/MTS_System.cpp b/src/MTS_System.cpp index e1ed348..abed817 100644 --- a/src/MTS_System.cpp +++ b/src/MTS_System.cpp @@ -95,6 +95,21 @@ uint64_t System::precisionTimeMicros() { return micros; } +uint64_t System::monoTimeMicros() { + uint64_t micros = 0; +#ifdef WIN32 + micros = static_cast(GetTickCount64()) * 1000; +#else + timespec ts; + int result = clock_gettime(CLOCK_MONOTONIC, &ts); + if (result == 0) { + micros = (static_cast(ts.tv_sec) * 1000000) + + (ts.tv_nsec / 1000); + } +#endif + return micros; +} + bool System::isBigEndian() { static union { uint32_t i; -- cgit v1.2.3