summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-11-06 17:29:47 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-11-07 18:54:37 +0100
commit80f0899c16931b41b51b062a3d020781c033bc87 (patch)
treec761bc1539c03a75a2aea7cf5a08701f4c13803e /src/utils
parente0fc91bd6a2830127b116f6a37f024e17ac594e7 (diff)
downloadmanaserv-80f0899c16931b41b51b062a3d020781c033bc87.tar.gz
manaserv-80f0899c16931b41b51b062a3d020781c033bc87.tar.xz
manaserv-80f0899c16931b41b51b062a3d020781c033bc87.zip
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
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/timer.cpp27
-rw-r--r--src/utils/timer.h10
2 files changed, 17 insertions, 20 deletions
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp
index a79a546..aea10ad 100644
--- a/src/utils/timer.cpp
+++ b/src/utils/timer.cpp
@@ -27,12 +27,25 @@
#include <windows.h>
#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
diff --git a/src/utils/timer.h b/src/utils/timer.h
index 87c94a2..2c6ca89 100644
--- a/src/utils/timer.h
+++ b/src/utils/timer.h
@@ -41,9 +41,8 @@ class Timer
* Constructor.
*
* @param ms the interval in milliseconds
- * @param createActive whether the timer should be implicitly started
*/
- Timer(unsigned int ms, bool createActive = true);
+ Timer(unsigned int ms);
/**
* Returns the number of elapsed ticks since last call.
@@ -68,15 +67,10 @@ class Timer
/**
* Changes the interval between two pulses.
*/
- void changeInterval (unsigned int newinterval);
+ void changeInterval(unsigned int newinterval);
private:
/**
- * Calls gettimeofday() and converts it into milliseconds.
- */
- uint64_t getTimeInMillisec();
-
- /**
* Interval between two pulses.
*/
unsigned int interval;