From 827388ffdd0e320eabda14efec2803c43c9fabee Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 16 May 2014 18:19:41 +0200 Subject: [PATCH] outline portable implementation to replace clock_gettime() --- .../wavesapi/miscutils/UMicroseconds.cpp | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libs/backends/wavesaudio/wavesapi/miscutils/UMicroseconds.cpp b/libs/backends/wavesaudio/wavesapi/miscutils/UMicroseconds.cpp index c98aa571da..5e3d2b4da8 100644 --- a/libs/backends/wavesaudio/wavesapi/miscutils/UMicroseconds.cpp +++ b/libs/backends/wavesaudio/wavesapi/miscutils/UMicroseconds.cpp @@ -10,22 +10,30 @@ namespace wvNS { UMicroseconds& UMicroseconds::ReadTime() { + // Note: g_get_monotonic_time() may be a viable alternative + // (it is on Linux and OSX); if not, this code should really go into libpbd #ifdef PLATFORM_WINDOWS LARGE_INTEGER Frequency, Count ; QueryPerformanceFrequency(&Frequency) ; QueryPerformanceCounter(&Count); theTime = uint64_t((Count.QuadPart * 1000000.0 / Frequency.QuadPart)); -#endif -#if defined(__linux__) || defined(__APPLE__) -// Mac code replaced by posix calls, to reduce Carbon dependency. - timeval buf; +#elif defined __MACH__ // OSX, BSD.. - gettimeofday(&buf,NULL); + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + theTime = (uint64_t)mts.tv_sec * 1e6 + (uint64_t)mts.tv_nsec / 1000; + +#else // Linux, POSIX + + struct timespec *ts + clock_gettime(CLOCK_MONOTONIC, ts); + theTime = (uint64_t)ts.tv_sec * 1e6 + (uint64_t)buf.tv_nsec / 1000; - // micro sec - theTime = uint64_t(buf.tv_sec) * 1000*1000 + buf.tv_usec; #endif return *this;