Add timer_cmp() utility function to compare two timevals.

This is preferable to using time_diff() to compare two timevals, because
time_diff() gives its result as a 'double' which only has 53 bits of
precision.

Also switch a couple of places from using time_diff() to using
this function.
This commit is contained in:
Kevin Easton
2015-05-21 01:21:02 +10:00
parent b944573a5e
commit b14d0ddcb9
3 changed files with 12 additions and 2 deletions

View File

@@ -1764,6 +1764,15 @@ double time_until(const struct timeval *tv_to)
return BX_time_diff(tv_now, *tv_to);
}
/* Compare two timevals - returns 1, 0 or -1 if a is >, = or < b */
int time_cmp(const struct timeval *a, const struct timeval *b)
{
if (a->tv_sec == b->tv_sec)
return (a->tv_usec > b->tv_usec) - (a->tv_usec < b->tv_usec);
else
return (a->tv_sec > b->tv_sec) - (a->tv_sec < b->tv_sec);
}
int BX_time_to_next_minute (void)
{
time_t now = time(NULL);