summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/posix/Time.cpp
diff options
context:
space:
mode:
authorStephen D. Huston <shuston@apache.org>2008-10-29 22:11:46 +0000
committerStephen D. Huston <shuston@apache.org>2008-10-29 22:11:46 +0000
commitfd0ee666d7d2026b81e3aaa85e15f380c32f109f (patch)
treeebfe7fcad03d8d43eb14867a99af372518a1a817 /cpp/src/qpid/sys/posix/Time.cpp
parent6d26c9b2c8a19cfd23336d2498bcad561a4458f6 (diff)
downloadqpid-python-fd0ee666d7d2026b81e3aaa85e15f380c32f109f.tar.gz
Allow AbsTime and Duration to be used cross-platform; add usleep() wrapper. Related to QPID-1209
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@709028 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/posix/Time.cpp')
-rw-r--r--cpp/src/qpid/sys/posix/Time.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/cpp/src/qpid/sys/posix/Time.cpp b/cpp/src/qpid/sys/posix/Time.cpp
index 8aa9fd9946..d8d0a58d2e 100644
--- a/cpp/src/qpid/sys/posix/Time.cpp
+++ b/cpp/src/qpid/sys/posix/Time.cpp
@@ -26,18 +26,39 @@
#include <time.h>
#include <stdio.h>
#include <sys/time.h>
+#include <unistd.h>
+
+namespace {
+int64_t max_abstime() { return std::numeric_limits<int64_t>::max(); }
+}
namespace qpid {
namespace sys {
+AbsTime::AbsTime(const AbsTime& t, const Duration& d) :
+ timepoint(d == Duration::max() ? max_abstime() : t.timepoint+d.nanosecs)
+{}
+
+AbsTime AbsTime::FarFuture() {
+ AbsTime ff; ff.timepoint = max_abstime(); return ff;
+}
+
AbsTime AbsTime::now() {
struct timespec ts;
::clock_gettime(CLOCK_REALTIME, &ts);
AbsTime time_now;
- time_now.time_ns = toTime(ts).nanosecs;
+ time_now.timepoint = toTime(ts).nanosecs;
return time_now;
}
+Duration::Duration(const AbsTime& time0) :
+ nanosecs(time0.timepoint)
+{}
+
+Duration::Duration(const AbsTime& start, const AbsTime& finish) :
+ nanosecs(finish.timepoint - start.timepoint)
+{}
+
struct timespec& toTimespec(struct timespec& ts, const Duration& t) {
ts.tv_sec = t / TIME_SEC;
ts.tv_nsec = t % TIME_SEC;
@@ -63,7 +84,7 @@ std::ostream& operator<<(std::ostream& o, const AbsTime& t) {
"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"
};
struct tm * timeinfo;
- time_t rawtime(t.time_ns/TIME_SEC);
+ time_t rawtime(t.timepoint/TIME_SEC);
timeinfo = localtime (&rawtime);
char time_string[100];
sprintf ( time_string,
@@ -78,5 +99,12 @@ std::ostream& operator<<(std::ostream& o, const AbsTime& t) {
return o << time_string;
}
-}}
+void sleep(int secs) {
+ ::sleep(secs);
+}
+void usleep(uint64_t usecs) {
+ ::usleep(usecs);
+}
+
+}}