[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4806 - gnuradio/branches/developers/eb/mb/mblock/src/
From: |
eb |
Subject: |
[Commit-gnuradio] r4806 - gnuradio/branches/developers/eb/mb/mblock/src/lib |
Date: |
Tue, 27 Mar 2007 21:45:42 -0600 (MDT) |
Author: eb
Date: 2007-03-27 21:45:42 -0600 (Tue, 27 Mar 2007)
New Revision: 4806
Added:
gnuradio/branches/developers/eb/mb/mblock/src/lib/README.locking
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_placeholder.cc
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_placeholder.h
gnuradio/branches/developers/eb/mb/mblock/src/lib/mbi_runtime_lock.h
Modified:
gnuradio/branches/developers/eb/mb/mblock/src/lib/Makefile.am
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_common.h
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock.h
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock_impl.cc
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock_impl.h
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_port_simple.cc
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime.h
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.cc
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.h
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_thread_per_mblock.cc
Log:
Added "Big Runtime Lock" to protect interconnection data structures.
Modified: gnuradio/branches/developers/eb/mb/mblock/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/Makefile.am
2007-03-28 00:02:35 UTC (rev 4805)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/Makefile.am
2007-03-28 03:45:42 UTC (rev 4806)
@@ -27,7 +27,8 @@
lib_LTLIBRARIES = libmblock.la libmblock-qa.la
-EXTRA_DIST =
+EXTRA_DIST = \
+ README.locking
# These are the source files that go into the mblock shared library
@@ -46,6 +47,7 @@
mb_protocol_class.cc \
mb_runtime.cc \
mb_runtime_nop.cc \
+ mb_runtime_placeholder.cc \
mb_runtime_thread_per_mblock.cc \
mb_util.cc
@@ -71,6 +73,7 @@
mb_protocol_class.h \
mb_runtime.h \
mb_runtime_nop.h \
+ mb_runtime_placeholder.h \
mb_runtime_thread_per_mblock.h \
mb_util.h
@@ -80,6 +83,7 @@
mb_endpoint.h \
mb_mblock_impl.h \
mb_msg_accepter_smp.h \
+ mbi_runtime_lock.h \
qa_mblock.h \
qa_mblock_prims.h \
qa_mblock_send.h
Added: gnuradio/branches/developers/eb/mb/mblock/src/lib/README.locking
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/README.locking
(rev 0)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/README.locking
2007-03-28 03:45:42 UTC (rev 4806)
@@ -0,0 +1,4 @@
+The Big Runtime Lock must be held when:
+
+Manipulating or traversing any mblock's d_port_map, d_comp_map or d_conn_table.
+
Modified: gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_common.h
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_common.h
2007-03-28 00:02:35 UTC (rev 4805)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_common.h
2007-03-28 03:45:42 UTC (rev 4806)
@@ -26,8 +26,8 @@
#include <stdexcept>
#include <boost/utility.hpp>
#include <boost/enable_shared_from_this.hpp>
+#include <boost/weak_ptr.hpp>
-
/*
* The priority type and valid range
*/
Modified: gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock.h
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock.h
2007-03-28 00:02:35 UTC (rev 4805)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock.h
2007-03-28 03:45:42 UTC (rev 4806)
@@ -24,7 +24,6 @@
#include <mb_common.h>
#include <mb_message.h>
#include <mb_port.h>
-#include <boost/enable_shared_from_this.hpp>
/*!
Modified: gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock_impl.cc
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock_impl.cc
2007-03-28 00:02:35 UTC (rev 4805)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock_impl.cc
2007-03-28 03:45:42 UTC (rev 4806)
@@ -30,6 +30,8 @@
#include <mb_exception.h>
#include <mb_util.h>
#include <mb_msg_accepter_smp.h>
+#include <mb_runtime_placeholder.h>
+#include <mbi_runtime_lock.h>
static pmt_t s_self = pmt_intern("self");
@@ -51,7 +53,7 @@
////////////////////////////////////////////////////////////////////////
mb_mblock_impl::mb_mblock_impl(mb_mblock *mb)
- : d_mb(mb), d_mb_parent(0),
+ : d_mb(mb), d_mb_parent(0), d_runtime(mb_runtime_placeholder::singleton()),
d_instance_name("<unknown>"), d_class_name("mblock")
{
}
@@ -68,6 +70,8 @@
bool conjugated,
mb_port::port_type_t port_type)
{
+ mbi_runtime_lock l(this);
+
if (port_is_defined(port_name))
throw mbe_duplicate_port(d_mb, port_name);
@@ -83,6 +87,8 @@
mb_mblock_impl::define_component(const std::string &name,
mb_mblock_sptr component)
{
+ mbi_runtime_lock l(this);
+
if (comp_is_defined(name)) // check for duplicate name
throw mbe_duplicate_component(d_mb, name);
@@ -96,6 +102,8 @@
const std::string &comp_name2,
const std::string &port_name2)
{
+ mbi_runtime_lock l(this);
+
mb_endpoint ep0 = check_and_resolve_endpoint(comp_name1, port_name1);
mb_endpoint ep1 = check_and_resolve_endpoint(comp_name2, port_name2);
@@ -114,24 +122,32 @@
const std::string &comp_name2,
const std::string &port_name2)
{
+ mbi_runtime_lock l(this);
+
d_conn_table.disconnect(comp_name1, port_name1, comp_name2, port_name2);
}
void
mb_mblock_impl::disconnect_component(const std::string component_name)
{
+ mbi_runtime_lock l(this);
+
d_conn_table.disconnect_component(component_name);
}
void
mb_mblock_impl::disconnect_all()
{
+ mbi_runtime_lock l(this);
+
d_conn_table.disconnect_all();
}
int
-mb_mblock_impl::nconnections() const
+mb_mblock_impl::nconnections()
{
+ mbi_runtime_lock l(this);
+
return d_conn_table.nconnections();
}
@@ -220,6 +236,7 @@
mb_msg_accepter_sptr
mb_mblock_impl::make_accepter(const std::string port_name)
{
+ // FIXME this should probably use some kind of configurable factory
mb_msg_accepter *ma =
new mb_msg_accepter_smp(d_mb->shared_from_this(),
pmt_intern(port_name));
Modified: gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock_impl.h
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock_impl.h
2007-03-28 00:02:35 UTC (rev 4805)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_mblock_impl.h
2007-03-28 03:45:42 UTC (rev 4806)
@@ -39,6 +39,7 @@
{
mb_mblock *d_mb; // pointer to our associated
mblock
mb_mblock *d_mb_parent; // pointer to our parent
+ mb_runtime *d_runtime; // pointer to runtime
std::string d_instance_name; // hierarchical name
std::string d_class_name; // name of this (derived)
class
@@ -137,7 +138,7 @@
* \brief Return number of connections (QA mostly)
*/
int
- nconnections() const;
+ nconnections();
bool
walk_tree(mb_visitor *visitor, const std::string &path="");
@@ -172,16 +173,21 @@
lookup_other_endpoint(const mb_port *port, mb_endpoint *ep);
- mb_mblock *
- mblock() const { return d_mb; }
+ //! Return point to associated mblock
+ mb_mblock *mblock() const { return d_mb; }
- mb_mblock *
- mblock_parent() const { return d_mb_parent; }
+ //! Return pointer to the parent of our mblock
+ mb_mblock *mblock_parent() const { return d_mb_parent; }
- mb_mblock_sptr
- component(const std::string &comp_name);
+ //! Lookup a component by name
+ mb_mblock_sptr component(const std::string &comp_name);
+ //! Return the runtime instance
+ mb_runtime *runtime() { return d_runtime; }
+ //! Set the runtime instance
+ void set_runtime(mb_runtime *runtime) { d_runtime = runtime; }
+
/*
* Our implementation methods
*/
Modified: gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_port_simple.cc
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_port_simple.cc
2007-03-28 00:02:35 UTC (rev 4805)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_port_simple.cc
2007-03-28 03:45:42 UTC (rev 4806)
@@ -29,6 +29,7 @@
#include <mb_mblock.h>
#include <mb_mblock_impl.h>
#include <assert.h>
+#include <mbi_runtime_lock.h>
mb_port_simple::mb_port_simple(mb_mblock *mblock,
@@ -66,6 +67,8 @@
mb_endpoint peer_ep;
mb_msg_accepter_sptr r;
+ mbi_runtime_lock l(p->mblock());
+
// Set up initial context.
switch(p->port_type()){
Modified: gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime.h
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime.h
2007-03-28 00:02:35 UTC (rev 4805)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime.h
2007-03-28 03:45:42 UTC (rev 4806)
@@ -22,6 +22,7 @@
#define INCLUDED_MB_RUNTIME_H
#include <mb_common.h>
+#include <omnithread.h>
/*!
* \brief Public constructor (factory) for mb_runtime objects.
@@ -33,8 +34,11 @@
*
* There should generally be only a single instance of this class.
*/
-class mb_runtime : boost::noncopyable
+class mb_runtime : boost::noncopyable,
+ public boost::enable_shared_from_this<mb_runtime>
{
+ omni_mutex d_brl; // big runtime lock (avoid using this if
possible...)
+
public:
mb_runtime(){}
virtual ~mb_runtime();
@@ -49,6 +53,24 @@
* \returns true if the system ran successfully.
*/
virtual bool run(mb_mblock_sptr top) = 0;
+
+
+ // ----------------------------------------------------------------
+ // Stuff from here down is really private to the implementation...
+ // ----------------------------------------------------------------
+
+ /*!
+ * \brief lock the big runtime lock
+ * \implementation
+ */
+ inline void lock() { d_brl.lock(); }
+
+ /*!
+ * \brief unlock the big runtime lock
+ * \implementation
+ */
+ inline void unlock() { d_brl.unlock(); }
+
};
#endif /* INCLUDED_MB_RUNTIME_H */
Modified: gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.cc
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.cc
2007-03-28 00:02:35 UTC (rev 4805)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.cc
2007-03-28 03:45:42 UTC (rev 4806)
@@ -58,9 +58,7 @@
initial_visitor visitor;
- d_top = top; // remember top of tree
+ top->walk_tree(&visitor);
- d_top->walk_tree(&visitor);
-
return true;
}
Modified: gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.h
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.h
2007-03-28 00:02:35 UTC (rev 4805)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.h
2007-03-28 03:45:42 UTC (rev 4806)
@@ -33,7 +33,6 @@
*/
class mb_runtime_nop : public mb_runtime
{
- mb_mblock_sptr d_top; // top mblock
public:
mb_runtime_nop();
Copied:
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_placeholder.cc
(from rev 4805,
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.cc)
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_placeholder.cc
(rev 0)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_placeholder.cc
2007-03-28 03:45:42 UTC (rev 4806)
@@ -0,0 +1,57 @@
+/* -*- 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_runtime_placeholder.h>
+#include <mb_mblock.h>
+#include <mb_exception.h>
+
+
+static mb_runtime *s_singleton = 0;
+
+
+mb_runtime_placeholder::mb_runtime_placeholder()
+{
+ // nop
+}
+
+mb_runtime_placeholder::~mb_runtime_placeholder()
+{
+ // nop
+}
+
+bool
+mb_runtime_placeholder::run(mb_mblock_sptr top)
+{
+ throw mbe_not_implemented(top.get(), "mb_runtime_placeholder::run");
+}
+
+mb_runtime *
+mb_runtime_placeholder::singleton()
+{
+ if (s_singleton)
+ return s_singleton;
+
+ s_singleton = new mb_runtime_placeholder();
+ return s_singleton;
+}
Copied:
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_placeholder.h
(from rev 4805,
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_nop.h)
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_placeholder.h
(rev 0)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_placeholder.h
2007-03-28 03:45:42 UTC (rev 4806)
@@ -0,0 +1,50 @@
+/* -*- 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.
+ */
+#ifndef INCLUDED_MB_RUNTIME_PLACEHOLDER_H
+#define INCLUDED_MB_RUNTIME_PLACEHOLDER_H
+
+#include <mb_runtime.h>
+
+/*!
+ * \brief Concrete runtime that serves as a placeholder until the real
+ * runtime is known.
+ *
+ * The singleton instance of this class is installed in the d_runtime
+ * instance variable of each mb_mblock_impl at construction time.
+ * Having a valid instance of runtime removes the "pre runtime::run"
+ * corner case, and allows us to lock and unlock the big runtime lock
+ * even though there's no "real runtime" yet.
+ */
+class mb_runtime_placeholder : public mb_runtime
+{
+
+public:
+ mb_runtime_placeholder();
+ ~mb_runtime_placeholder();
+
+ //! throws mbe_not_implemented
+ bool run(mb_mblock_sptr top);
+
+ //! Return the placeholder singleton
+ static mb_runtime *singleton();
+};
+
+#endif /* INCLUDED_MB_RUNTIME_PLACEHOLDER_H */
Modified:
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_thread_per_mblock.cc
===================================================================
---
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_thread_per_mblock.cc
2007-03-28 00:02:35 UTC (rev 4805)
+++
gnuradio/branches/developers/eb/mb/mblock/src/lib/mb_runtime_thread_per_mblock.cc
2007-03-28 03:45:42 UTC (rev 4806)
@@ -24,6 +24,7 @@
#endif
#include <mb_runtime_thread_per_mblock.h>
#include <mb_mblock.h>
+#include <mb_mblock_impl.h>
mb_runtime_thread_per_mblock::mb_runtime_thread_per_mblock()
@@ -41,16 +42,20 @@
{
class initial_visitor : public mb_visitor
{
+ mb_runtime *d_rt;
+
public:
+ initial_visitor(mb_runtime *rt) : d_rt(rt) {}
bool operator()(mb_mblock *mblock, const std::string &path)
{
+ mblock->impl()->set_runtime(d_rt);
mblock->set_instance_name(path);
mblock->init_fsm();
return true;
}
};
- initial_visitor visitor;
+ initial_visitor visitor(this);
d_top = top; // remember top of tree
Added: gnuradio/branches/developers/eb/mb/mblock/src/lib/mbi_runtime_lock.h
===================================================================
--- gnuradio/branches/developers/eb/mb/mblock/src/lib/mbi_runtime_lock.h
(rev 0)
+++ gnuradio/branches/developers/eb/mb/mblock/src/lib/mbi_runtime_lock.h
2007-03-28 03:45:42 UTC (rev 4806)
@@ -0,0 +1,61 @@
+/* -*- 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.
+ */
+
+#ifndef INCLUDED_MBI_RUNTIME_LOCK_H
+#define INCLUDED_MBI_RUNTIME_LOCK_H
+
+#include <mb_runtime.h>
+#include <mb_mblock_impl.h>
+#include <boost/utility.hpp>
+
+/*!
+ * \brief acquire and release big runtime lock
+ *
+ * As an alternative to:
+ * {
+ * rt->lock();
+ * .....
+ * rt->unlock();
+ * }
+ *
+ * you can use a single instance of the mbi_runtime_lock class:
+ *
+ * {
+ * mbi_runtime_lock l(rt);
+ * ....
+ * }
+ *
+ * This has the advantage that rt->unlock() will be called automatically
+ * when an exception is thrown.
+ */
+
+class mbi_runtime_lock : boost::noncopyable {
+ mb_runtime *d_rt;
+public:
+ mbi_runtime_lock(mb_runtime *rt) : d_rt(rt) { d_rt->lock(); }
+ mbi_runtime_lock(mb_mblock_impl *mi) : d_rt(mi->runtime()) { d_rt->lock(); }
+ mbi_runtime_lock(mb_mblock *mb) : d_rt(mb->impl()->runtime()) {
d_rt->lock(); }
+ ~mbi_runtime_lock(void) { d_rt->unlock(); }
+
+};
+
+#endif /* INCLUDED_MBI_RUNTIME_LOCK_H */
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4806 - gnuradio/branches/developers/eb/mb/mblock/src/lib,
eb <=