Fix ArchHooks::FixupTimeIfBackwards when the time becomes negative

in Linux.  This can happen if the clock is turned back when using
the system clock; the time will be less than ArchHooks_Unix::m_iStartTime.
This commit is contained in:
Glenn Maynard
2005-12-08 21:48:57 +00:00
parent f02b8e3a3d
commit afbd2f3bbc
2 changed files with 11 additions and 11 deletions
+9 -9
View File
@@ -33,15 +33,15 @@ ArchHooks *MakeArchHooks()
* bAccurate == false.
*/
uint64_t ArchHooks::FixupTimeIfLooped( uint64_t usecs )
int64_t ArchHooks::FixupTimeIfLooped( int64_t usecs )
{
static uint64_t last = 0;
static uint64_t offset_us = 0;
static int64_t last = 0;
static int64_t offset_us = 0;
/* The time has wrapped if the last time was very high and the current time is very low. */
const uint64_t i32BitMaxMs = uint64_t(1) << 32;
const uint64_t i32BitMaxUs = i32BitMaxMs*1000;
const uint64_t one_day = uint64_t(24*60*60)*1000000;
const int64_t i32BitMaxMs = uint64_t(1) << 32;
const int64_t i32BitMaxUs = i32BitMaxMs*1000;
const int64_t one_day = uint64_t(24*60*60)*1000000;
if( last > (i32BitMaxUs-one_day) && usecs < one_day )
offset_us += i32BitMaxUs;
@@ -50,10 +50,10 @@ uint64_t ArchHooks::FixupTimeIfLooped( uint64_t usecs )
return usecs + offset_us;
}
uint64_t ArchHooks::FixupTimeIfBackwards( uint64_t usecs )
int64_t ArchHooks::FixupTimeIfBackwards( int64_t usecs )
{
static uint64_t last = 0;
static uint64_t offset_us = 0;
static int64_t last = 0;
static int64_t offset_us = 0;
if( usecs < last )
{
+2 -2
View File
@@ -78,8 +78,8 @@ public:
private:
/* This are helpers for GetMicrosecondsSinceStart on systems with a timer
* that may loop or move backwards. */
static uint64_t FixupTimeIfLooped( uint64_t usecs );
static uint64_t FixupTimeIfBackwards( uint64_t usecs );
static int64_t FixupTimeIfLooped( int64_t usecs );
static int64_t FixupTimeIfBackwards( int64_t usecs );
};
#endif