Changeset 12259


Ignore:
Timestamp:
Mar 29, 2011, 11:15:38 PM (11 years ago)
Author:
jch
Message:

Protect against monotonic time being non-monotonic.

Within utp.cpp, there's a bunch of assertions that will cause us
to crash if monotonic time isn't. While I have no idea about Windows,
under Unix we use real time instead of monotonic time if POSIX clocks
are not available, and real time can be stepped backwards. Since the
protection is cheap, we perform it on all platforms.

File:
1 edited

Legend:

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

    r11919 r12259  
    5555int64 abs64(int64 x) { return x < 0 ? -x : x; }
    5656
    57 uint64 UTP_GetMicroseconds()
     57static uint64 GetMicroseconds()
    5858{
    5959        static bool time_init = false;
     
    9595#include <mach/mach_time.h>
    9696
    97 uint64 UTP_GetMicroseconds()
     97static uint64 GetMicroseconds()
    9898{
    9999        // http://developer.apple.com/mac/library/qa/qa2004/qa1398.html
     
    119119   kernel (think OpenWRT). -- jch */
    120120
    121 uint64 UTP_GetMicroseconds()
     121static uint64_t GetMicroseconds()
    122122{
    123123        static int have_posix_clocks = -1;
     
    156156#endif
    157157
     158uint64 UTP_GetMicroseconds()
     159{
     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;
     171        return now;
     172}
     173
    158174uint32 UTP_GetMilliseconds()
    159175{
Note: See TracChangeset for help on using the changeset viewer.