X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Futility%2Ftimer.h;h=122d0eaaf7033d6868ab64bd8939484ad759c943;hb=3b48b20b7b77beab3ae36e973e3390dafa4e3e86;hp=6d5a15dcaa55acbf6a4248ae52ad8ba8d356835e;hpb=4b01d1446c9eaa79557dab0def60cdbedabe6217;p=casparcg diff --git a/common/utility/timer.h b/common/utility/timer.h index 6d5a15dca..122d0eaaf 100644 --- a/common/utility/timer.h +++ b/common/utility/timer.h @@ -1,31 +1,39 @@ +/* +* copyright (c) 2010 Sveriges Television AB +* +* This file is part of CasparCG. +* +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* CasparCG is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with CasparCG. If not, see . +* +*/ #pragma once +#define NOMINMAX + #include namespace caspar { -class timer +class high_prec_timer { public: - timer() + high_prec_timer() { QueryPerformanceFrequency(&freq_); QueryPerformanceCounter(&time_); } - double elapsed() - { - LARGE_INTEGER t; - QueryPerformanceCounter(&t); - int ticks_passed = static_cast(static_cast<__int64>(t.QuadPart) - static_cast<__int64>(time_.QuadPart)); - return static_cast(ticks_passed)/static_cast(freq_.QuadPart); - } - - void reset() - { - QueryPerformanceCounter(&time_); - } - // Author: Ryan M. Geiss // http://www.geisswerks.com/ryan/FAQS/timing.html void tick(double interval) @@ -35,14 +43,14 @@ public: if (time_.QuadPart != 0) { - int ticks_to_wait = static_cast(static_cast(freq_.QuadPart) * interval); - int done = 0; + __int64 ticks_to_wait = static_cast(static_cast(freq_.QuadPart) * interval); + __int64 done = 0; do { QueryPerformanceCounter(&t); - int ticks_passed = static_cast(static_cast<__int64>(t.QuadPart) - static_cast<__int64>(time_.QuadPart)); - int ticks_left = ticks_to_wait - ticks_passed; + __int64 ticks_passed = static_cast<__int64>(t.QuadPart) - static_cast<__int64>(time_.QuadPart); + __int64 ticks_left = ticks_to_wait - ticks_passed; if (t.QuadPart < time_.QuadPart) // time wrap done = 1; @@ -57,7 +65,7 @@ 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((freq_.QuadPart*2)/1000)) + if (ticks_left > static_cast<__int64>((freq_.QuadPart*2)/1000)) Sleep(1); else for (int i = 0; i < 10; ++i) @@ -74,4 +82,5 @@ private: LARGE_INTEGER time_; }; + } \ No newline at end of file