summaryrefslogtreecommitdiffhomepage
path: root/opentrack-compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-10-11 06:54:30 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-10-11 06:54:30 +0200
commitf60c53b27e1afab06786161b84d13154564d996a (patch)
treec6e1ea48d270b45288790b48dfdd18a68d3324a1 /opentrack-compat
parent8343e1895e8dd692ba861eed9330e2413dfe893f (diff)
timer: fix overflow
Issue: #253
Diffstat (limited to 'opentrack-compat')
-rw-r--r--opentrack-compat/timer.hpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/opentrack-compat/timer.hpp b/opentrack-compat/timer.hpp
index fd710499..8192aa83 100644
--- a/opentrack-compat/timer.hpp
+++ b/opentrack-compat/timer.hpp
@@ -24,11 +24,12 @@ static inline void opentrack_clock_gettime(int, struct timespec* ts)
(void) QueryPerformanceCounter(&d);
- d.QuadPart *= 1000000000L;
- d.QuadPart /= freq.QuadPart;
+ long long part = d.QuadPart;
+ part *= 1000000000ULL;
+ part /= freq.QuadPart;
- ts->tv_sec = d.QuadPart / 1000000000L;
- ts->tv_nsec = d.QuadPart % 1000000000L;
+ ts->tv_sec = part / 1000000000ULL;
+ ts->tv_nsec = part % 1000000000ULL;
}
# define clock_gettime opentrack_clock_gettime
#else
@@ -53,9 +54,9 @@ static inline void clock_gettime(int, struct timespec* ts)
class Timer {
private:
struct timespec state;
- long conv(const struct timespec& cur)
+ long long conv(const struct timespec& cur)
{
- return (cur.tv_sec - state.tv_sec) * 1000000000L + (cur.tv_nsec - state.tv_nsec);
+ return (cur.tv_sec - state.tv_sec) * 1000000000LL + (cur.tv_nsec - state.tv_nsec);
}
public:
Timer() {
@@ -64,7 +65,7 @@ public:
void start() {
(void) clock_gettime(CLOCK_MONOTONIC, &state);
}
- long elapsed() {
+ long long elapsed() {
struct timespec cur;
(void) clock_gettime(CLOCK_MONOTONIC, &cur);
return conv(cur);