Created
June 28, 2017 23:43
-
-
Save jeb2239/dabd71d50536d90b95e646c850b6d080 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 <time.h> | |
#include <sys/time.h> | |
#ifdef __MACH__ | |
#include <mach/clock.h> | |
#include <mach/mach.h> | |
#endif | |
struct timespec ts; | |
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time | |
clock_serv_t cclock; | |
mach_timespec_t mts; | |
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); | |
clock_get_time(cclock, &mts); | |
mach_port_deallocate(mach_task_self(), cclock); | |
ts.tv_sec = mts.tv_sec; | |
ts.tv_nsec = mts.tv_nsec; | |
#else | |
clock_gettime(CLOCK_REALTIME, &ts); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment