aboutsummaryrefslogtreecommitdiffstats
path: root/src/timer
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-29 00:03:19 +0000
committerlloyd <[email protected]>2008-09-29 00:03:19 +0000
commit8269e2897e0a652bbd949d38b74873976a98adeb (patch)
tree2ea103d5d7d4cf9073b4ac06cb5d5f7c62be16a6 /src/timer
parentab81a9d95264914ab34cb4e7134f827e3128c326 (diff)
Move timer base class into a module, add dep from other timer modules
Diffstat (limited to 'src/timer')
-rw-r--r--src/timer/cpu_counter/modinfo.txt5
-rw-r--r--src/timer/gettimeofday/modinfo.txt5
-rw-r--r--src/timer/posix_rt/modinfo.txt5
-rw-r--r--src/timer/timer_base/modinfo.txt10
-rw-r--r--src/timer/timer_base/timers.cpp52
-rw-r--r--src/timer/timer_base/timers.h29
-rw-r--r--src/timer/win32_query_perf_ctr/modinfo.txt5
7 files changed, 111 insertions, 0 deletions
diff --git a/src/timer/cpu_counter/modinfo.txt b/src/timer/cpu_counter/modinfo.txt
index d5583c0d7..2a64bedee 100644
--- a/src/timer/cpu_counter/modinfo.txt
+++ b/src/timer/cpu_counter/modinfo.txt
@@ -29,3 +29,8 @@ ia64 # ar.itc
s390x
hppa
</arch>
+
+<requires>
+timer_base
+</requires>
+
diff --git a/src/timer/gettimeofday/modinfo.txt b/src/timer/gettimeofday/modinfo.txt
index 495914589..c079dfd58 100644
--- a/src/timer/gettimeofday/modinfo.txt
+++ b/src/timer/gettimeofday/modinfo.txt
@@ -25,3 +25,8 @@ qnx
solaris
tru64
</os>
+
+<requires>
+timer_base
+</requires>
+
diff --git a/src/timer/posix_rt/modinfo.txt b/src/timer/posix_rt/modinfo.txt
index e9298a81c..fb1870988 100644
--- a/src/timer/posix_rt/modinfo.txt
+++ b/src/timer/posix_rt/modinfo.txt
@@ -21,3 +21,8 @@ linux
#netbsd
#openbsd
</os>
+
+<requires>
+timer_base
+</requires>
+
diff --git a/src/timer/timer_base/modinfo.txt b/src/timer/timer_base/modinfo.txt
new file mode 100644
index 000000000..3637d4c94
--- /dev/null
+++ b/src/timer/timer_base/modinfo.txt
@@ -0,0 +1,10 @@
+realname "Timer Base Class"
+
+define TIMER
+
+load_on auto
+
+<add>
+timers.cpp
+timers.h
+</add>
diff --git a/src/timer/timer_base/timers.cpp b/src/timer/timer_base/timers.cpp
new file mode 100644
index 000000000..4f482916f
--- /dev/null
+++ b/src/timer/timer_base/timers.cpp
@@ -0,0 +1,52 @@
+/*************************************************
+* Timestamp Functions Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/timers.h>
+#include <botan/loadstor.h>
+#include <botan/util.h>
+#include <ctime>
+
+namespace Botan {
+
+/*************************************************
+* Get the system clock *
+*************************************************/
+u64bit system_time()
+ {
+ return static_cast<u64bit>(std::time(0));
+ }
+
+/*************************************************
+* Default Timer clock reading *
+*************************************************/
+u64bit Timer::clock() const
+ {
+ return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
+ }
+
+/*************************************************
+* Read the clock and return the output *
+*************************************************/
+u32bit Timer::slow_poll(byte out[], u32bit length)
+ {
+ const u64bit clock_value = this->clock();
+
+ for(u32bit j = 0; j != sizeof(clock_value); ++j)
+ out[j % length] ^= get_byte(j, clock_value);
+
+ return (length < 8) ? length : 8;
+ }
+
+/*************************************************
+* Combine a two time values into a single one *
+*************************************************/
+u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
+ {
+ static const u64bit NANOSECONDS_UNITS = 1000000000;
+ parts *= (NANOSECONDS_UNITS / parts_hz);
+ return ((seconds * NANOSECONDS_UNITS) + parts);
+ }
+
+}
diff --git a/src/timer/timer_base/timers.h b/src/timer/timer_base/timers.h
new file mode 100644
index 000000000..253f71f6b
--- /dev/null
+++ b/src/timer/timer_base/timers.h
@@ -0,0 +1,29 @@
+/*************************************************
+* Timestamp Functions Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_TIMERS_H__
+#define BOTAN_TIMERS_H__
+
+#include <botan/rng.h>
+
+namespace Botan {
+
+/*************************************************
+* Timer Interface *
+*************************************************/
+class BOTAN_DLL Timer : public EntropySource
+ {
+ public:
+ virtual u64bit clock() const;
+ u32bit slow_poll(byte[], u32bit);
+
+ virtual ~Timer() {}
+ protected:
+ static u64bit combine_timers(u32bit, u32bit, u32bit);
+ };
+
+}
+
+#endif
diff --git a/src/timer/win32_query_perf_ctr/modinfo.txt b/src/timer/win32_query_perf_ctr/modinfo.txt
index 74c4a59ea..e956f99c5 100644
--- a/src/timer/win32_query_perf_ctr/modinfo.txt
+++ b/src/timer/win32_query_perf_ctr/modinfo.txt
@@ -18,3 +18,8 @@ windows
<libs>
windows -> user32
</libs>
+
+<requires>
+timer_base
+</requires>
+