Revision 7833f98e
| b/configure.ac | ||
|---|---|---|
| 213 | 213 |
GRC_GR_RADIO_ASTRONOMY |
| 214 | 214 |
GRC_GR_TRELLIS |
| 215 | 215 |
GRC_GR_VIDEO_SDL |
| 216 |
#GRC_GR_QTGUI dnl disabled until grc_gr_qtgui.m4 is final
|
|
| 216 |
GRC_GR_QTGUI dnl disabled until grc_gr_qtgui.m4 is final |
|
| 217 | 217 |
GRC_GR_WXGUI |
| 218 | 218 |
GRC_PMT |
| 219 | 219 |
GRC_MBLOCK dnl this must come after GRC_PMT |
| b/mblock/src/lib/Makefile.am | ||
|---|---|---|
| 27 | 27 |
|
| 28 | 28 |
lib_LTLIBRARIES = libmblock.la libmblock-qa.la |
| 29 | 29 |
|
| 30 |
EXTRA_DIST = |
|
| 30 |
EXTRA_DIST = \ |
|
| 31 |
README.locking |
|
| 31 | 32 |
|
| 32 | 33 |
|
| 33 | 34 |
# These are the source files that go into the mblock shared library |
| ... | ... | |
| 45 | 46 |
mb_port_simple.cc \ |
| 46 | 47 |
mb_protocol_class.cc \ |
| 47 | 48 |
mb_runtime.cc \ |
| 48 |
mb_runtime_single_threaded.cc \ |
|
| 49 |
mb_runtime_nop.cc \ |
|
| 50 |
mb_runtime_placeholder.cc \ |
|
| 51 |
mb_runtime_thread_per_mblock.cc \ |
|
| 49 | 52 |
mb_util.cc |
| 50 | 53 |
|
| 51 | 54 |
|
| ... | ... | |
| 69 | 72 |
mb_port_simple.h \ |
| 70 | 73 |
mb_protocol_class.h \ |
| 71 | 74 |
mb_runtime.h \ |
| 72 |
mb_runtime_single_threaded.h \ |
|
| 75 |
mb_runtime_nop.h \ |
|
| 76 |
mb_runtime_placeholder.h \ |
|
| 77 |
mb_runtime_thread_per_mblock.h \ |
|
| 73 | 78 |
mb_util.h |
| 74 | 79 |
|
| 75 | 80 |
|
| ... | ... | |
| 78 | 83 |
mb_endpoint.h \ |
| 79 | 84 |
mb_mblock_impl.h \ |
| 80 | 85 |
mb_msg_accepter_smp.h \ |
| 86 |
mbi_runtime_lock.h \ |
|
| 81 | 87 |
qa_mblock.h \ |
| 82 | 88 |
qa_mblock_prims.h \ |
| 83 | 89 |
qa_mblock_send.h |
| b/mblock/src/lib/README.locking | ||
|---|---|---|
| 1 |
The Big Runtime Lock must be held when: |
|
| 2 |
|
|
| 3 |
Manipulating or traversing any mblock's d_port_map, d_comp_map or d_conn_table. |
|
| 4 |
|
|
| b/mblock/src/lib/mb_common.h | ||
|---|---|---|
| 26 | 26 |
#include <stdexcept> |
| 27 | 27 |
#include <boost/utility.hpp> |
| 28 | 28 |
#include <boost/enable_shared_from_this.hpp> |
| 29 |
|
|
| 29 |
#include <boost/weak_ptr.hpp> |
|
| 30 | 30 |
|
| 31 | 31 |
/* |
| 32 | 32 |
* The priority type and valid range |
| b/mblock/src/lib/mb_mblock.cc | ||
|---|---|---|
| 121 | 121 |
} |
| 122 | 122 |
|
| 123 | 123 |
std::string |
| 124 |
mb_mblock::fullname() const
|
|
| 124 |
mb_mblock::instance_name() const
|
|
| 125 | 125 |
{
|
| 126 |
return d_impl->fullname();
|
|
| 126 |
return d_impl->instance_name();
|
|
| 127 | 127 |
} |
| 128 | 128 |
|
| 129 | 129 |
void |
| 130 |
mb_mblock::set_fullname(const std::string name)
|
|
| 130 |
mb_mblock::set_instance_name(const std::string name)
|
|
| 131 | 131 |
{
|
| 132 |
d_impl->set_fullname(name); |
|
| 132 |
d_impl->set_instance_name(name); |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
std::string |
|
| 136 |
mb_mblock::class_name() const |
|
| 137 |
{
|
|
| 138 |
return d_impl->class_name(); |
|
| 139 |
} |
|
| 140 |
|
|
| 141 |
void |
|
| 142 |
mb_mblock::set_class_name(const std::string name) |
|
| 143 |
{
|
|
| 144 |
d_impl->set_class_name(name); |
|
| 133 | 145 |
} |
| 134 | 146 |
|
| 135 | 147 |
mb_mblock * |
| b/mblock/src/lib/mb_mblock.h | ||
|---|---|---|
| 24 | 24 |
#include <mb_common.h> |
| 25 | 25 |
#include <mb_message.h> |
| 26 | 26 |
#include <mb_port.h> |
| 27 |
#include <boost/enable_shared_from_this.hpp> |
|
| 28 | 27 |
|
| 29 | 28 |
|
| 30 | 29 |
/*! |
| ... | ... | |
| 175 | 174 |
int |
| 176 | 175 |
nconnections() const; |
| 177 | 176 |
|
| 177 |
//! Set the class name |
|
| 178 |
void set_class_name(const std::string name); |
|
| 178 | 179 |
|
| 179 | 180 |
public: |
| 180 | 181 |
virtual ~mb_mblock(); |
| 181 | 182 |
|
| 182 |
void set_fullname(const std::string name); |
|
| 183 |
|
|
| 184 |
//! Return full name of this block |
|
| 185 |
std::string fullname() const; |
|
| 183 |
//! Return instance name of this block |
|
| 184 |
std::string instance_name() const; |
|
| 185 |
|
|
| 186 |
//! Return the class name of this block |
|
| 187 |
std::string class_name() const; |
|
| 186 | 188 |
|
| 189 |
//! Set the instance name of this block. |
|
| 190 |
void set_instance_name(const std::string name); |
|
| 191 |
|
|
| 187 | 192 |
//! Return the parent of this mblock, or 0 if we're the top-level block. |
| 188 | 193 |
mb_mblock *parent() const; |
| 189 | 194 |
|
| b/mblock/src/lib/mb_mblock_impl.cc | ||
|---|---|---|
| 30 | 30 |
#include <mb_exception.h> |
| 31 | 31 |
#include <mb_util.h> |
| 32 | 32 |
#include <mb_msg_accepter_smp.h> |
| 33 |
#include <mb_runtime_placeholder.h> |
|
| 34 |
#include <mbi_runtime_lock.h> |
|
| 33 | 35 |
|
| 34 | 36 |
|
| 35 | 37 |
static pmt_t s_self = pmt_intern("self");
|
| ... | ... | |
| 51 | 53 |
//////////////////////////////////////////////////////////////////////// |
| 52 | 54 |
|
| 53 | 55 |
mb_mblock_impl::mb_mblock_impl(mb_mblock *mb) |
| 54 |
: d_mb(mb), d_mb_parent(0), d_fullname("<unknown>")
|
|
| 56 |
: d_mb(mb), d_mb_parent(0), d_runtime(mb_runtime_placeholder::singleton()), |
|
| 57 |
d_instance_name("<unknown>"), d_class_name("mblock")
|
|
| 55 | 58 |
{
|
| 56 | 59 |
} |
| 57 | 60 |
|
| ... | ... | |
| 67 | 70 |
bool conjugated, |
| 68 | 71 |
mb_port::port_type_t port_type) |
| 69 | 72 |
{
|
| 73 |
mbi_runtime_lock l(this); |
|
| 74 |
|
|
| 70 | 75 |
if (port_is_defined(port_name)) |
| 71 | 76 |
throw mbe_duplicate_port(d_mb, port_name); |
| 72 | 77 |
|
| ... | ... | |
| 82 | 87 |
mb_mblock_impl::define_component(const std::string &name, |
| 83 | 88 |
mb_mblock_sptr component) |
| 84 | 89 |
{
|
| 90 |
mbi_runtime_lock l(this); |
|
| 91 |
|
|
| 85 | 92 |
if (comp_is_defined(name)) // check for duplicate name |
| 86 | 93 |
throw mbe_duplicate_component(d_mb, name); |
| 87 | 94 |
|
| ... | ... | |
| 95 | 102 |
const std::string &comp_name2, |
| 96 | 103 |
const std::string &port_name2) |
| 97 | 104 |
{
|
| 105 |
mbi_runtime_lock l(this); |
|
| 106 |
|
|
| 98 | 107 |
mb_endpoint ep0 = check_and_resolve_endpoint(comp_name1, port_name1); |
| 99 | 108 |
mb_endpoint ep1 = check_and_resolve_endpoint(comp_name2, port_name2); |
| 100 | 109 |
|
| ... | ... | |
| 113 | 122 |
const std::string &comp_name2, |
| 114 | 123 |
const std::string &port_name2) |
| 115 | 124 |
{
|
| 125 |
mbi_runtime_lock l(this); |
|
| 126 |
|
|
| 116 | 127 |
d_conn_table.disconnect(comp_name1, port_name1, comp_name2, port_name2); |
| 117 | 128 |
} |
| 118 | 129 |
|
| 119 | 130 |
void |
| 120 | 131 |
mb_mblock_impl::disconnect_component(const std::string component_name) |
| 121 | 132 |
{
|
| 133 |
mbi_runtime_lock l(this); |
|
| 134 |
|
|
| 122 | 135 |
d_conn_table.disconnect_component(component_name); |
| 123 | 136 |
} |
| 124 | 137 |
|
| 125 | 138 |
void |
| 126 | 139 |
mb_mblock_impl::disconnect_all() |
| 127 | 140 |
{
|
| 141 |
mbi_runtime_lock l(this); |
|
| 142 |
|
|
| 128 | 143 |
d_conn_table.disconnect_all(); |
| 129 | 144 |
} |
| 130 | 145 |
|
| 131 | 146 |
int |
| 132 |
mb_mblock_impl::nconnections() const
|
|
| 147 |
mb_mblock_impl::nconnections() |
|
| 133 | 148 |
{
|
| 149 |
mbi_runtime_lock l(this); |
|
| 150 |
|
|
| 134 | 151 |
return d_conn_table.nconnections(); |
| 135 | 152 |
} |
| 136 | 153 |
|
| ... | ... | |
| 219 | 236 |
mb_msg_accepter_sptr |
| 220 | 237 |
mb_mblock_impl::make_accepter(const std::string port_name) |
| 221 | 238 |
{
|
| 239 |
// FIXME this should probably use some kind of configurable factory |
|
| 222 | 240 |
mb_msg_accepter *ma = |
| 223 | 241 |
new mb_msg_accepter_smp(d_mb->shared_from_this(), |
| 224 | 242 |
pmt_intern(port_name)); |
| ... | ... | |
| 252 | 270 |
} |
| 253 | 271 |
|
| 254 | 272 |
void |
| 255 |
mb_mblock_impl::set_fullname(const std::string &name) |
|
| 273 |
mb_mblock_impl::set_instance_name(const std::string &name) |
|
| 274 |
{
|
|
| 275 |
d_instance_name = name; |
|
| 276 |
} |
|
| 277 |
|
|
| 278 |
void |
|
| 279 |
mb_mblock_impl::set_class_name(const std::string &name) |
|
| 256 | 280 |
{
|
| 257 |
d_fullname = name;
|
|
| 281 |
d_class_name = name;
|
|
| 258 | 282 |
} |
| 259 | 283 |
|
| b/mblock/src/lib/mb_mblock_impl.h | ||
|---|---|---|
| 39 | 39 |
{
|
| 40 | 40 |
mb_mblock *d_mb; // pointer to our associated mblock |
| 41 | 41 |
mb_mblock *d_mb_parent; // pointer to our parent |
| 42 |
mb_runtime *d_runtime; // pointer to runtime |
|
| 42 | 43 |
|
| 43 |
std::string d_fullname; // hierarchical name |
|
| 44 |
std::string d_instance_name; // hierarchical name |
|
| 45 |
std::string d_class_name; // name of this (derived) class |
|
| 44 | 46 |
|
| 45 | 47 |
mb_port_map_t d_port_map; // our ports |
| 46 | 48 |
mb_comp_map_t d_comp_map; // our components |
| ... | ... | |
| 136 | 138 |
* \brief Return number of connections (QA mostly) |
| 137 | 139 |
*/ |
| 138 | 140 |
int |
| 139 |
nconnections() const;
|
|
| 141 |
nconnections(); |
|
| 140 | 142 |
|
| 141 | 143 |
bool |
| 142 | 144 |
walk_tree(mb_visitor *visitor, const std::string &path=""); |
| ... | ... | |
| 147 | 149 |
mb_msg_queue & |
| 148 | 150 |
msgq() { return d_msgq; }
|
| 149 | 151 |
|
| 150 |
//! Return full name of this block
|
|
| 151 |
std::string fullname() const { return d_fullname; }
|
|
| 152 |
//! Return instance name of this block
|
|
| 153 |
std::string instance_name() const { return d_instance_name; }
|
|
| 152 | 154 |
|
| 153 |
//! Set the name of this block |
|
| 154 |
void set_fullname(const std::string &name); |
|
| 155 |
//! Set the instance name of this block |
|
| 156 |
void set_instance_name(const std::string &name); |
|
| 157 |
|
|
| 158 |
//! Return the class name of this block |
|
| 159 |
std::string class_name() const { return d_class_name; }
|
|
| 160 |
|
|
| 161 |
//! Set the class name |
|
| 162 |
void set_class_name(const std::string &name); |
|
| 155 | 163 |
|
| 156 | 164 |
/*! |
| 157 | 165 |
* \brief If bound, store endpoint from the other end of the connection. |
| ... | ... | |
| 165 | 173 |
lookup_other_endpoint(const mb_port *port, mb_endpoint *ep); |
| 166 | 174 |
|
| 167 | 175 |
|
| 168 |
mb_mblock * |
|
| 169 |
mblock() const { return d_mb; }
|
|
| 176 |
//! Return point to associated mblock |
|
| 177 |
mb_mblock *mblock() const { return d_mb; }
|
|
| 178 |
|
|
| 179 |
//! Return pointer to the parent of our mblock |
|
| 180 |
mb_mblock *mblock_parent() const { return d_mb_parent; }
|
|
| 170 | 181 |
|
| 171 |
mb_mblock *
|
|
| 172 |
mblock_parent() const { return d_mb_parent; }
|
|
| 182 |
//! Lookup a component by name
|
|
| 183 |
mb_mblock_sptr component(const std::string &comp_name);
|
|
| 173 | 184 |
|
| 174 |
mb_mblock_sptr
|
|
| 175 |
component(const std::string &comp_name);
|
|
| 185 |
//! Return the runtime instance
|
|
| 186 |
mb_runtime *runtime() { return d_runtime; }
|
|
| 176 | 187 |
|
| 188 |
//! Set the runtime instance |
|
| 189 |
void set_runtime(mb_runtime *runtime) { d_runtime = runtime; }
|
|
| 177 | 190 |
|
| 178 | 191 |
/* |
| 179 | 192 |
* Our implementation methods |
| b/mblock/src/lib/mb_msg_accepter_smp.cc | ||
|---|---|---|
| 45 | 45 |
mb_message_sptr msg = mb_make_message(signal, data, metadata, priority); |
| 46 | 46 |
msg->set_port_id(d_port_name); |
| 47 | 47 |
d_mb->impl()->msgq().insert(msg); |
| 48 |
|
|
| 49 |
// FIXME tell runtime that we're ready to run |
|
| 50 | 48 |
} |
| b/mblock/src/lib/mb_msg_queue.cc | ||
|---|---|---|
| 25 | 25 |
#include <mb_msg_queue.h> |
| 26 | 26 |
#include <mb_message.h> |
| 27 | 27 |
|
| 28 |
// FIXME turn this into a template so we can use it for the runq of mblocks too |
|
| 29 | 28 |
|
| 30 | 29 |
mb_msg_queue::mb_msg_queue() |
| 30 |
: d_not_empty(&d_mutex) |
|
| 31 | 31 |
{
|
| 32 | 32 |
} |
| 33 | 33 |
|
| ... | ... | |
| 51 | 51 |
d_queue[q].tail = msg; |
| 52 | 52 |
msg->d_next.reset(); // msg->d_next = 0; |
| 53 | 53 |
} |
| 54 |
|
|
| 54 | 55 |
// FIXME set bit in bitmap |
| 56 |
|
|
| 57 |
d_not_empty.signal(); |
|
| 55 | 58 |
} |
| 56 | 59 |
|
| 60 |
/* |
|
| 61 |
* Delete highest pri message from the queue and return it. |
|
| 62 |
* Returns equivalent of zero pointer if queue is empty. |
|
| 63 |
* |
|
| 64 |
* Caller must be holding d_mutex |
|
| 65 |
*/ |
|
| 57 | 66 |
mb_message_sptr |
| 58 |
mb_msg_queue::get_highest_pri_msg() |
|
| 67 |
mb_msg_queue::get_highest_pri_msg_helper()
|
|
| 59 | 68 |
{
|
| 60 |
omni_mutex_lock l(d_mutex); |
|
| 61 |
|
|
| 62 | 69 |
// FIXME use bitmap and ffz to find best queue in O(1) |
| 63 | 70 |
|
| 64 | 71 |
for (mb_pri_t q = 0; q <= MB_PRI_WORST; q++){
|
| ... | ... | |
| 78 | 85 |
|
| 79 | 86 |
return mb_message_sptr(); // equivalent of a zero pointer |
| 80 | 87 |
} |
| 88 |
|
|
| 89 |
|
|
| 90 |
mb_message_sptr |
|
| 91 |
mb_msg_queue::get_highest_pri_msg_nowait() |
|
| 92 |
{
|
|
| 93 |
omni_mutex_lock l(d_mutex); |
|
| 94 |
|
|
| 95 |
return get_highest_pri_msg_helper(); |
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
mb_message_sptr |
|
| 99 |
mb_msg_queue::get_highest_pri_msg() |
|
| 100 |
{
|
|
| 101 |
omni_mutex_lock l(d_mutex); |
|
| 102 |
|
|
| 103 |
while (1){
|
|
| 104 |
mb_message_sptr msg = get_highest_pri_msg_helper(); |
|
| 105 |
if (msg) // Got one; return it |
|
| 106 |
return msg; |
|
| 107 |
|
|
| 108 |
d_not_empty.wait(); // Wait for something |
|
| 109 |
} |
|
| 110 |
} |
|
| 111 |
|
|
| b/mblock/src/lib/mb_msg_queue.h | ||
|---|---|---|
| 37 | 37 |
bool empty_p() const { return head == 0; }
|
| 38 | 38 |
}; |
| 39 | 39 |
|
| 40 |
omni_mutex d_mutex; |
|
| 40 |
omni_mutex d_mutex; |
|
| 41 |
omni_condition d_not_empty; // reader waits on this |
|
| 41 | 42 |
|
| 42 | 43 |
// FIXME add bitmap to indicate which queues are non-empty. |
| 43 |
subq d_queue[MB_NPRI]; |
|
| 44 |
subq d_queue[MB_NPRI]; |
|
| 45 |
|
|
| 46 |
mb_message_sptr get_highest_pri_msg_helper(); |
|
| 44 | 47 |
|
| 45 | 48 |
public: |
| 46 | 49 |
mb_msg_queue(); |
| ... | ... | |
| 53 | 56 |
* \brief Delete highest pri message from the queue and return it. |
| 54 | 57 |
* Returns equivalent of zero pointer if queue is empty. |
| 55 | 58 |
*/ |
| 59 |
mb_message_sptr get_highest_pri_msg_nowait(); |
|
| 60 |
|
|
| 61 |
/* |
|
| 62 |
* \brief Delete highest pri message from the queue and return it. |
|
| 63 |
* If the queue is empty, this call blocks until it can return a message. |
|
| 64 |
*/ |
|
| 56 | 65 |
mb_message_sptr get_highest_pri_msg(); |
| 57 | 66 |
}; |
| 58 | 67 |
|
| b/mblock/src/lib/mb_port_simple.cc | ||
|---|---|---|
| 29 | 29 |
#include <mb_mblock.h> |
| 30 | 30 |
#include <mb_mblock_impl.h> |
| 31 | 31 |
#include <assert.h> |
| 32 |
#include <mbi_runtime_lock.h> |
|
| 32 | 33 |
|
| 33 | 34 |
|
| 34 | 35 |
mb_port_simple::mb_port_simple(mb_mblock *mblock, |
| ... | ... | |
| 49 | 50 |
mb_port_simple::send(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority) |
| 50 | 51 |
{
|
| 51 | 52 |
if (port_type() == mb_port::RELAY) // Can't send directly to a RELAY port |
| 52 |
throw mbe_invalid_port_type(mblock(), mblock()->fullname(), port_name());
|
|
| 53 |
throw mbe_invalid_port_type(mblock(), mblock()->instance_name(), port_name());
|
|
| 53 | 54 |
|
| 54 | 55 |
mb_msg_accepter_sptr accepter = find_accepter(this); |
| 55 | 56 |
if (accepter) |
| ... | ... | |
| 66 | 67 |
mb_endpoint peer_ep; |
| 67 | 68 |
mb_msg_accepter_sptr r; |
| 68 | 69 |
|
| 70 |
mbi_runtime_lock l(p->mblock()); |
|
| 71 |
|
|
| 69 | 72 |
// Set up initial context. |
| 70 | 73 |
|
| 71 | 74 |
switch(p->port_type()){
|
| b/mblock/src/lib/mb_runtime.cc | ||
|---|---|---|
| 24 | 24 |
#endif |
| 25 | 25 |
|
| 26 | 26 |
#include <mb_runtime.h> |
| 27 |
#include <mb_runtime_single_threaded.h>
|
|
| 27 |
#include <mb_runtime_thread_per_mblock.h>
|
|
| 28 | 28 |
|
| 29 | 29 |
mb_runtime_sptr |
| 30 | 30 |
mb_make_runtime() |
| 31 | 31 |
{
|
| 32 |
return mb_runtime_sptr(new mb_runtime_single_threaded());
|
|
| 32 |
return mb_runtime_sptr(new mb_runtime_thread_per_mblock());
|
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
mb_runtime::~mb_runtime() |
| b/mblock/src/lib/mb_runtime.h | ||
|---|---|---|
| 22 | 22 |
#define INCLUDED_MB_RUNTIME_H |
| 23 | 23 |
|
| 24 | 24 |
#include <mb_common.h> |
| 25 |
#include <omnithread.h> |
|
| 25 | 26 |
|
| 26 | 27 |
/*! |
| 27 | 28 |
* \brief Public constructor (factory) for mb_runtime objects. |
| ... | ... | |
| 33 | 34 |
* |
| 34 | 35 |
* There should generally be only a single instance of this class. |
| 35 | 36 |
*/ |
| 36 |
class mb_runtime : boost::noncopyable |
|
| 37 |
class mb_runtime : boost::noncopyable, |
|
| 38 |
public boost::enable_shared_from_this<mb_runtime> |
|
| 37 | 39 |
{
|
| 40 |
omni_mutex d_brl; // big runtime lock (avoid using this if possible...) |
|
| 41 |
|
|
| 38 | 42 |
public: |
| 39 | 43 |
mb_runtime(){}
|
| 40 | 44 |
virtual ~mb_runtime(); |
| ... | ... | |
| 49 | 53 |
* \returns true if the system ran successfully. |
| 50 | 54 |
*/ |
| 51 | 55 |
virtual bool run(mb_mblock_sptr top) = 0; |
| 56 |
|
|
| 57 |
|
|
| 58 |
// ---------------------------------------------------------------- |
|
| 59 |
// Stuff from here down is really private to the implementation... |
|
| 60 |
// ---------------------------------------------------------------- |
|
| 61 |
|
|
| 62 |
/*! |
|
| 63 |
* \brief lock the big runtime lock |
|
| 64 |
* \implementation |
|
| 65 |
*/ |
|
| 66 |
inline void lock() { d_brl.lock(); }
|
|
| 67 |
|
|
| 68 |
/*! |
|
| 69 |
* \brief unlock the big runtime lock |
|
| 70 |
* \implementation |
|
| 71 |
*/ |
|
| 72 |
inline void unlock() { d_brl.unlock(); }
|
|
| 73 |
|
|
| 52 | 74 |
}; |
| 53 | 75 |
|
| 54 | 76 |
#endif /* INCLUDED_MB_RUNTIME_H */ |
| b/mblock/src/lib/mb_runtime_nop.cc | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 2, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License along |
|
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 20 |
*/ |
|
| 21 |
|
|
| 22 |
#ifdef HAVE_CONFIG_H |
|
| 23 |
#include <config.h> |
|
| 24 |
#endif |
|
| 25 |
#include <mb_runtime_nop.h> |
|
| 26 |
#include <mb_mblock.h> |
|
| 27 |
|
|
| 28 |
mb_runtime_sptr |
|
| 29 |
mb_make_runtime_nop() |
|
| 30 |
{
|
|
| 31 |
return mb_runtime_sptr(new mb_runtime_nop()); |
|
| 32 |
} |
|
| 33 |
|
|
| 34 |
|
|
| 35 |
mb_runtime_nop::mb_runtime_nop() |
|
| 36 |
{
|
|
| 37 |
// nop for now |
|
| 38 |
} |
|
| 39 |
|
|
| 40 |
mb_runtime_nop::~mb_runtime_nop() |
|
| 41 |
{
|
|
| 42 |
// nop for now |
|
| 43 |
} |
|
| 44 |
|
|
| 45 |
bool |
|
| 46 |
mb_runtime_nop::run(mb_mblock_sptr top) |
|
| 47 |
{
|
|
| 48 |
class initial_visitor : public mb_visitor |
|
| 49 |
{
|
|
| 50 |
public: |
|
| 51 |
bool operator()(mb_mblock *mblock, const std::string &path) |
|
| 52 |
{
|
|
| 53 |
mblock->set_instance_name(path); |
|
| 54 |
mblock->init_fsm(); |
|
| 55 |
return true; |
|
| 56 |
} |
|
| 57 |
}; |
|
| 58 |
|
|
| 59 |
initial_visitor visitor; |
|
| 60 |
|
|
| 61 |
top->walk_tree(&visitor); |
|
| 62 |
|
|
| 63 |
return true; |
|
| 64 |
} |
|
| b/mblock/src/lib/mb_runtime_nop.h | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 2, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License along |
|
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 20 |
*/ |
|
| 21 |
#ifndef INCLUDED_MB_RUNTIME_NOP_H |
|
| 22 |
#define INCLUDED_MB_RUNTIME_NOP_H |
|
| 23 |
|
|
| 24 |
#include <mb_runtime.h> |
|
| 25 |
|
|
| 26 |
/*! |
|
| 27 |
* \brief Public constructor (factory) for mb_runtime_nop objects. |
|
| 28 |
*/ |
|
| 29 |
mb_runtime_sptr mb_make_runtime_nop(); |
|
| 30 |
|
|
| 31 |
/*! |
|
| 32 |
* \brief Concrete runtime that does nothing. Used only during early QA tests. |
|
| 33 |
*/ |
|
| 34 |
class mb_runtime_nop : public mb_runtime |
|
| 35 |
{
|
|
| 36 |
|
|
| 37 |
public: |
|
| 38 |
mb_runtime_nop(); |
|
| 39 |
~mb_runtime_nop(); |
|
| 40 |
|
|
| 41 |
bool run(mb_mblock_sptr top); |
|
| 42 |
}; |
|
| 43 |
|
|
| 44 |
#endif /* INCLUDED_MB_RUNTIME_NOP_H */ |
|
| b/mblock/src/lib/mb_runtime_placeholder.cc | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 2, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License along |
|
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 20 |
*/ |
|
| 21 |
|
|
| 22 |
#ifdef HAVE_CONFIG_H |
|
| 23 |
#include <config.h> |
|
| 24 |
#endif |
|
| 25 |
#include <mb_runtime_placeholder.h> |
|
| 26 |
#include <mb_mblock.h> |
|
| 27 |
#include <mb_exception.h> |
|
| 28 |
|
|
| 29 |
|
|
| 30 |
static mb_runtime *s_singleton = 0; |
|
| 31 |
|
|
| 32 |
|
|
| 33 |
mb_runtime_placeholder::mb_runtime_placeholder() |
|
| 34 |
{
|
|
| 35 |
// nop |
|
| 36 |
} |
|
| 37 |
|
|
| 38 |
mb_runtime_placeholder::~mb_runtime_placeholder() |
|
| 39 |
{
|
|
| 40 |
// nop |
|
| 41 |
} |
|
| 42 |
|
|
| 43 |
bool |
|
| 44 |
mb_runtime_placeholder::run(mb_mblock_sptr top) |
|
| 45 |
{
|
|
| 46 |
throw mbe_not_implemented(top.get(), "mb_runtime_placeholder::run"); |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
mb_runtime * |
|
| 50 |
mb_runtime_placeholder::singleton() |
|
| 51 |
{
|
|
| 52 |
if (s_singleton) |
|
| 53 |
return s_singleton; |
|
| 54 |
|
|
| 55 |
s_singleton = new mb_runtime_placeholder(); |
|
| 56 |
return s_singleton; |
|
| 57 |
} |
|
| b/mblock/src/lib/mb_runtime_placeholder.h | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 2, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License along |
|
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 20 |
*/ |
|
| 21 |
#ifndef INCLUDED_MB_RUNTIME_PLACEHOLDER_H |
|
| 22 |
#define INCLUDED_MB_RUNTIME_PLACEHOLDER_H |
|
| 23 |
|
|
| 24 |
#include <mb_runtime.h> |
|
| 25 |
|
|
| 26 |
/*! |
|
| 27 |
* \brief Concrete runtime that serves as a placeholder until the real |
|
| 28 |
* runtime is known. |
|
| 29 |
* |
|
| 30 |
* The singleton instance of this class is installed in the d_runtime |
|
| 31 |
* instance variable of each mb_mblock_impl at construction time. |
|
| 32 |
* Having a valid instance of runtime removes the "pre runtime::run" |
|
| 33 |
* corner case, and allows us to lock and unlock the big runtime lock |
|
| 34 |
* even though there's no "real runtime" yet. |
|
| 35 |
*/ |
|
| 36 |
class mb_runtime_placeholder : public mb_runtime |
|
| 37 |
{
|
|
| 38 |
|
|
| 39 |
public: |
|
| 40 |
mb_runtime_placeholder(); |
|
| 41 |
~mb_runtime_placeholder(); |
|
| 42 |
|
|
| 43 |
//! throws mbe_not_implemented |
|
| 44 |
bool run(mb_mblock_sptr top); |
|
| 45 |
|
|
| 46 |
//! Return the placeholder singleton |
|
| 47 |
static mb_runtime *singleton(); |
|
| 48 |
}; |
|
| 49 |
|
|
| 50 |
#endif /* INCLUDED_MB_RUNTIME_PLACEHOLDER_H */ |
|
| /dev/null | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 2, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License along |
|
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 20 |
*/ |
|
| 21 |
|
|
| 22 |
#ifdef HAVE_CONFIG_H |
|
| 23 |
#include <config.h> |
|
| 24 |
#endif |
|
| 25 |
#include <mb_runtime_single_threaded.h> |
|
| 26 |
#include <mb_mblock.h> |
|
| 27 |
|
|
| 28 |
|
|
| 29 |
mb_runtime_single_threaded::mb_runtime_single_threaded() |
|
| 30 |
{
|
|
| 31 |
// nop for now |
|
| 32 |
} |
|
| 33 |
|
|
| 34 |
mb_runtime_single_threaded::~mb_runtime_single_threaded() |
|
| 35 |
{
|
|
| 36 |
// nop for now |
|
| 37 |
} |
|
| 38 |
|
|
| 39 |
bool |
|
| 40 |
mb_runtime_single_threaded::run(mb_mblock_sptr top) |
|
| 41 |
{
|
|
| 42 |
class initial_visitor : public mb_visitor |
|
| 43 |
{
|
|
| 44 |
public: |
|
| 45 |
bool operator()(mb_mblock *mblock, const std::string &path) |
|
| 46 |
{
|
|
| 47 |
mblock->set_fullname(path); |
|
| 48 |
mblock->init_fsm(); |
|
| 49 |
return true; |
|
| 50 |
} |
|
| 51 |
}; |
|
| 52 |
|
|
| 53 |
initial_visitor visitor; |
|
| 54 |
|
|
| 55 |
d_top = top; // remember top of tree |
|
| 56 |
|
|
| 57 |
d_top->walk_tree(&visitor); |
|
| 58 |
|
|
| 59 |
return true; |
|
| 60 |
} |
|
| /dev/null | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 2, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License along |
|
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 20 |
*/ |
|
| 21 |
#ifndef INCLUDED_MB_RUNTIME_SINGLE_THREADED_H |
|
| 22 |
#define INCLUDED_MB_RUNTIME_SINGLE_THREADED_H |
|
| 23 |
|
|
| 24 |
#include <mb_runtime.h> |
|
| 25 |
|
|
| 26 |
/*! |
|
| 27 |
* \brief Concrete runtime that uses a single thread for all work. |
|
| 28 |
*/ |
|
| 29 |
class mb_runtime_single_threaded : public mb_runtime |
|
| 30 |
{
|
|
| 31 |
mb_mblock_sptr d_top; // top mblock |
|
| 32 |
|
|
| 33 |
public: |
|
| 34 |
mb_runtime_single_threaded(); |
|
| 35 |
~mb_runtime_single_threaded(); |
|
| 36 |
|
|
| 37 |
bool run(mb_mblock_sptr top); |
|
| 38 |
}; |
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
#endif /* INCLUDED_MB_RUNTIME_SINGLE_THREADED_H */ |
|
| b/mblock/src/lib/mb_runtime_thread_per_mblock.cc | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 2, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License along |
|
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 20 |
*/ |
|
| 21 |
|
|
| 22 |
#ifdef HAVE_CONFIG_H |
|
| 23 |
#include <config.h> |
|
| 24 |
#endif |
|
| 25 |
#include <mb_runtime_thread_per_mblock.h> |
|
| 26 |
#include <mb_mblock.h> |
|
| 27 |
#include <mb_mblock_impl.h> |
|
| 28 |
|
|
| 29 |
|
|
| 30 |
mb_runtime_thread_per_mblock::mb_runtime_thread_per_mblock() |
|
| 31 |
{
|
|
| 32 |
// nop for now |
|
| 33 |
} |
|
| 34 |
|
|
| 35 |
mb_runtime_thread_per_mblock::~mb_runtime_thread_per_mblock() |
|
| 36 |
{
|
|
| 37 |
// nop for now |
|
| 38 |
} |
|
| 39 |
|
|
| 40 |
bool |
|
| 41 |
mb_runtime_thread_per_mblock::run(mb_mblock_sptr top) |
|
| 42 |
{
|
|
| 43 |
class initial_visitor : public mb_visitor |
|
| 44 |
{
|
|
| 45 |
mb_runtime *d_rt; |
|
| 46 |
|
|
| 47 |
public: |
|
| 48 |
initial_visitor(mb_runtime *rt) : d_rt(rt) {}
|
|
| 49 |
bool operator()(mb_mblock *mblock, const std::string &path) |
|
| 50 |
{
|
|
| 51 |
mblock->impl()->set_runtime(d_rt); |
|
| 52 |
mblock->set_instance_name(path); |
|
| 53 |
mblock->init_fsm(); |
|
| 54 |
return true; |
|
| 55 |
} |
|
| 56 |
}; |
|
| 57 |
|
|
| 58 |
initial_visitor visitor(this); |
|
| 59 |
|
|
| 60 |
d_top = top; // remember top of tree |
|
| 61 |
|
|
| 62 |
d_top->walk_tree(&visitor); |
|
| 63 |
|
|
| 64 |
return true; |
|
| 65 |
} |
|
| b/mblock/src/lib/mb_runtime_thread_per_mblock.h | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 2, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License along |
|
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 20 |
*/ |
|
| 21 |
#ifndef INCLUDED_MB_RUNTIME_THREAD_PER_MBLOCK_H |
|
| 22 |
#define INCLUDED_MB_RUNTIME_THREAD_PER_MBLOCK_H |
|
| 23 |
|
|
| 24 |
#include <mb_runtime.h> |
|
| 25 |
|
|
| 26 |
/*! |
|
| 27 |
* \brief Concrete runtime that uses a single thread for all work. |
|
| 28 |
*/ |
|
| 29 |
class mb_runtime_thread_per_mblock : public mb_runtime |
|
| 30 |
{
|
|
| 31 |
mb_mblock_sptr d_top; // top mblock |
|
| 32 |
|
|
| 33 |
public: |
|
| 34 |
mb_runtime_thread_per_mblock(); |
|
| 35 |
~mb_runtime_thread_per_mblock(); |
|
| 36 |
|
|
| 37 |
bool run(mb_mblock_sptr top); |
|
| 38 |
}; |
|
| 39 |
|
|
| 40 |
#endif /* INCLUDED_MB_RUNTIME_THREAD_PER_MBLOCK_H */ |
|
| b/mblock/src/lib/mbi_runtime_lock.h | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 2, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License along |
|
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
|
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 20 |
*/ |
|
| 21 |
|
|
| 22 |
#ifndef INCLUDED_MBI_RUNTIME_LOCK_H |
|
| 23 |
#define INCLUDED_MBI_RUNTIME_LOCK_H |
|
| 24 |
|
|
| 25 |
#include <mb_runtime.h> |
|
| 26 |
#include <mb_mblock_impl.h> |
|
| 27 |
#include <boost/utility.hpp> |
|
| 28 |
|
|
| 29 |
/*! |
|
| 30 |
* \brief acquire and release big runtime lock |
|
| 31 |
* |
|
| 32 |
* As an alternative to: |
|
| 33 |
* {
|
|
| 34 |
* rt->lock(); |
|
| 35 |
* ..... |
|
| 36 |
* rt->unlock(); |
|
| 37 |
* } |
|
| 38 |
* |
|
| 39 |
* you can use a single instance of the mbi_runtime_lock class: |
|
| 40 |
* |
|
| 41 |
* {
|
|
| 42 |
* mbi_runtime_lock l(rt); |
|
| 43 |
* .... |
|
| 44 |
* } |
|
| 45 |
* |
|
| 46 |
* This has the advantage that rt->unlock() will be called automatically |
|
| 47 |
* when an exception is thrown. |
|
| 48 |
*/ |
|
| 49 |
|
|
| 50 |
class mbi_runtime_lock : boost::noncopyable {
|
|
| 51 |
mb_runtime *d_rt; |
|
| 52 |
public: |
|
| 53 |
mbi_runtime_lock(mb_runtime *rt) : d_rt(rt) { d_rt->lock(); }
|
|
| 54 |
mbi_runtime_lock(mb_mblock_impl *mi) : d_rt(mi->runtime()) { d_rt->lock(); }
|
|
| 55 |
mbi_runtime_lock(mb_mblock *mb) : d_rt(mb->impl()->runtime()) { d_rt->lock(); }
|
|
| 56 |
~mbi_runtime_lock(void) { d_rt->unlock(); }
|
|
| 57 |
|
|
| 58 |
}; |
|
| 59 |
|
|
| 60 |
#endif /* INCLUDED_MBI_RUNTIME_LOCK_H */ |
|
| 61 |
|
|
| b/mblock/src/lib/qa_mblock_prims.cc | ||
|---|---|---|
| 95 | 95 |
void |
| 96 | 96 |
qa_mblock_prims::test_define_ports() |
| 97 | 97 |
{
|
| 98 |
mb_runtime_sptr rt = mb_make_runtime(); |
|
| 99 | 98 |
// std::vector<mb_port_sptr> intf; |
| 100 | 99 |
|
| 101 | 100 |
mb_mblock_sptr mb1 = mb_mblock_sptr(new dp_1()); |
| ... | ... | |
| 175 | 174 |
void |
| 176 | 175 |
qa_mblock_prims::test_define_components() |
| 177 | 176 |
{
|
| 178 |
mb_runtime_sptr rt = mb_make_runtime(); |
|
| 179 | 177 |
mb_mblock_sptr mb1 = mb_mblock_sptr(new dc_ok()); // OK |
| 180 | 178 |
|
| 181 | 179 |
// raises pmt_exception because of duplicate component definition of "c0" |
| ... | ... | |
| 317 | 315 |
pmt_list1(pmt_intern("in")), // in
|
| 318 | 316 |
pmt_list1(pmt_intern("out"))); // out
|
| 319 | 317 |
|
| 320 |
|
|
| 321 |
mb_runtime_sptr rt = mb_make_runtime(); |
|
| 322 | 318 |
mb_mblock_sptr mb0 = mb_mblock_sptr(new tc_0()); |
| 323 | 319 |
} |
| 324 | 320 |
|
| ... | ... | |
| 330 | 326 |
mb_msg_queue q; |
| 331 | 327 |
|
| 332 | 328 |
// check initial state |
| 333 |
CPPUNIT_ASSERT(q.get_highest_pri_msg() == 0); |
|
| 329 |
CPPUNIT_ASSERT(q.get_highest_pri_msg_nowait() == 0);
|
|
| 334 | 330 |
|
| 335 | 331 |
CPPUNIT_ASSERT(MB_NPRI >= 5); // sanity check for this test |
| 336 | 332 |
|
| ... | ... | |
| 340 | 336 |
q.insert(mb_make_message(PMT_NIL, pmt_from_long(1), PMT_NIL, MB_PRI_BEST + 2)); |
| 341 | 337 |
q.insert(mb_make_message(PMT_NIL, pmt_from_long(2), PMT_NIL, MB_PRI_BEST + 2)); |
| 342 | 338 |
|
| 343 |
CPPUNIT_ASSERT_EQUAL(0L, pmt_to_long(q.get_highest_pri_msg()->data())); |
|
| 344 |
CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(q.get_highest_pri_msg()->data())); |
|
| 345 |
CPPUNIT_ASSERT_EQUAL(2L, pmt_to_long(q.get_highest_pri_msg()->data())); |
|
| 339 |
CPPUNIT_ASSERT_EQUAL(0L, pmt_to_long(q.get_highest_pri_msg_nowait()->data()));
|
|
| 340 |
CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(q.get_highest_pri_msg_nowait()->data()));
|
|
| 341 |
CPPUNIT_ASSERT_EQUAL(2L, pmt_to_long(q.get_highest_pri_msg_nowait()->data()));
|
|
| 346 | 342 |
|
| 347 |
CPPUNIT_ASSERT(q.get_highest_pri_msg() == 0); |
|
| 343 |
CPPUNIT_ASSERT(q.get_highest_pri_msg_nowait() == 0);
|
|
| 348 | 344 |
|
| 349 | 345 |
|
| 350 | 346 |
// insert messages of different priorities in pseudo-random order |
| ... | ... | |
| 361 | 357 |
q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 1)); |
| 362 | 358 |
|
| 363 | 359 |
// confirm that they come out in order |
| 364 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 0, q.get_highest_pri_msg()->priority()); |
|
| 365 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 0, q.get_highest_pri_msg()->priority()); |
|
| 366 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 1, q.get_highest_pri_msg()->priority()); |
|
| 367 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 1, q.get_highest_pri_msg()->priority()); |
|
| 368 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 2, q.get_highest_pri_msg()->priority()); |
|
| 369 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 2, q.get_highest_pri_msg()->priority()); |
|
| 370 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 3, q.get_highest_pri_msg()->priority()); |
|
| 371 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 3, q.get_highest_pri_msg()->priority()); |
|
| 372 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 4, q.get_highest_pri_msg()->priority()); |
|
| 373 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 4, q.get_highest_pri_msg()->priority()); |
|
| 360 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 0, q.get_highest_pri_msg_nowait()->priority());
|
|
| 361 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 0, q.get_highest_pri_msg_nowait()->priority());
|
|
| 362 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 1, q.get_highest_pri_msg_nowait()->priority());
|
|
| 363 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 1, q.get_highest_pri_msg_nowait()->priority());
|
|
| 364 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 2, q.get_highest_pri_msg_nowait()->priority());
|
|
| 365 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 2, q.get_highest_pri_msg_nowait()->priority());
|
|
| 366 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 3, q.get_highest_pri_msg_nowait()->priority());
|
|
| 367 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 3, q.get_highest_pri_msg_nowait()->priority());
|
|
| 368 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 4, q.get_highest_pri_msg_nowait()->priority());
|
|
| 369 |
CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 4, q.get_highest_pri_msg_nowait()->priority());
|
|
| 374 | 370 |
|
| 375 | 371 |
// check final state |
| 376 |
CPPUNIT_ASSERT(q.get_highest_pri_msg() == 0); |
|
| 372 |
CPPUNIT_ASSERT(q.get_highest_pri_msg_nowait() == 0);
|
|
| 377 | 373 |
} |
| 378 | 374 |
|
| 379 | 375 |
//////////////////////////////////////////////////////////////// |
| ... | ... | |
| 397 | 393 |
|
| 398 | 394 |
pmt_t cs = pmt_intern("cs");
|
| 399 | 395 |
|
| 400 |
mb_message_sptr msg = mb->impl()->msgq().get_highest_pri_msg(); |
|
| 396 |
mb_message_sptr msg = mb->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 401 | 397 |
CPPUNIT_ASSERT(pmt_eq(cs, msg->port_id())); // confirm that port_id is set |
| 402 | 398 |
CPPUNIT_ASSERT_EQUAL(0L, pmt_to_long(msg->data())); // and that data is correct |
| 403 | 399 |
|
| 404 |
CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(mb->impl()->msgq().get_highest_pri_msg()->data())); |
|
| 405 |
CPPUNIT_ASSERT_EQUAL(2L, pmt_to_long(mb->impl()->msgq().get_highest_pri_msg()->data())); |
|
| 400 |
CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(mb->impl()->msgq().get_highest_pri_msg_nowait()->data()));
|
|
| 401 |
CPPUNIT_ASSERT_EQUAL(2L, pmt_to_long(mb->impl()->msgq().get_highest_pri_msg_nowait()->data()));
|
|
| 406 | 402 |
} |
| b/mblock/src/lib/qa_mblock_send.cc | ||
|---|---|---|
| 28 | 28 |
#include <cppunit/TestAssert.h> |
| 29 | 29 |
#include <mb_mblock.h> |
| 30 | 30 |
#include <mb_runtime.h> |
| 31 |
#include <mb_runtime_nop.h> // QA only |
|
| 31 | 32 |
#include <mb_protocol_class.h> |
| 32 | 33 |
#include <mb_exception.h> |
| 33 | 34 |
#include <mb_msg_queue.h> |
| ... | ... | |
| 86 | 87 |
void |
| 87 | 88 |
sr1::init_fsm() |
| 88 | 89 |
{
|
| 89 |
// std::cout << fullname() << "[sr1]: init_fsm\n";
|
|
| 90 |
// std::cout << instance_name() << "[sr1]: init_fsm\n";
|
|
| 90 | 91 |
|
| 91 | 92 |
// send two messages to each port |
| 92 |
pmt_t our_name = pmt_intern(fullname());
|
|
| 93 |
pmt_t our_name = pmt_intern(instance_name());
|
|
| 93 | 94 |
d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(0))); |
| 94 | 95 |
d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(1))); |
| 95 | 96 |
|
| ... | ... | |
| 127 | 128 |
void |
| 128 | 129 |
sr0::init_fsm() |
| 129 | 130 |
{
|
| 130 |
// std::cout << fullname() << "[sr0]: init_fsm\n";
|
|
| 131 |
// std::cout << instance_name() << "[sr0]: init_fsm\n";
|
|
| 131 | 132 |
|
| 132 | 133 |
// send two messages to p0 |
| 133 |
pmt_t our_name = pmt_intern(fullname());
|
|
| 134 |
pmt_t our_name = pmt_intern(instance_name());
|
|
| 134 | 135 |
d_p0->send(s_control, pmt_list3(our_name, s_p0, pmt_from_long(0))); |
| 135 | 136 |
d_p0->send(s_control, pmt_list3(our_name, s_p0, pmt_from_long(1))); |
| 136 | 137 |
} |
| ... | ... | |
| 149 | 150 |
|
| 150 | 151 |
mb_message_sptr msg; |
| 151 | 152 |
|
| 152 |
mb_runtime_sptr rt = mb_make_runtime(); |
|
| 153 |
mb_runtime_sptr rt = mb_make_runtime_nop();
|
|
| 153 | 154 |
mb_mblock_sptr mb0 = mb_mblock_sptr(new sr0()); |
| 154 | 155 |
rt->run(mb0); |
| 155 | 156 |
|
| 156 | 157 |
// Reach into the guts and see if the messages ended up where they should have |
| 157 | 158 |
|
| 158 | 159 |
// mb0 should have received two messages sent from mb1 via its p1 |
| 159 |
msg = mb0->impl()->msgq().get_highest_pri_msg(); |
|
| 160 |
msg = mb0->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 160 | 161 |
CPPUNIT_ASSERT(msg); |
| 161 | 162 |
// std::cerr << msg->data() << std::endl; |
| 162 | 163 |
CPPUNIT_ASSERT_EQUAL(s_p0, msg->port_id()); |
| 163 | 164 |
CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p1, pmt_from_long(0)),
|
| 164 | 165 |
msg->data())); |
| 165 | 166 |
|
| 166 |
msg = mb0->impl()->msgq().get_highest_pri_msg(); |
|
| 167 |
msg = mb0->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 167 | 168 |
CPPUNIT_ASSERT(msg); |
| 168 | 169 |
// std::cerr << msg->data() << std::endl; |
| 169 | 170 |
CPPUNIT_ASSERT_EQUAL(s_p0, msg->port_id()); |
| ... | ... | |
| 176 | 177 |
|
| 177 | 178 |
mb_mblock_sptr mb1 = mb0->impl()->component("mb1");
|
| 178 | 179 |
|
| 179 |
msg = mb1->impl()->msgq().get_highest_pri_msg(); |
|
| 180 |
msg = mb1->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 180 | 181 |
CPPUNIT_ASSERT(msg); |
| 181 | 182 |
// std::cerr << msg->data() << std::endl; |
| 182 | 183 |
CPPUNIT_ASSERT_EQUAL(s_p1, msg->port_id()); |
| 183 | 184 |
CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top"), s_p0, pmt_from_long(0)),
|
| 184 | 185 |
msg->data())); |
| 185 | 186 |
|
| 186 |
msg = mb1->impl()->msgq().get_highest_pri_msg(); |
|
| 187 |
msg = mb1->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 187 | 188 |
CPPUNIT_ASSERT(msg); |
| 188 | 189 |
// std::cerr << msg->data() << std::endl; |
| 189 | 190 |
CPPUNIT_ASSERT_EQUAL(s_p1, msg->port_id()); |
| 190 | 191 |
CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top"), s_p0, pmt_from_long(1)),
|
| 191 | 192 |
msg->data())); |
| 192 | 193 |
|
| 193 |
msg = mb1->impl()->msgq().get_highest_pri_msg(); |
|
| 194 |
msg = mb1->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 194 | 195 |
CPPUNIT_ASSERT(msg); |
| 195 | 196 |
// std::cerr << msg->data() << std::endl; |
| 196 | 197 |
CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); |
| 197 | 198 |
CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb2"), s_p2, pmt_from_long(0)),
|
| 198 | 199 |
msg->data())); |
| 199 | 200 |
|
| 200 |
msg = mb1->impl()->msgq().get_highest_pri_msg(); |
|
| 201 |
msg = mb1->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 201 | 202 |
CPPUNIT_ASSERT(msg); |
| 202 | 203 |
// std::cerr << msg->data() << std::endl; |
| 203 | 204 |
CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); |
| ... | ... | |
| 210 | 211 |
|
| 211 | 212 |
mb_mblock_sptr mb2 = mb0->impl()->component("mb2");
|
| 212 | 213 |
|
| 213 |
msg = mb2->impl()->msgq().get_highest_pri_msg(); |
|
| 214 |
msg = mb2->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 214 | 215 |
CPPUNIT_ASSERT(msg); |
| 215 | 216 |
// std::cerr << msg->data() << std::endl; |
| 216 | 217 |
CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); |
| 217 | 218 |
CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p2, pmt_from_long(0)),
|
| 218 | 219 |
msg->data())); |
| 219 | 220 |
|
| 220 |
msg = mb2->impl()->msgq().get_highest_pri_msg(); |
|
| 221 |
msg = mb2->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 221 | 222 |
CPPUNIT_ASSERT(msg); |
| 222 | 223 |
// std::cerr << msg->data() << std::endl; |
| 223 | 224 |
CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); |
| ... | ... | |
| 253 | 254 |
void |
| 254 | 255 |
rr2::init_fsm() |
| 255 | 256 |
{
|
| 256 |
// std::cout << fullname() << "[rr2]: init_fsm\n";
|
|
| 257 |
// std::cout << instance_name() << "[rr2]: init_fsm\n";
|
|
| 257 | 258 |
|
| 258 | 259 |
// send two messages via p1 |
| 259 |
pmt_t our_name = pmt_intern(fullname());
|
|
| 260 |
pmt_t our_name = pmt_intern(instance_name());
|
|
| 260 | 261 |
d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(0))); |
| 261 | 262 |
d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(1))); |
| 262 | 263 |
} |
| ... | ... | |
| 321 | 322 |
{
|
| 322 | 323 |
mb_message_sptr msg; |
| 323 | 324 |
|
| 324 |
mb_runtime_sptr rt = mb_make_runtime(); |
|
| 325 |
mb_runtime_sptr rt = mb_make_runtime_nop();
|
|
| 325 | 326 |
mb_mblock_sptr top = mb_mblock_sptr(new rr0_a()); |
| 326 | 327 |
rt->run(top); |
| 327 | 328 |
|
| ... | ... | |
| 335 | 336 |
// c0c0 should have received |
| 336 | 337 |
// two message from c1 via its p2 |
| 337 | 338 |
|
| 338 |
msg = c0c0->impl()->msgq().get_highest_pri_msg(); |
|
| 339 |
msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 339 | 340 |
CPPUNIT_ASSERT(msg); |
| 340 | 341 |
//std::cerr << msg->data() << std::endl; |
| 341 | 342 |
CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); |
| 342 | 343 |
CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1"), s_p1, pmt_from_long(0)),
|
| 343 | 344 |
msg->data())); |
| 344 | 345 |
|
| 345 |
msg = c0c0->impl()->msgq().get_highest_pri_msg(); |
|
| 346 |
msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 346 | 347 |
CPPUNIT_ASSERT(msg); |
| 347 | 348 |
//std::cerr << msg->data() << std::endl; |
| 348 | 349 |
CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); |
| ... | ... | |
| 352 | 353 |
// c1 should have received |
| 353 | 354 |
// two message from c0c0 via its p2 |
| 354 | 355 |
|
| 355 |
msg = c1->impl()->msgq().get_highest_pri_msg(); |
|
| 356 |
msg = c1->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 356 | 357 |
CPPUNIT_ASSERT(msg); |
| 357 | 358 |
//std::cerr << msg->data() << std::endl; |
| 358 | 359 |
CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); |
| 359 | 360 |
CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(0)),
|
| 360 | 361 |
msg->data())); |
| 361 | 362 |
|
| 362 |
msg = c1->impl()->msgq().get_highest_pri_msg(); |
|
| 363 |
msg = c1->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 363 | 364 |
CPPUNIT_ASSERT(msg); |
| 364 | 365 |
//std::cerr << msg->data() << std::endl; |
| 365 | 366 |
CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); |
| ... | ... | |
| 402 | 403 |
{
|
| 403 | 404 |
mb_message_sptr msg; |
| 404 | 405 |
|
| 405 |
mb_runtime_sptr rt = mb_make_runtime(); |
|
| 406 |
mb_runtime_sptr rt = mb_make_runtime_nop();
|
|
| 406 | 407 |
mb_mblock_sptr top = mb_mblock_sptr(new rr0_b()); |
| 407 | 408 |
rt->run(top); |
| 408 | 409 |
|
| ... | ... | |
| 417 | 418 |
// c0c0 should have received |
| 418 | 419 |
// two message from c1c0 via its p2 |
| 419 | 420 |
|
| 420 |
msg = c0c0->impl()->msgq().get_highest_pri_msg(); |
|
| 421 |
msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 421 | 422 |
CPPUNIT_ASSERT(msg); |
| 422 | 423 |
// std::cerr << msg->data() << std::endl; |
| 423 | 424 |
CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); |
| 424 | 425 |
CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1/c0"), s_p1, pmt_from_long(0)),
|
| 425 | 426 |
msg->data())); |
| 426 | 427 |
|
| 427 |
msg = c0c0->impl()->msgq().get_highest_pri_msg(); |
|
| 428 |
msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 428 | 429 |
CPPUNIT_ASSERT(msg); |
| 429 | 430 |
// std::cerr << msg->data() << std::endl; |
| 430 | 431 |
CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); |
| ... | ... | |
| 434 | 435 |
// c1c0 should have received |
| 435 | 436 |
// two message from c0c0 via its p2 |
| 436 | 437 |
|
| 437 |
msg = c1c0->impl()->msgq().get_highest_pri_msg(); |
|
| 438 |
msg = c1c0->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 438 | 439 |
CPPUNIT_ASSERT(msg); |
| 439 | 440 |
// std::cerr << msg->data() << std::endl; |
| 440 | 441 |
CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); |
| 441 | 442 |
CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(0)),
|
| 442 | 443 |
msg->data())); |
| 443 | 444 |
|
| 444 |
msg = c1c0->impl()->msgq().get_highest_pri_msg(); |
|
| 445 |
msg = c1c0->impl()->msgq().get_highest_pri_msg_nowait();
|
|
| 445 | 446 |
CPPUNIT_ASSERT(msg); |
| 446 | 447 |
// std::cerr << msg->data() << std::endl; |
| 447 | 448 |
CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); |
Also available in: Unified diff