From 9544a5419bf078136f828e52765092c557b0c716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=B6fferlein?= Date: Sun, 9 Sep 2018 16:51:54 +0200 Subject: [PATCH] Addd current_utc_time() again which got lost during merge --- src/tl/tl/tlTimer.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/tl/tl/tlTimer.cc b/src/tl/tl/tlTimer.cc index 9934a8ace..6c612ee07 100644 --- a/src/tl/tl/tlTimer.cc +++ b/src/tl/tl/tlTimer.cc @@ -47,6 +47,36 @@ namespace tl { +// ------------------------------------------------------------- + +void current_utc_time (struct timespec *ts) +{ + +#if defined(__MACH__) + + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts->tv_sec = mts.tv_sec; + ts->tv_nsec = mts.tv_nsec; + +#elif defined(_MSC_VER) + + FILETIME ft; + GetSystemTimeAsFileTime (&ft); + + uint64_t t = (uint64_t (ft.dwHighDateTime) << (sizeof (ft.dwHighDateTime) * 8)) | uint64_t (ft.dwLowDateTime); + // t is in 100ns units + ts->tv_nsec = (t % 10000000) * 100; + ts->tv_sec = (t / 10000000); + +#else + clock_gettime(CLOCK_REALTIME, ts); +#endif +} + // ------------------------------------------------------------- // Gets the current time in ms from epoch