summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib/top_block_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-runtime/lib/top_block_impl.cc')
-rw-r--r--gnuradio-runtime/lib/top_block_impl.cc260
1 files changed, 121 insertions, 139 deletions
diff --git a/gnuradio-runtime/lib/top_block_impl.cc b/gnuradio-runtime/lib/top_block_impl.cc
index d2a07e89ef..70b1e3e87c 100644
--- a/gnuradio-runtime/lib/top_block_impl.cc
+++ b/gnuradio-runtime/lib/top_block_impl.cc
@@ -40,68 +40,66 @@ namespace gr {
#define GR_TOP_BLOCK_IMPL_DEBUG 0
- typedef scheduler_sptr(*scheduler_maker)(flat_flowgraph_sptr ffg,
- int max_noutput_items);
+typedef scheduler_sptr (*scheduler_maker)(flat_flowgraph_sptr ffg, int max_noutput_items);
- static struct scheduler_table {
- const char *name;
+static struct scheduler_table {
+ const char* name;
scheduler_maker f;
- } scheduler_table[] = {
- { "TPB", scheduler_tpb::make } // first entry is default
- };
+} scheduler_table[] = {
+ { "TPB", scheduler_tpb::make } // first entry is default
+};
- static scheduler_sptr
- make_scheduler(flat_flowgraph_sptr ffg, int max_noutput_items)
- {
+static scheduler_sptr make_scheduler(flat_flowgraph_sptr ffg, int max_noutput_items)
+{
static scheduler_maker factory = 0;
- if(factory == 0) {
- char *v = getenv("GR_SCHEDULER");
- if(!v)
- factory = scheduler_table[0].f; // use default
- else {
- for(size_t i = 0; i < sizeof(scheduler_table)/sizeof(scheduler_table[0]); i++) {
- if(strcmp(v, scheduler_table[i].name) == 0) {
- factory = scheduler_table[i].f;
- break;
- }
+ if (factory == 0) {
+ char* v = getenv("GR_SCHEDULER");
+ if (!v)
+ factory = scheduler_table[0].f; // use default
+ else {
+ for (size_t i = 0; i < sizeof(scheduler_table) / sizeof(scheduler_table[0]);
+ i++) {
+ if (strcmp(v, scheduler_table[i].name) == 0) {
+ factory = scheduler_table[i].f;
+ break;
+ }
+ }
+ if (factory == 0) {
+ std::cerr << "warning: Invalid GR_SCHEDULER environment variable value \""
+ << v << "\". Using \"" << scheduler_table[0].name << "\"\n";
+ factory = scheduler_table[0].f;
+ }
}
- if(factory == 0) {
- std::cerr << "warning: Invalid GR_SCHEDULER environment variable value \""
- << v << "\". Using \"" << scheduler_table[0].name << "\"\n";
- factory = scheduler_table[0].f;
- }
- }
}
return factory(ffg, max_noutput_items);
- }
+}
- top_block_impl::top_block_impl(top_block *owner)
- : d_owner(owner), d_ffg(),
- d_state(IDLE), d_lock_count(0), d_retry_wait(false)
- {
- }
+top_block_impl::top_block_impl(top_block* owner)
+ : d_owner(owner), d_ffg(), d_state(IDLE), d_lock_count(0), d_retry_wait(false)
+{
+}
- top_block_impl::~top_block_impl()
- {
+top_block_impl::~top_block_impl()
+{
if (d_lock_count) {
- std::cerr << "error: destroying locked block." << std::endl;
+ std::cerr << "error: destroying locked block." << std::endl;
}
d_owner = 0;
- }
+}
- void
- top_block_impl::start(int max_noutput_items)
- {
+void top_block_impl::start(int max_noutput_items)
+{
gr::thread::scoped_lock l(d_mutex);
d_max_noutput_items = max_noutput_items;
- if(d_state != IDLE)
- throw std::runtime_error("top_block::start: top block already running or wait() not called after previous stop()");
+ if (d_state != IDLE)
+ throw std::runtime_error("top_block::start: top block already running or wait() "
+ "not called after previous stop()");
- if(d_lock_count > 0)
- throw std::runtime_error("top_block::start: can't start with flow graph locked");
+ if (d_lock_count > 0)
+ throw std::runtime_error("top_block::start: can't start with flow graph locked");
// Create new flat flow graph by flattening hierarchy
d_ffg = d_owner->flatten();
@@ -112,135 +110,119 @@ namespace gr {
// Only export perf. counters if ControlPort config param is
// enabled and if the PerfCounter option 'export' is turned on.
- prefs *p = prefs::singleton();
- if(p->get_bool("ControlPort", "on", false) && p->get_bool("PerfCounters", "export", false))
- d_ffg->enable_pc_rpc();
+ prefs* p = prefs::singleton();
+ if (p->get_bool("ControlPort", "on", false) &&
+ p->get_bool("PerfCounters", "export", false))
+ d_ffg->enable_pc_rpc();
d_scheduler = make_scheduler(d_ffg, d_max_noutput_items);
d_state = RUNNING;
- }
+}
- void
- top_block_impl::stop()
- {
+void top_block_impl::stop()
+{
gr::thread::scoped_lock lock(d_mutex);
- if(d_scheduler)
- d_scheduler->stop();
+ if (d_scheduler)
+ d_scheduler->stop();
d_state = IDLE;
- }
+}
- void
- top_block_impl::wait()
- {
+void top_block_impl::wait()
+{
do {
- wait_for_jobs();
- {
- gr::thread::scoped_lock lock(d_mutex);
- if (!d_lock_count) {
- if(d_retry_wait) {
- d_retry_wait = false;
- continue;
- }
- d_state = IDLE;
- break;
+ wait_for_jobs();
+ {
+ gr::thread::scoped_lock lock(d_mutex);
+ if (!d_lock_count) {
+ if (d_retry_wait) {
+ d_retry_wait = false;
+ continue;
+ }
+ d_state = IDLE;
+ break;
+ }
+ d_lock_cond.wait(lock);
}
- d_lock_cond.wait(lock);
- }
- } while(true);
- }
-
- void
- top_block_impl::wait_for_jobs()
- {
- if(d_scheduler)
- d_scheduler->wait();
- }
-
- // N.B. lock() and unlock() cannot be called from a flow graph
- // thread or deadlock will occur when reconfiguration happens
- void
- top_block_impl::lock()
- {
+ } while (true);
+}
+
+void top_block_impl::wait_for_jobs()
+{
+ if (d_scheduler)
+ d_scheduler->wait();
+}
+
+// N.B. lock() and unlock() cannot be called from a flow graph
+// thread or deadlock will occur when reconfiguration happens
+void top_block_impl::lock()
+{
gr::thread::scoped_lock lock(d_mutex);
- if(d_scheduler)
- d_scheduler->stop();
+ if (d_scheduler)
+ d_scheduler->stop();
d_lock_count++;
- }
+}
- void
- top_block_impl::unlock()
- {
+void top_block_impl::unlock()
+{
gr::thread::scoped_lock lock(d_mutex);
- if(d_lock_count <= 0) {
- d_lock_count = 0; // fix it, then complain
- throw std::runtime_error("unpaired unlock() call");
+ if (d_lock_count <= 0) {
+ d_lock_count = 0; // fix it, then complain
+ throw std::runtime_error("unpaired unlock() call");
}
d_lock_count--;
- if(d_lock_count > 0 || d_state == IDLE) // nothing to do
- return;
+ if (d_lock_count > 0 || d_state == IDLE) // nothing to do
+ return;
restart();
d_lock_cond.notify_all();
- }
-
- /*
- * restart is called with d_mutex held
- */
- void
- top_block_impl::restart()
- {
+}
+
+/*
+ * restart is called with d_mutex held
+ */
+void top_block_impl::restart()
+{
wait_for_jobs();
// Create new simple flow graph
flat_flowgraph_sptr new_ffg = d_owner->flatten();
- new_ffg->validate(); // check consistency, sanity, etc
- new_ffg->merge_connections(d_ffg); // reuse buffers, etc
+ new_ffg->validate(); // check consistency, sanity, etc
+ new_ffg->merge_connections(d_ffg); // reuse buffers, etc
d_ffg = new_ffg;
// Create a new scheduler to execute it
d_scheduler = make_scheduler(d_ffg, d_max_noutput_items);
d_retry_wait = true;
- }
+}
- std::string
- top_block_impl::edge_list()
- {
- if(d_ffg)
- return d_ffg->edge_list();
+std::string top_block_impl::edge_list()
+{
+ if (d_ffg)
+ return d_ffg->edge_list();
else
- return "";
- }
-
- std::string
- top_block_impl::msg_edge_list()
- {
- if(d_ffg)
- return d_ffg->msg_edge_list();
+ return "";
+}
+
+std::string top_block_impl::msg_edge_list()
+{
+ if (d_ffg)
+ return d_ffg->msg_edge_list();
else
- return "";
- }
-
- void
- top_block_impl::dump()
- {
- if(d_ffg)
- d_ffg->dump();
- }
-
- int
- top_block_impl::max_noutput_items()
- {
- return d_max_noutput_items;
- }
-
- void
- top_block_impl::set_max_noutput_items(int nmax)
- {
- d_max_noutput_items = nmax;
- }
+ return "";
+}
+
+void top_block_impl::dump()
+{
+ if (d_ffg)
+ d_ffg->dump();
+}
+
+int top_block_impl::max_noutput_items() { return d_max_noutput_items; }
+
+void top_block_impl::set_max_noutput_items(int nmax) { d_max_noutput_items = nmax; }
} /* namespace gr */