Skip to content

Instantly share code, notes, and snippets.

@PilzAdam
Created December 20, 2013 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PilzAdam/8057716 to your computer and use it in GitHub Desktop.
Save PilzAdam/8057716 to your computer and use it in GitHub Desktop.
diff --git a/src/porting.h b/src/porting.h
index ea7f31b..fadeea4 100644
--- a/src/porting.h
+++ b/src/porting.h
@@ -213,7 +213,17 @@
inline u32 getTimeNs()
{
struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &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
return ts.tv_sec * 1000000000 + ts.tv_nsec;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment