From ed188fd21c4c27447115f2a49269e41bd6f0337b Mon Sep 17 00:00:00 2001 From: hodasemi Date: Sat, 5 Jan 2019 12:45:02 +0100 Subject: [PATCH] Fix timer --- exercise2/include/timer.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/exercise2/include/timer.h b/exercise2/include/timer.h index a4e32f6..60499b7 100644 --- a/exercise2/include/timer.h +++ b/exercise2/include/timer.h @@ -7,16 +7,17 @@ typedef std::chrono::duration milliseconds_type; -class Counter { -private: +class Counter +{ + private: int max; int n; - std::chrono::_V2::system_clock::time_point last_time; + std::chrono::system_clock::time_point last_time; milliseconds_type update_interval; -public: + public: Counter(int max, float interval) - : max(max), update_interval((int)(interval * 1000.0f)) + : max(max), update_interval((int)(interval * 1000.0f)) { last_time = std::chrono::high_resolution_clock::now(); n = 0; @@ -24,16 +25,19 @@ public: ~Counter() {} - int get_counter() { + int get_counter() + { auto new_time = std::chrono::high_resolution_clock::now(); milliseconds_type time_difference = std::chrono::duration_cast(new_time - last_time); - if (time_difference.count() >= update_interval.count()) { + if (time_difference.count() >= update_interval.count()) + { last_time += update_interval; n++; - if (n >= max) { + if (n >= max) + { n = n - max; abort(); }