Timer: Switch from gettimeofday() to clock_gettime() to workaround problems on cygwin

This commit is contained in:
jsteube
2017-12-10 14:02:43 +01:00
parent 494c2724f5
commit bbe9b723e1
3 changed files with 20 additions and 4 deletions
+18 -3
View File
@@ -24,14 +24,16 @@ inline double hc_timer_get (hc_timer_t a)
hc_timer_set (&hr_tmp);
return (double) ((double) (hr_tmp.QuadPart - a.QuadPart) / (double) (hr_freq.QuadPart / 1000));
double r = ((double) hr_tmp.QuadPart - (double) a.QuadPart) / ((double) hr_freq.QuadPart / 1000);
return r;
}
#else
inline void hc_timer_set (hc_timer_t* a)
{
gettimeofday (a, NULL);
clock_gettime (CLOCK_MONOTONIC, a);
}
inline double hc_timer_get (hc_timer_t a)
@@ -40,7 +42,20 @@ inline double hc_timer_get (hc_timer_t a)
hc_timer_set (&hr_tmp);
return (double) (((hr_tmp.tv_sec - (a).tv_sec) * 1000) + ((double) (hr_tmp.tv_usec - (a).tv_usec) / 1000));
hc_timer_t s;
s.tv_sec = hr_tmp.tv_sec - a.tv_sec;
s.tv_nsec = hr_tmp.tv_nsec - a.tv_nsec;
if (s.tv_nsec < 0)
{
s.tv_sec -= 1;
s.tv_nsec += 1000000000;
}
double r = ((double) s.tv_sec * 1000) + ((double) s.tv_nsec / 1000000);
return r;
}
#endif