Last active
March 23, 2016 09:41
-
-
Save perj/f2db2a90fc831ab5e7f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <mach/mach.h> | |
#include <mach/mach_time.h> | |
#include <sys/time.h> | |
#include <time.h> | |
static mach_timebase_info_data_t timebase_info; | |
int | |
clock_gettime_monotonic(struct timespec *tp) { | |
uint64_t mticks = mach_absolute_time(); | |
if (timebase_info.denom == 0) | |
mach_timebase_info(&timebase_info); | |
uint64_t nsecs = mticks * timebase_info.numer / timebase_info.denom; | |
tp->tv_sec = nsecs / 1000000000; | |
tp->tv_nsec = nsecs % 1000000000; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment