From 80f0899c16931b41b51b062a3d020781c033bc87 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 6 Nov 2011 17:29:47 +0100 Subject: Small cleanups in utils::Timer * Not nice to pass boolean parameter to constructor for preventing the timer from running on creation. Just call 'start' on it explicitly. * getTimeInMillisec could be made static. Reviewed-by: Yohann Ferreira --- src/utils/timer.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/utils/timer.cpp') diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp index a79a546f..aea10add 100644 --- a/src/utils/timer.cpp +++ b/src/utils/timer.cpp @@ -27,12 +27,25 @@ #include #endif +/** + * Calls gettimeofday() and converts it into milliseconds. + */ +static uint64_t getTimeInMillisec() +{ + uint64_t timeInMillisec; + timeval time; + + gettimeofday(&time, 0); + timeInMillisec = (uint64_t)time.tv_sec * 1000 + time.tv_usec / 1000; + return timeInMillisec; +} + namespace utils { -Timer::Timer(unsigned int ms, bool createActive) +Timer::Timer(unsigned int ms) { - active = createActive; + active = false; interval = ms; lastpulse = getTimeInMillisec(); } @@ -89,14 +102,4 @@ void Timer::changeInterval(unsigned int newinterval) interval = newinterval; } -uint64_t Timer::getTimeInMillisec() -{ - uint64_t timeInMillisec; - timeval time; - - gettimeofday(&time, 0); - timeInMillisec = (uint64_t)time.tv_sec * 1000 + time.tv_usec / 1000; - return timeInMillisec; -} - } // ::utils -- cgit v1.2.3-70-g09d2