diff options
Diffstat (limited to 'opentrack-compat/timer.hpp')
-rw-r--r-- | opentrack-compat/timer.hpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/opentrack-compat/timer.hpp b/opentrack-compat/timer.hpp index 8192aa83..f0741295 100644 --- a/opentrack-compat/timer.hpp +++ b/opentrack-compat/timer.hpp @@ -24,9 +24,7 @@ static inline void opentrack_clock_gettime(int, struct timespec* ts) (void) QueryPerformanceCounter(&d); - long long part = d.QuadPart; - part *= 1000000000ULL; - part /= freq.QuadPart; + long long part = d.QuadPart / ((long double)freq.QuadPart) * 1000000000.L; ts->tv_sec = part / 1000000000ULL; ts->tv_nsec = part % 1000000000ULL; @@ -54,7 +52,7 @@ static inline void clock_gettime(int, struct timespec* ts) class Timer { private: struct timespec state; - long long conv(const struct timespec& cur) + long long conv(const struct timespec& cur) const { return (cur.tv_sec - state.tv_sec) * 1000000000LL + (cur.tv_nsec - state.tv_nsec); } @@ -65,12 +63,12 @@ public: void start() { (void) clock_gettime(CLOCK_MONOTONIC, &state); } - long long elapsed() { + long long elapsed() const { struct timespec cur; (void) clock_gettime(CLOCK_MONOTONIC, &cur); return conv(cur); } - long elapsed_ms() { + long elapsed_ms() const { return elapsed() / 1000000L; } }; |