Changed: Simplify some things

This commit is contained in:
kaetemi 2012-07-27 22:33:07 +02:00
parent 8560e1c146
commit 986148af4e
2 changed files with 5 additions and 17 deletions

View file

@ -84,7 +84,7 @@ public:
* the value can jump backwards if the system time is changed by a user or a NTP time sync process. * the value can jump backwards if the system time is changed by a user or a NTP time sync process.
* The value is different on 2 different computers; use the CUniTime class to get a universal * The value is different on 2 different computers; use the CUniTime class to get a universal
* time that is the same on all computers. * time that is the same on all computers.
* \warning On Win32, the value is on 32 bits only. It wraps around to 0 every about 49.71 days. * \warning On Win32, the value is on 32 bits only, and uses the low-res timer. It wraps around to 0 every about 49.71 days.
*/ */
static TTime getLocalTime(); static TTime getLocalTime();

View file

@ -40,6 +40,7 @@ namespace NLMISC
namespace { namespace {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
bool a_HaveQueryPerformance = false; bool a_HaveQueryPerformance = false;
LARGE_INTEGER a_QueryPerformanceFrequency;
#endif #endif
} }
@ -72,6 +73,7 @@ void CTime::probeTimerInfo(CTime::CTimerInfo &result)
result.HighPrecisionResolution = 1000; result.HighPrecisionResolution = 1000;
} }
a_HaveQueryPerformance = result.IsHighPrecisionAvailable; a_HaveQueryPerformance = result.IsHighPrecisionAvailable;
a_QueryPerformanceFrequency.QuadPart = winPerfFreq.QuadPart;
if (!result.IsHighPrecisionAvailable) if (!result.IsHighPrecisionAvailable)
{ {
lowResTime = timeGetTime(); lowResTime = timeGetTime();
@ -299,20 +301,6 @@ TTime CTime::getLocalTime ()
#endif #endif
} }
#ifdef NL_OS_WINDOWS
namespace {
struct CQPFProvider
{
CQPFProvider()
{
QueryPerformanceFrequency(&Frequency);
}
LARGE_INTEGER Frequency;
};
CQPFProvider s_QPFProvider;
}
#endif
/// Same as above but prefer high resolution timer /// Same as above but prefer high resolution timer
TTime CTime::getLocalTimeHR() TTime CTime::getLocalTimeHR()
{ {
@ -323,8 +311,8 @@ TTime CTime::getLocalTimeHR()
// If my calculations are right. // If my calculations are right.
LARGE_INTEGER counter; LARGE_INTEGER counter;
QueryPerformanceCounter(&counter); QueryPerformanceCounter(&counter);
counter.QuadPart *= 1000; counter.QuadPart *= (LONGLONG)1000L;
counter.QuadPart /= s_QPFProvider.Frequency.QuadPart; counter.QuadPart /= a_QueryPerformanceFrequency.QuadPart;
} }
else else
{ {