From 7d2ec8a64dfb7c96cd00f62bd30bdbade959232d Mon Sep 17 00:00:00 2001 From: ronag Date: Mon, 5 Sep 2011 14:33:42 +0000 Subject: [PATCH] git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1348 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- common/utility/timer.h | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) 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_; }; -- 2.39.2