From bedc366948fe5e3b38d7d058cb53c829406e6ea2 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Thu, 15 Nov 2001 01:54:12 +0000 Subject: Changed to a more typesafe definition of ElapsedTime. --- win32/PlatWin.cxx | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'win32') diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index d227aa7a1..7a1ef5f9c 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -877,38 +877,45 @@ static bool initialisedET = false; static bool usePerformanceCounter = false; static LARGE_INTEGER frequency; -static double Now() { - if (usePerformanceCounter) { - LARGE_INTEGER timeVal; - ::QueryPerformanceCounter(&timeVal); - return *(reinterpret_cast(&timeVal)); - } else { - return clock(); - } -} - ElapsedTime::ElapsedTime() { if (!initialisedET) { usePerformanceCounter = ::QueryPerformanceFrequency(&frequency); initialisedET = true; } - beginTime = Now(); + if (usePerformanceCounter) { + LARGE_INTEGER timeVal; + ::QueryPerformanceCounter(&timeVal); + bigBit = timeVal.HighPart; + littleBit = timeVal.LowPart; + } else { + bigBit = clock(); + } } double ElapsedTime::Duration(bool reset) { - double endTime = Now(); double result; + long endBigBit; + long endLittleBit; + if (usePerformanceCounter) { - LARGE_INTEGER lBegin = *(reinterpret_cast(&beginTime)); - LARGE_INTEGER lEnd = *(reinterpret_cast(&endTime)); + LARGE_INTEGER lEnd; + ::QueryPerformanceCounter(&lEnd); + endBigBit = lEnd.HighPart; + endLittleBit = lEnd.LowPart; + LARGE_INTEGER lBegin; + lBegin.HighPart = bigBit; + lBegin.LowPart = littleBit; double elapsed = lEnd.QuadPart - lBegin.QuadPart; result = elapsed / static_cast(frequency.QuadPart); } else { - double elapsed = endTime - beginTime; + endBigBit = clock(); + endLittleBit = 0; + double elapsed = endBigBit - bigBit; result = elapsed / CLOCKS_PER_SEC; } if (reset) { - beginTime = endTime; + bigBit = endBigBit; + littleBit = endLittleBit; } return result; } -- cgit v1.2.3