diff options
author | Stephen D. Huston <shuston@apache.org> | 2008-10-29 22:11:46 +0000 |
---|---|---|
committer | Stephen D. Huston <shuston@apache.org> | 2008-10-29 22:11:46 +0000 |
commit | fd0ee666d7d2026b81e3aaa85e15f380c32f109f (patch) | |
tree | ebfe7fcad03d8d43eb14867a99af372518a1a817 /cpp/src/qpid/sys/posix | |
parent | 6d26c9b2c8a19cfd23336d2498bcad561a4458f6 (diff) | |
download | qpid-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')
-rw-r--r-- | cpp/src/qpid/sys/posix/Time.cpp | 34 | ||||
-rwxr-xr-x | cpp/src/qpid/sys/posix/Time.h | 34 |
2 files changed, 65 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); +} + +}} diff --git a/cpp/src/qpid/sys/posix/Time.h b/cpp/src/qpid/sys/posix/Time.h new file mode 100755 index 0000000000..62d734c816 --- /dev/null +++ b/cpp/src/qpid/sys/posix/Time.h @@ -0,0 +1,34 @@ +#ifndef QPID_SYS_POSIX_TIME_H +#define QPID_SYS_POSIX_TIME_H + +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "qpid/sys/IntegerTypes.h" + +namespace qpid { +namespace sys { + +/** + * Class to represent an instant in time. + */ +typedef int64_t TimePrivate; + +}} // namespace qpid::sys + +#endif /*!QPID_SYS_POSIX_TIME_H*/ |