From 3d6ab158aec3569a13fb790d100f1ce3286772ca Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 11 Jun 2014 20:29:40 +0200 Subject: Fix OSX high resolution timers --- facetracknoir/timer.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/facetracknoir/timer.hpp b/facetracknoir/timer.hpp index 306bcaa7..d8c15181 100644 --- a/facetracknoir/timer.hpp +++ b/facetracknoir/timer.hpp @@ -28,17 +28,18 @@ static inline void clock_gettime(int, struct timespec* ts) # include static inline void clock_gettime(int, struct timespec* ts) { - uint64_t state, nsec; static mach_timebase_info_data_t sTimebaseInfo; + uint64_t state, nsec; if ( sTimebaseInfo.denom == 0 ) { (void) mach_timebase_info(&sTimebaseInfo); } state = mach_absolute_time(); - nsec = elapsed * sTimebaseInfo.numer / sTimebaseInfo.denom; - ts->tv_sec = nsec / 1000000; - ts->tv_nsec = nsec % 1000000; + nsec = state * sTimebaseInfo.numer / sTimebaseInfo.denom; + ts->tv_sec = nsec / 1000000000L; + ts->tv_nsec = nsec % 1000000000L; } -# else +# endif +#endif class Timer { private: struct timespec state; @@ -63,5 +64,3 @@ public: return conv(cur); } }; -# endif -#endif -- cgit v1.2.3