mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-17 12:16:30 +01:00
outline portable implementation to replace clock_gettime()
This commit is contained in:
parent
253fb8f4a6
commit
6eaa121474
1 changed files with 15 additions and 7 deletions
|
|
@ -10,22 +10,30 @@
|
||||||
namespace wvNS {
|
namespace wvNS {
|
||||||
UMicroseconds& UMicroseconds::ReadTime()
|
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
|
#ifdef PLATFORM_WINDOWS
|
||||||
LARGE_INTEGER Frequency, Count ;
|
LARGE_INTEGER Frequency, Count ;
|
||||||
|
|
||||||
QueryPerformanceFrequency(&Frequency) ;
|
QueryPerformanceFrequency(&Frequency) ;
|
||||||
QueryPerformanceCounter(&Count);
|
QueryPerformanceCounter(&Count);
|
||||||
theTime = uint64_t((Count.QuadPart * 1000000.0 / Frequency.QuadPart));
|
theTime = uint64_t((Count.QuadPart * 1000000.0 / Frequency.QuadPart));
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__APPLE__)
|
#elif defined __MACH__ // OSX, BSD..
|
||||||
// Mac code replaced by posix calls, to reduce Carbon dependency.
|
|
||||||
timeval buf;
|
|
||||||
|
|
||||||
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
|
#endif
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue