From c6d02936e93584837ce1b16cb5a59a24ed49dce8 Mon Sep 17 00:00:00 2001 From: "Joseph C. Lehner" Date: Fri, 18 Nov 2016 17:26:53 +0100 Subject: [PATCH] Add util.c --- util.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 util.c diff --git a/util.c b/util.c new file mode 100644 index 0000000..ff2b191 --- /dev/null +++ b/util.c @@ -0,0 +1,36 @@ +#include + +#ifdef NMRPFLASH_OSX +#include +#endif + +time_t time_monotonic() +{ +#ifndef NMRPFLASH_WINDOWS +#ifndef NMRPFLASH_OSX + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.ts_sec; +#else + static double factor = 0.0; + mach_timebase_info_data_t timebase; + if (factor == 0.0) { + mach_timebase_info(&timebase); + factor = (double)timebase.numer / timebase.denom; + } + + return round(mach_absolute_time() * factor / 1e9); +#endif +#else + return round(GetTickCount() / 1000.0); +#endif +} + +int main() +{ + time_t beg = time_monotonic(); + printf("now: %ld\n", beg); + sleep(2); + printf("+2s: %ld\n", time_monotonic()); + return 0; +} -- 2.25.1