From: ronag Date: Fri, 2 Sep 2011 18:45:16 +0000 (+0000) Subject: 2.0. timer: Replaced QPC with timeGetTime, QPC might have problems with Turbo Boost... X-Git-Tag: 2.0.1~31 X-Git-Url: https://git.sesse.net/?p=casparcg;a=commitdiff_plain;h=f9c7bf3eee1eefc10e11d8d760d627c70a8d111f 2.0. timer: Replaced QPC with timeGetTime, QPC might have problems with Turbo Boost on newer cpus (e.g Sandy Bridge). git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1326 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- diff --git a/common/utility/timer.h b/common/utility/timer.h index 122d0eaaf..ce3993275 100644 --- a/common/utility/timer.h +++ b/common/utility/timer.h @@ -22,6 +22,7 @@ #define NOMINMAX #include +#include namespace caspar { @@ -29,30 +30,26 @@ class high_prec_timer { public: high_prec_timer() + : time_(0) { - QueryPerformanceFrequency(&freq_); - QueryPerformanceCounter(&time_); } // Author: Ryan M. Geiss // http://www.geisswerks.com/ryan/FAQS/timing.html void tick(double interval) { - LARGE_INTEGER t; - QueryPerformanceCounter(&t); + auto t = ::timeGetTime(); - if (time_.QuadPart != 0) + if (time_ != 0) { - __int64 ticks_to_wait = static_cast(static_cast(freq_.QuadPart) * interval); - __int64 done = 0; + auto ticks_to_wait = static_cast(interval*1000.0); + bool done = 0; do - { - QueryPerformanceCounter(&t); - - __int64 ticks_passed = static_cast<__int64>(t.QuadPart) - static_cast<__int64>(time_.QuadPart); - __int64 ticks_left = ticks_to_wait - ticks_passed; + { + auto ticks_passed = t - time_; + auto ticks_left = ticks_to_wait - ticks_passed; - if (t.QuadPart < time_.QuadPart) // time wrap + if (t < time_) // time wrap done = 1; if (ticks_passed >= ticks_to_wait) done = 1; @@ -65,12 +62,14 @@ public: // otherwise, do a few Sleep(0)'s, which just give up the timeslice, // but don't really save cpu or battery, but do pass a tiny // amount of time. - if (ticks_left > static_cast<__int64>((freq_.QuadPart*2)/1000)) + if (ticks_left > 2) Sleep(1); else for (int i = 0; i < 10; ++i) Sleep(0); // causes thread to give up its timeslice } + + t = ::timeGetTime(); } while (!done); } @@ -78,8 +77,7 @@ public: time_ = t; } private: - LARGE_INTEGER freq_; - LARGE_INTEGER time_; + DWORD time_; };