summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/Time.h
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2006-11-09 21:55:34 +0000
committerAlan Conway <aconway@apache.org>2006-11-09 21:55:34 +0000
commitc33f3d8550b9b4455ad6ca8a2327a7bd9d6f7db1 (patch)
treebb5d68281986eb1664c227d15f303664a65d5e03 /cpp/src/qpid/sys/Time.h
parent76fb78a8495b6cd48c633e8b6219b29761133d82 (diff)
downloadqpid-python-c33f3d8550b9b4455ad6ca8a2327a7bd9d6f7db1.tar.gz
Added POSIX equivalents to APR classes used by clients, inlined trivial calls.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@473087 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/Time.h')
-rw-r--r--cpp/src/qpid/sys/Time.h47
1 files changed, 41 insertions, 6 deletions
diff --git a/cpp/src/qpid/sys/Time.h b/cpp/src/qpid/sys/Time.h
index 92e83116a5..6faaf5e367 100644
--- a/cpp/src/qpid/sys/Time.h
+++ b/cpp/src/qpid/sys/Time.h
@@ -21,17 +21,52 @@
#include <stdint.h>
+#ifdef USE_APR
+# include <apr-1/apr_time.h>
+#else
+# include <time.h>
+#endif
+
namespace qpid {
namespace sys {
-inline int64_t msecsToNsecs(int64_t msecs) { return msecs * 1000 *1000; }
-inline int64_t nsecsToMsecs(int64_t nsecs) { return nsecs / (1000 *1000); }
+class Time
+{
+ public:
+ static Time now();
+
+ enum {
+ NSEC_PER_SEC=1000*1000*1000,
+ NSEC_PER_MSEC=1000*1000,
+ NSEC_PER_USEC=1000
+ };
+
+ inline Time(int64_t ticks=0, long nsec_per_tick=1);
+
+ void set(int64_t ticks, long nsec_per_tick=1);
+
+ inline int64_t msecs() const;
+ inline int64_t usecs() const;
+ int64_t nsecs() const;
+
+#ifndef USE_APR
+ const struct timespec& getTimespec() const { return time; }
+ struct timespec& getTimespec() { return time; }
+#endif
+
+ private:
+#ifdef USE_APR
+ apr_time_t time;
+#else
+ struct timespec time;
+#endif
+};
+
+Time::Time(int64_t ticks, long nsec_per_tick) { set(ticks, nsec_per_tick); }
-/** Nanoseconds since epoch */
-int64_t getTimeNsecs();
+int64_t Time::msecs() const { return nsecs() / NSEC_PER_MSEC; }
-/** Milliseconds since epoch */
-int64_t getTimeMsecs();
+int64_t Time::usecs() const { return nsecs() / NSEC_PER_USEC; }
}}