Protect against monotonic time being non-monotonic, take 2.

This is a better fix, suggested by ghazel.
This commit is contained in:
Juliusz Chroboczek 2011-03-30 00:14:41 +00:00
parent 74c0721a2c
commit c0ef0f50ad
1 changed files with 7 additions and 9 deletions

View File

@ -157,17 +157,15 @@ static uint64_t GetMicroseconds()
uint64 UTP_GetMicroseconds()
{
static bool valid = false;
static uint64 last_time;
static uint64 offset = 0, previous = 0;
uint64 now = GetMicroseconds();
if (valid) {
if (last_time > now)
/* Eek! */
now = last_time;
uint64 now = GetMicroseconds() + offset;
if (previous > now) {
/* Eek! */
offset += previous - now;
now = previous;
}
last_time = now;
valid = true;
previous = now;
return now;
}