1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

Use mach_absolute_time() on OSX without clock_gettime().

This should fix #759 for OSX versions below 10.12.
This commit is contained in:
Martin Ling 2018-09-23 17:43:46 +01:00
parent f40ea9d461
commit 192e77492a
2 changed files with 8 additions and 0 deletions

View File

@ -62,6 +62,7 @@
#include <IOKit/serial/IOSerialKeys.h> #include <IOKit/serial/IOSerialKeys.h>
#include <IOKit/serial/ioss.h> #include <IOKit/serial/ioss.h>
#include <sys/syslimits.h> #include <sys/syslimits.h>
#include <mach/mach_time.h>
#endif #endif
#ifdef __linux__ #ifdef __linux__
#include <dirent.h> #include <dirent.h>

View File

@ -64,6 +64,13 @@ static void get_time(struct timeval *time)
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
time->tv_sec = ts.tv_sec; time->tv_sec = ts.tv_sec;
time->tv_usec = ts.tv_nsec / 1000; time->tv_usec = ts.tv_nsec / 1000;
#elif defined(__APPLE__)
mach_timebase_info_data_t info;
mach_timebase_info(&info);
uint64_t ticks = mach_absolute_time();
uint64_t ns = (ticks * info.numer) / info.denom;
time->tv_sec = ns / 1000000000;
time->tv_usec = (ns % 1000000000) / 1000;
#else #else
gettimeofday(time, NULL); gettimeofday(time, NULL);
#endif #endif