Changeset 12260


Ignore:
Timestamp:
Mar 30, 2011, 12:14:41 AM (11 years ago)
Author:
jch
Message:

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

This is a better fix, suggested by ghazel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/third-party/libutp/utp_utils.cpp

    r12259 r12260  
    158158uint64 UTP_GetMicroseconds()
    159159{
    160         static bool valid = false;
    161         static uint64 last_time;
    162 
    163         uint64 now = GetMicroseconds();
    164         if (valid) {
    165                 if (last_time > now)
    166                         /* Eek! */
    167                         now = last_time;
    168         }
    169         last_time = now;
    170         valid = true;
     160        static uint64 offset = 0, previous = 0;
     161
     162        uint64 now = GetMicroseconds() + offset;
     163        if (previous > now) {
     164                /* Eek! */
     165                offset += previous - now;
     166                now = previous;
     167        }
     168        previous = now;
    171169        return now;
    172170}
Note: See TracChangeset for help on using the changeset viewer.