Fix time calculations

eloop.c and log.c use struct timeval to calculate time-diffs but
incorrectly use "-" instead of "+" as the value is already negative.
They also use unsigned integers so fix both occurences.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-03-23 18:27:29 +01:00
parent 5a865fc39b
commit 83dc28fcc7
2 changed files with 5 additions and 5 deletions

View File

@ -816,7 +816,7 @@ int ev_eloop_run(struct ev_eloop *loop, int timeout)
{
int ret;
struct timeval tv, start;
uint64_t off, msec;
int64_t off, msec;
if (!loop)
return -EINVAL;
@ -835,10 +835,10 @@ int ev_eloop_run(struct ev_eloop *loop, int timeout)
} else if (timeout > 0) {
gettimeofday(&tv, NULL);
off = tv.tv_sec - start.tv_sec;
msec = tv.tv_usec - start.tv_usec;
msec = (int64_t)tv.tv_usec - (int64_t)start.tv_usec;
if (msec < 0) {
off -= 1;
msec = 1000000 - msec;
msec = 1000000 + msec;
}
off *= 1000;
off += msec / 1000;

View File

@ -59,10 +59,10 @@ static void log__time(long long *sec, long long *usec)
} else {
gettimeofday(&t, NULL);
*sec = t.tv_sec - log__ftime.tv_sec;
*usec = t.tv_usec - log__ftime.tv_usec;
*usec = (long long)t.tv_usec - (long long)log__ftime.tv_usec;
if (*usec < 0) {
*sec -= 1;
*usec = 1000000 - *usec;
*usec = 1000000 + *usec;
}
}
}