diff options
author | Robin Gareus <robin@gareus.org> | 2014-05-16 18:19:41 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2014-05-16 18:19:41 +0200 |
commit | 827388ffdd0e320eabda14efec2803c43c9fabee (patch) | |
tree | e07cb0832d7ed0374ab593414ff2538c2a39d2cf /libs | |
parent | 4ece16be8ea0b9862d05886eaecdf4108b345c53 (diff) |
outline portable implementation to replace clock_gettime()
Diffstat (limited to 'libs')
-rw-r--r-- | libs/backends/wavesaudio/wavesapi/miscutils/UMicroseconds.cpp | 22 |
1 files 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.. + + 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 - gettimeofday(&buf,NULL); + 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; |