summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir/timer.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-06-11 20:29:40 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-06-11 20:29:40 +0200
commit3d6ab158aec3569a13fb790d100f1ce3286772ca (patch)
tree82f0a42f575f08c020bac387e543a93565a45847 /facetracknoir/timer.hpp
parent64dea656becd8c914a3c8dc3f3b4f0d71bd3f2d0 (diff)
Fix OSX high resolution timers
Diffstat (limited to 'facetracknoir/timer.hpp')
-rw-r--r--facetracknoir/timer.hpp13
1 files 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 <mach/mach_time.h>
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