summaryrefslogtreecommitdiff
path: root/omnithread
diff options
context:
space:
mode:
authoreb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>2008-06-19 15:04:26 +0000
committereb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>2008-06-19 15:04:26 +0000
commit8b04fb2beeae36bbbb8d66ce95dea7df8edb65be (patch)
tree4af4834b661ea2d6d502f30e6f2844ba0033d7f0 /omnithread
parentdf0ae475f782814c95d4f9be166aaffbcc7d47b1 (diff)
Moved mb_time to omni_time and left mb_time.h with typedef to maintain
backwards compatibility. Removed gcell's dependency on mblocks. Now gcell only depends on omnithread. Merged eb/wip -r8621:8623 to trunk. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8624 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'omnithread')
-rw-r--r--omnithread/Makefile.am3
-rw-r--r--omnithread/omni_time.cc84
-rw-r--r--omnithread/omni_time.h89
3 files changed, 176 insertions, 0 deletions
diff --git a/omnithread/Makefile.am b/omnithread/Makefile.am
index 0985f4ed45..d0dde72b2a 100644
--- a/omnithread/Makefile.am
+++ b/omnithread/Makefile.am
@@ -37,11 +37,13 @@ lib_LTLIBRARIES = libgromnithread.la
if OMNITHREAD_POSIX
libgromnithread_la_SOURCES = \
+ omni_time.cc \
posix.cc
endif
if OMNITHREAD_NT
libgromnithread_la_SOURCES = \
+ omni_time.cc \
nt.cc
endif
@@ -67,6 +69,7 @@ EXTRA_DIST = \
grinclude_HEADERS = \
omnithread.h \
+ omni_time.h \
ot_mach.h \
ot_nt.h \
ot_posix.h \
diff --git a/omnithread/omni_time.cc b/omnithread/omni_time.cc
new file mode 100644
index 0000000000..8703245bff
--- /dev/null
+++ b/omnithread/omni_time.cc
@@ -0,0 +1,84 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <omni_time.h>
+#include <omnithread.h>
+#include <math.h>
+#include <assert.h>
+
+
+omni_time::omni_time(double real_secs)
+{
+ double floor_secs = floor(real_secs);
+ d_secs = (long) floor_secs;
+ d_nsecs = (long) ((real_secs - floor_secs) * 1e9); // always positive
+}
+
+omni_time
+omni_time::time(const omni_time &delta_t)
+{
+ unsigned long abs_sec, abs_nsec;
+ unsigned long rel_sec = delta_t.d_secs;
+ unsigned long rel_nsec = delta_t.d_nsecs;
+
+ omni_thread::get_time(&abs_sec, &abs_nsec, rel_sec, rel_nsec);
+ return omni_time(abs_sec, abs_nsec);
+}
+
+
+omni_time
+operator+(const omni_time &x, const omni_time &y)
+{
+ omni_time r(x.d_secs + y.d_secs, x.d_nsecs + y.d_nsecs);
+ while (r.d_nsecs >= 1000000000){
+ r.d_nsecs -= 1000000000;
+ r.d_secs++;
+ }
+ return r;
+}
+
+omni_time
+operator-(const omni_time &x, const omni_time &y)
+{
+ // assert(!(x < y));
+
+ omni_time r(x.d_secs - y.d_secs, x.d_nsecs - y.d_nsecs);
+ while (r.d_nsecs < 0){
+ r.d_nsecs += 1000000000;
+ r.d_secs--;
+ }
+ return r;
+}
+
+omni_time
+operator+(const omni_time &x, double y)
+{
+ return x + omni_time(y);
+}
+
+omni_time
+operator-(const omni_time &x, double y)
+{
+ return x - omni_time(y);
+}
diff --git a/omnithread/omni_time.h b/omnithread/omni_time.h
new file mode 100644
index 0000000000..bfb1516104
--- /dev/null
+++ b/omnithread/omni_time.h
@@ -0,0 +1,89 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_OMNI_TIME_H
+#define INCLUDED_OMNI_TIME_H
+
+struct omni_time {
+ long int d_secs; // seconds.
+ long int d_nsecs; // nanoseconds. Always in [0, 1e9-1]
+
+ omni_time() : d_secs(0), d_nsecs(0) {}
+ omni_time(long secs, long nanosecs=0) : d_secs(secs), d_nsecs(nanosecs) {}
+
+ // N.B., this only makes sense for differences between times.
+ // Double doesn't have enough bits to precisely represent an absolute time.
+ omni_time(double secs);
+
+ // N.B. This only makes sense for differences between times.
+ // Double doesn't have enough bits to precisely represent an absolute time.
+ double double_time() const { return (double)d_secs + d_nsecs * 1e-9; }
+
+ /*!
+ * \brief Return an absolute time suitable for use with
+ * schedule_one_shot_timeout & schedule_periodic_timeout
+ *
+ * The return value is the current time plus the given relative offset.
+ */
+ static omni_time time(const omni_time &relative_offset = omni_time());
+};
+
+
+inline static bool
+operator<(const omni_time &x, const omni_time &y)
+{
+ return ((x.d_secs < y.d_secs)
+ || (x.d_secs == y.d_secs && x.d_nsecs < y.d_nsecs));
+}
+
+inline static bool
+operator>(const omni_time &x, const omni_time &y)
+{
+ return ((x.d_secs > y.d_secs)
+ || (x.d_secs == y.d_secs && x.d_nsecs > y.d_nsecs));
+}
+
+inline static bool
+operator>=(const omni_time &x, const omni_time &y)
+{
+ return ((x.d_secs > y.d_secs)
+ || (x.d_secs == y.d_secs && x.d_nsecs >= y.d_nsecs));
+}
+
+inline static bool
+operator<=(const omni_time &x, const omni_time &y)
+{
+ return ((x.d_secs < y.d_secs)
+ || (x.d_secs == y.d_secs && x.d_nsecs <= y.d_nsecs));
+}
+
+inline static bool
+operator==(const omni_time &x, const omni_time &y)
+{
+ return (x.d_secs == y.d_secs && x.d_nsecs == y.d_nsecs);
+}
+
+
+omni_time operator+(const omni_time &x, const omni_time &y);
+omni_time operator+(const omni_time &x, double y);
+omni_time operator-(const omni_time &x, const omni_time &y);
+omni_time operator-(const omni_time &x, double y);
+
+#endif /* INCLUDED_OMNI_TIME_H */