X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e16458826d99c9c76c93ee46933a22d89a38a388..4a699e3a59b19c21b6faae714b56cac5a75df2e2:/src/common/stopwatch.cpp diff --git a/src/common/stopwatch.cpp b/src/common/stopwatch.cpp index b0e6ddde40..d71d1e9127 100644 --- a/src/common/stopwatch.cpp +++ b/src/common/stopwatch.cpp @@ -33,10 +33,11 @@ #if wxUSE_STOPWATCH #ifndef WX_PRECOMP - #ifdef __WXMSW__ + #ifdef __WINDOWS__ #include "wx/msw/wrapwin.h" #endif #include "wx/log.h" + #include "wx/thread.h" #endif //WX_PRECOMP // ============================================================================ @@ -50,7 +51,7 @@ namespace { -#ifdef __WXMSW__ +#ifdef __WINDOWS__ struct PerfCounter { @@ -64,12 +65,12 @@ struct PerfCounter return freq.QuadPart != 0; } - wxCriticalSection cs; + wxCRIT_SECT_DECLARE_MEMBER(cs); LARGE_INTEGER freq; bool init; } gs_perfCounter; -#endif // __WXMSW__ +#endif // __WINDOWS__ const int MILLISECONDS_PER_SECOND = 1000; const int MICROSECONDS_PER_MILLISECOND = 1000; @@ -79,10 +80,10 @@ const int MICROSECONDS_PER_SECOND = 1000*1000; void wxStopWatch::DoStart() { -#ifdef __WXMSW__ +#ifdef __WINDOWS__ if ( !gs_perfCounter.init ) { - wxCriticalSectionLocker lock(gs_perfCounter.cs); + wxCRIT_SECT_LOCKER(lock, gs_perfCounter.cs); ::QueryPerformanceFrequency(&gs_perfCounter.freq); // Just a sanity check: it's not supposed to happen but verify that @@ -98,26 +99,37 @@ void wxStopWatch::DoStart() gs_perfCounter.init = true; } -#endif // __WXMSW__ +#endif // __WINDOWS__ m_t0 = GetCurrentClockValue(); } wxLongLong wxStopWatch::GetClockFreq() const { -#ifdef __WXMSW__ +#ifdef __WINDOWS__ // Under MSW we use the high resolution performance counter timer which has // its own frequency (usually related to the CPU clock speed). if ( gs_perfCounter.CanBeUsed() ) return gs_perfCounter.freq.QuadPart; -#endif // __WXMSW__ - +#endif // __WINDOWS__ + +#ifdef HAVE_GETTIMEOFDAY + // With gettimeofday() we can have nominally microsecond precision and + // while this is not the case in practice, it's still better than + // millisecond. + return MICROSECONDS_PER_SECOND; +#else // !HAVE_GETTIMEOFDAY // Currently milliseconds are used everywhere else. return MILLISECONDS_PER_SECOND; +#endif // HAVE_GETTIMEOFDAY/!HAVE_GETTIMEOFDAY } void wxStopWatch::Start(long t0) { + // Calling Start() makes the stop watch run however many times it was + // paused before. + m_pauseCount = 0; + DoStart(); m_t0 -= (wxLongLong(t0)*GetClockFreq())/MILLISECONDS_PER_SECOND; @@ -125,16 +137,20 @@ void wxStopWatch::Start(long t0) wxLongLong wxStopWatch::GetCurrentClockValue() const { -#ifdef __WXMSW__ +#ifdef __WINDOWS__ if ( gs_perfCounter.CanBeUsed() ) { LARGE_INTEGER counter; ::QueryPerformanceCounter(&counter); return counter.QuadPart; } -#endif // __WXMSW__ +#endif // __WINDOWS__ +#ifdef HAVE_GETTIMEOFDAY + return wxGetUTCTimeUSec(); +#else // !HAVE_GETTIMEOFDAY return wxGetUTCTimeMillis(); +#endif // HAVE_GETTIMEOFDAY/!HAVE_GETTIMEOFDAY } wxLongLong wxStopWatch::TimeInMicro() const