fix timing errors in thread wait functions on unix. patch by makovick fixes bug #1154212

This commit is contained in:
Ted Percival
2005-03-24 19:46:50 +00:00
parent 382db74f8f
commit e1ab8c5b77
3 changed files with 28 additions and 19 deletions
+23 -17
View File
@@ -17,6 +17,9 @@
#endif
int64_t ArchHooks_Unix::iStartTime = 0;
bool ArchHooks_Unix::bTimerInitialized = false;
static bool IsFatalSignal( int signal )
{
switch( signal )
@@ -95,6 +98,26 @@ static void TestTLS()
}
#endif
static int64_t GetMicrosecondsSinceEpoch()
{
struct timeval tv;
gettimeofday( &tv, NULL );
return int64_t(tv.tv_sec) * 1000000 + int64_t(tv.tv_usec);
}
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{
if (!ArchHooks_Unix::bTimerInitialized) {
ArchHooks_Unix::bTimerInitialized = true;
ArchHooks_Unix::iStartTime = GetMicrosecondsSinceEpoch();
}
int64_t ret = GetMicrosecondsSinceEpoch() - ArchHooks_Unix::iStartTime;
if( bAccurate )
ret = FixupTimeIfBackwards( ret );
return ret;
}
ArchHooks_Unix::ArchHooks_Unix()
{
/* First, handle non-fatal termination signals. */
@@ -166,23 +189,6 @@ void ArchHooks_Unix::SetTime( tm newtime )
system( "hwclock --systohc" );
}
static int64_t GetMicrosecondsSinceEpoch()
{
struct timeval tv;
gettimeofday( &tv, NULL );
return int64_t(tv.tv_sec) * 1000000 + int64_t(tv.tv_usec);
}
int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate )
{
static int64_t iStartTime = GetMicrosecondsSinceEpoch();
int64_t ret = GetMicrosecondsSinceEpoch() - iStartTime;
if( bAccurate )
ret = FixupTimeIfBackwards( ret );
return ret;
}
/*
* (c) 2003-2004 Glenn Maynard
* All rights reserved.