diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2013-08-14 12:39:34 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2013-08-14 12:39:34 -0400 |
commit | 7b34b6a3f6ec6920bf4718a878e3aea7011851ab (patch) | |
tree | 469829dadaeccfdf81ad9a3514d44c4e3d628949 /libs | |
parent | dfac01bdd472217ddbc1a70049c05e8de56ca113 (diff) |
provide clock_gettime() implementation for lovely OSX, which doesn't have it
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/globals.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 89edc66e84..4e99bc767e 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -540,6 +540,31 @@ ARDOUR::get_available_sync_options () /** Return a monotonic value for the number of microseconds that have elapsed * since an arbitrary zero origin. */ + +#ifdef __MACH__ +/* Thanks Apple for not implementing this basic SUSv2, POSIX.1-2001 function + */ +#include <mach/mach_time.h> +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 0 +int +clock_gettime (int /*clk_id*/, struct timespec *t) +{ + static bool initialized = false; + static mach_timebase_info_data_t timebase; + if (!initialized) { + mach_timebase_info(&timebase); + initialized = true; + } + uint64_t time; + time = mach_absolute_time(); + double nseconds = ((double)time * (double)timebase.numer)/((double)timebase.denom); + double seconds = ((double)time * (double)timebase.numer)/((double)timebase.denom * 1e9); + t->tv_sec = seconds; + t->tv_nsec = nseconds; + return 0; +} +#endif microseconds_t ARDOUR::get_microseconds () |