[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5063 - gnuradio/branches/developers/eb/ibu/mblock/src
From: |
eb |
Subject: |
[Commit-gnuradio] r5063 - gnuradio/branches/developers/eb/ibu/mblock/src/lib |
Date: |
Sat, 21 Apr 2007 13:26:55 -0600 (MDT) |
Author: eb
Date: 2007-04-21 13:26:54 -0600 (Sat, 21 Apr 2007)
New Revision: 5063
Added:
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_time.cc
gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_timeouts.cc
gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_timeouts.h
Modified:
gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_time.h
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.cc
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.h
gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock.cc
Log:
work-in-progress on mblock timeouts
Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
2007-04-21 17:15:14 UTC (rev 5062)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
2007-04-21 19:26:54 UTC (rev 5063)
@@ -58,6 +58,7 @@
mb_runtime_base.cc \
mb_runtime_nop.cc \
mb_runtime_thread_per_block.cc \
+ mb_time.cc \
mb_timer_queue.cc \
mb_util.cc \
mb_worker.cc
@@ -104,7 +105,8 @@
qa_mblock.h \
qa_mblock_prims.h \
qa_mblock_send.h \
- qa_mblock_sys.h
+ qa_mblock_sys.h \
+ qa_timeouts.h
# Build the qa code into its own library
@@ -116,7 +118,8 @@
qa_mblock.cc \
qa_mblock_prims.cc \
qa_mblock_send.cc \
- qa_mblock_sys.cc
+ qa_mblock_sys.cc \
+ qa_timeouts.cc
# magic flags
Modified:
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
===================================================================
---
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
2007-04-21 17:15:14 UTC (rev 5062)
+++
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
2007-04-21 19:26:54 UTC (rev 5063)
@@ -143,10 +143,12 @@
}
}
else if (pmt_eq(signal, s_request_timeout)){ // %request-timeout
- std::cerr << "mb_runtime_thread_per_block: unimplemented msg: " << msg
<< std::endl;
+ mb_timeout_sptr to =
+ boost::any_cast<mb_timeout_sptr>(pmt_any_ref(msg->data()));
+ d_timer_queue.push(to);
}
else if (pmt_eq(signal, s_cancel_timeout)){ //
%cancel-timeout
- std::cerr << "mb_runtime_thread_per_block: unimplemented msg: " << msg
<< std::endl;
+ d_timer_queue.cancel(msg->data());
}
else {
std::cerr << "mb_runtime_thread_per_block: unhandled msg: " << msg <<
std::endl;
Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_time.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_time.cc
(rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_time.cc
2007-04-21 19:26:54 UTC (rev 5063)
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 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 2, 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 <mb_time.h>
+#include <assert.h>
+
+mb_time
+operator+(const mb_time &x, const mb_time &y)
+{
+ mb_time r(x.d_sec + y.d_sec, x.d_nsec + y.d_nsec);
+ while (r.d_nsec >= 1000000000){
+ r.d_nsec -= 1000000000;
+ r.d_sec++;
+ }
+ return r;
+}
+
+mb_time
+operator-(const mb_time &x, const mb_time &y)
+{
+ // assert(!(x < y));
+
+ mb_time r(x.d_sec - y.d_sec, x.d_nsec - y.d_nsec);
+ while (r.d_nsec < 0){
+ r.d_nsec += 1000000000;
+ r.d_sec--;
+ }
+ return r;
+}
+
Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_time.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_time.h
2007-04-21 17:15:14 UTC (rev 5062)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_time.h
2007-04-21 19:26:54 UTC (rev 5063)
@@ -29,6 +29,43 @@
mb_time(long secs, long nanosecs=0) : d_sec(secs), d_nsec(nanosecs) {}
};
-typedef unsigned long mb_timeout_t;
+inline static bool
+operator<(const mb_time &x, const mb_time &y)
+{
+ return ((x.d_sec < y.d_sec)
+ || (x.d_sec == y.d_sec && x.d_nsec < y.d_nsec));
+}
+
+inline static bool
+operator>(const mb_time &x, const mb_time &y)
+{
+ return ((x.d_sec > y.d_sec)
+ || (x.d_sec == y.d_sec && x.d_nsec > y.d_nsec));
+}
+
+inline static bool
+operator>=(const mb_time &x, const mb_time &y)
+{
+ return ((x.d_sec > y.d_sec)
+ || (x.d_sec == y.d_sec && x.d_nsec >= y.d_nsec));
+}
+
+inline static bool
+operator<=(const mb_time &x, const mb_time &y)
+{
+ return ((x.d_sec < y.d_sec)
+ || (x.d_sec == y.d_sec && x.d_nsec <= y.d_nsec));
+}
+
+inline static bool
+operator==(const mb_time &x, const mb_time &y)
+{
+ return (x.d_sec == y.d_sec && x.d_nsec == y.d_nsec);
+}
+
+
+mb_time operator+(const mb_time &x, const mb_time &y);
+mb_time operator-(const mb_time &x, const mb_time &y);
+
#endif /* INCLUDED_MB_TIME_H */
Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.cc
2007-04-21 17:15:14 UTC (rev 5062)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.cc
2007-04-21 19:26:54 UTC (rev 5063)
@@ -51,5 +51,13 @@
void
mb_timer_queue::cancel(pmt_t handle)
{
- // FIXME
+ container_type::iterator it;
+
+ for (it = c.begin(); it != c.end();){
+ if (pmt_equal((*it)->handle(), handle))
+ it = c.erase(it);
+ else
+ ++it;
+ }
+ std::make_heap(c.begin(), c.end(), comp);
}
Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.h
2007-04-21 17:15:14 UTC (rev 5062)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.h
2007-04-21 19:26:54 UTC (rev 5063)
@@ -57,12 +57,11 @@
public:
bool operator() (const mb_timeout_sptr t1, const mb_timeout_sptr t2)
{
- return ((t1->d_when.d_sec > t2->d_when.d_sec)
- || (t1->d_when.d_sec == t2->d_when.d_sec
- && t1->d_when.d_nsec > t2->d_when.d_nsec));
+ return t1->d_when > t2->d_when;
}
};
+
class mb_timer_queue : public std::priority_queue<mb_timeout_sptr,
std::vector<mb_timeout_sptr>,
timeout_later>
Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock.cc
2007-04-21 17:15:14 UTC (rev 5062)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock.cc
2007-04-21 19:26:54 UTC (rev 5063)
@@ -28,6 +28,7 @@
#include <qa_mblock_prims.h>
#include <qa_mblock_send.h>
#include <qa_mblock_sys.h>
+#include <qa_timeouts.h>
CppUnit::TestSuite *
qa_mblock::suite()
@@ -37,6 +38,7 @@
s->addTest (qa_mblock_prims::suite());
s->addTest (qa_mblock_send::suite());
s->addTest (qa_mblock_sys::suite());
+ s->addTest (qa_timeouts::suite());
return s;
}
Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_timeouts.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_timeouts.cc
(rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_timeouts.cc
2007-04-21 19:26:54 UTC (rev 5063)
@@ -0,0 +1,120 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 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 2, 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 <qa_timeouts.h>
+#include <cppunit/TestAssert.h>
+#include <mb_mblock.h>
+#include <mb_runtime.h>
+#include <mb_protocol_class.h>
+#include <mb_exception.h>
+#include <mb_msg_queue.h>
+#include <mb_message.h>
+#include <mb_mblock_impl.h>
+#include <mb_msg_accepter.h>
+#include <mb_class_registry.h>
+#include <mb_timer_queue.h>
+#include <stdio.h>
+#include <string.h>
+#include <iostream>
+
+void
+qa_timeouts::test_timer_queue()
+{
+ mb_timer_queue tq;
+ mb_msg_accepter_sptr accepter;
+
+ mb_timeout_sptr t1000_000 =
+ mb_timeout_sptr(new mb_timeout(mb_time(1000,0), PMT_F, accepter));
+
+ mb_timeout_sptr t2000_000 =
+ mb_timeout_sptr(new mb_timeout(mb_time(2000,0), PMT_F, accepter));
+
+ mb_timeout_sptr t3000_000 =
+ mb_timeout_sptr(new mb_timeout(mb_time(3000,0), PMT_F, accepter));
+
+ mb_timeout_sptr t3000_125 =
+ mb_timeout_sptr(new mb_timeout(mb_time(3000,125), PMT_F, accepter));
+
+ mb_timeout_sptr t3000_250 =
+ mb_timeout_sptr(new mb_timeout(mb_time(3000,250), PMT_F, accepter));
+
+ mb_timeout_sptr t4000_000 =
+ mb_timeout_sptr(new mb_timeout(mb_time(4000,0), PMT_F, accepter));
+
+ // insert in pseudo-random order
+
+ tq.push(t3000_125);
+ tq.push(t1000_000);
+ tq.push(t4000_000);
+ tq.push(t3000_250);
+ tq.push(t2000_000);
+ tq.push(t3000_000);
+
+ CPPUNIT_ASSERT_EQUAL(t1000_000, tq.top());
+ tq.pop();
+
+ CPPUNIT_ASSERT_EQUAL(t2000_000, tq.top());
+ tq.pop();
+
+ CPPUNIT_ASSERT_EQUAL(t3000_000, tq.top());
+ tq.pop();
+
+ CPPUNIT_ASSERT_EQUAL(t3000_125, tq.top());
+ tq.pop();
+
+ CPPUNIT_ASSERT_EQUAL(t3000_250, tq.top());
+ tq.pop();
+
+ CPPUNIT_ASSERT_EQUAL(t4000_000, tq.top());
+ tq.pop();
+
+ CPPUNIT_ASSERT(tq.empty());
+
+ // insert in pseudo-random order
+
+ tq.push(t3000_000);
+ tq.push(t4000_000);
+ tq.push(t3000_125);
+ tq.push(t1000_000);
+ tq.push(t2000_000);
+ tq.push(t3000_250);
+
+ tq.cancel(t1000_000->handle());
+
+ CPPUNIT_ASSERT_EQUAL(t2000_000, tq.top());
+ tq.pop();
+
+ CPPUNIT_ASSERT_EQUAL(t3000_000, tq.top());
+ tq.pop();
+
+ tq.cancel(t3000_250->handle());
+
+ CPPUNIT_ASSERT_EQUAL(t3000_125, tq.top());
+ tq.pop();
+
+ CPPUNIT_ASSERT_EQUAL(t4000_000, tq.top());
+ tq.pop();
+
+ CPPUNIT_ASSERT(tq.empty());
+}
Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_timeouts.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_timeouts.h
(rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_timeouts.h
2007-04-21 19:26:54 UTC (rev 5063)
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2007 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 2, 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef INCLUDED_QA_TIMEOUTS_H
+#define INCLUDED_QA_TIMEOUTS_H
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+
+class qa_timeouts : public CppUnit::TestCase {
+
+ CPPUNIT_TEST_SUITE(qa_timeouts);
+ CPPUNIT_TEST(test_timer_queue);
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+ void test_timer_queue();
+};
+
+#endif /* INCLUDED_QA_TIMEOUTS_H */
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5063 - gnuradio/branches/developers/eb/ibu/mblock/src/lib,
eb <=