summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/Time.h
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2007-05-22 15:18:08 +0000
committerAndrew Stitcher <astitcher@apache.org>2007-05-22 15:18:08 +0000
commitf646350b5e59ccf49f1253bd55f98d062769f2ee (patch)
treeba8143aa842ced96eaa450cc236a96abdd8b9c05 /cpp/src/qpid/sys/Time.h
parentb8f00ac2a358a02d0cdae2dc098f2bacb2af44d5 (diff)
downloadqpid-python-f646350b5e59ccf49f1253bd55f98d062769f2ee.tar.gz
* Split apart platform (threading etc.) from network io
you can now use a posix platform implementation by configuring --disable-apr-platform * Changed Time classes to distinguish between absolute times (AbsTime) and durations (Duration). This should avoid bugs caused by confusing the two types of time. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@540608 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/Time.h')
-rw-r--r--cpp/src/qpid/sys/Time.h78
1 files changed, 59 insertions, 19 deletions
diff --git a/cpp/src/qpid/sys/Time.h b/cpp/src/qpid/sys/Time.h
index 47609d51df..314f4b5bbb 100644
--- a/cpp/src/qpid/sys/Time.h
+++ b/cpp/src/qpid/sys/Time.h
@@ -23,36 +23,76 @@
*/
#include <stdint.h>
-
-#ifdef USE_APR
-#include <apr_time.h>
-#else
-#include <time.h>
-#endif
+#include <limits>
namespace qpid {
namespace sys {
-/** Time in nanoseconds */
-typedef int64_t Time;
+class Duration;
+
+/** Times in nanoseconds */
+class AbsTime {
+ int64_t time_ns;
+
+ friend class Duration;
+
+public:
+ inline AbsTime() {}
+ inline AbsTime(const AbsTime& time0, const Duration& duration);
+ // Default asignment operation fine
+ // Default copy constructor fine
+
+ static AbsTime now();
+ inline static AbsTime FarFuture();
+};
+
+class Duration {
+ int64_t nanosecs;
+
+ friend class AbsTime;
+
+public:
+ inline Duration(int64_t time0);
+ inline explicit Duration(const AbsTime& time0);
+ inline explicit Duration(const AbsTime& start, const AbsTime& finish);
+ inline operator int64_t() const;
+};
+
-Time now();
+AbsTime::AbsTime(const AbsTime& time0, const Duration& duration0) :
+ time_ns(time0.time_ns+duration0.nanosecs)
+{}
+
+AbsTime AbsTime::FarFuture() { AbsTime ff; ff.time_ns = std::numeric_limits<int64_t>::max(); return ff;}
+
+inline AbsTime now() { return AbsTime::now(); }
+
+Duration::Duration(int64_t time0) :
+ nanosecs(time0)
+{}
+
+Duration::Duration(const AbsTime& time0) :
+ nanosecs(time0.time_ns)
+{}
+
+Duration::Duration(const AbsTime& start, const AbsTime& finish) :
+ nanosecs(finish.time_ns - start.time_ns)
+{}
+
+Duration::operator int64_t() const
+{ return nanosecs; }
/** Nanoseconds per second. */
-const Time TIME_SEC = 1000*1000*1000;
+const Duration TIME_SEC = 1000*1000*1000;
/** Nanoseconds per millisecond */
-const Time TIME_MSEC = 1000*1000;
+const Duration TIME_MSEC = 1000*1000;
/** Nanoseconds per microseconds. */
-const Time TIME_USEC = 1000;
+const Duration TIME_USEC = 1000;
/** Nanoseconds per nanosecond. */
-const Time TIME_NSEC = 1;
-
-#ifndef USE_APR
-struct timespec toTimespec(const Time& t);
-struct timespec& toTimespec(struct timespec& ts, const Time& t);
-Time toTime(const struct timespec& ts);
-#endif
+const Duration TIME_NSEC = 1;
+/** Time greater than any other time */
+const AbsTime FAR_FUTURE = AbsTime::FarFuture();
}}
#endif /*!_sys_Time_h*/