Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/Makefile.am4
-rw-r--r--src/sys/timer.cc46
-rw-r--r--src/sys/timer.h50
3 files changed, 98 insertions, 2 deletions
diff --git a/src/sys/Makefile.am b/src/sys/Makefile.am
index be1c636..ff1fbe0 100644
--- a/src/sys/Makefile.am
+++ b/src/sys/Makefile.am
@@ -2,5 +2,5 @@ INCLUDES = -I$(top_srcdir)/src
METASOURCES = AUTO
libsys_la_LDFLAGS = -avoid-version -no-undefined
noinst_LTLIBRARIES = libsys.la
-libsys_la_SOURCES = consoleinterface.cc sys.cc
-noinst_HEADERS = consoleinterface.h sys.h
+libsys_la_SOURCES = consoleinterface.cc sys.cc timer.cc
+noinst_HEADERS = consoleinterface.h sys.h timer.h
diff --git a/src/sys/timer.cc b/src/sys/timer.cc
new file mode 100644
index 0000000..c46ece2
--- /dev/null
+++ b/src/sys/timer.cc
@@ -0,0 +1,46 @@
+/*
+ sys/timer.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "sys/timer.h"
+
+#include <sys/time.h>
+
+#include <unistd.h>
+#include <iostream>
+
+namespace sys
+{
+
+Timer::Timer()
+{
+ reset();
+}
+
+Timer::~Timer()
+{
+}
+
+void Timer::reset()
+{
+ struct timeval tick;
+ struct timezone tick_tz;
+
+ gettimeofday(&tick, &tick_tz);
+ timer_start = tick.tv_sec * 1000 + tick.tv_usec / 1000;
+}
+
+unsigned long Timer::timestamp() const
+{
+ struct timeval tick;
+ struct timezone tick_tz;
+
+ gettimeofday(&tick, &tick_tz);
+ unsigned long delta = (tick.tv_sec * 1000 + tick.tv_usec / 1000) - timer_start;
+
+ return delta;
+}
+
+}
diff --git a/src/sys/timer.h b/src/sys/timer.h
new file mode 100644
index 0000000..125363d
--- /dev/null
+++ b/src/sys/timer.h
@@ -0,0 +1,50 @@
+/*
+ sys/timer.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_SYS_TIMER_H__
+#define __INCLUDED_SYS_TIMER_H__
+
+namespace sys
+{
+
+/// a timer measures intervals in seconds
+/*! A timer class measures the time elapsed
+* between the last two calls to its mark() function.
+*/
+class Timer
+{
+public:
+ /**
+ * @brief constructor
+ * The constructor autmaticly calls reset()
+ * */
+ Timer();
+
+ /**
+ * @brief destructor
+ * */
+ ~Timer();
+
+ /**
+ * @brief reset the timer to 0
+ */
+ void reset();
+
+ /**
+ * @brief return the time elapsed since the last reset() call, in milliseconds
+ *
+ * */
+ unsigned long timestamp() const;
+
+private:
+ unsigned long timer_start;
+
+}; // class Timer
+
+} // namespace sys
+
+#endif // __INCLUDED_SYS_TIMER_H__
+