diff options
author | Scott Torborg <storborg@gmail.com> | 2018-07-14 18:56:50 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2020-01-05 16:07:47 -0800 |
commit | b0a26eeb4d8a4e0233f30e7137ec4c13391ca2b1 (patch) | |
tree | 625ceabd8dbd7f5e5061309ce6e7a3fe543f1181 /gnuradio-runtime/lib | |
parent | 0c579fba83d55e2ee4acc8362a1be2beae86ad56 (diff) |
Add a top_block parameter to control exception handling
This restores past behavior where the scheduler catches exceptions
raised in block threads, allowing flowgraphs to continue running after
the failure of an individual block. It also adds optional new behavior,
selected by setting catch_exceptions=False to the top block, which causes
exceptions to not be caught. In this mode of operation, a std::terminate
handler can be installed to print a stack trace before the flowgraph exits.
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r-- | gnuradio-runtime/lib/scheduler.cc | 6 | ||||
-rw-r--r-- | gnuradio-runtime/lib/scheduler.h | 2 | ||||
-rw-r--r-- | gnuradio-runtime/lib/scheduler_tpb.cc | 15 | ||||
-rw-r--r-- | gnuradio-runtime/lib/scheduler_tpb.h | 6 | ||||
-rw-r--r-- | gnuradio-runtime/lib/top_block.cc | 8 | ||||
-rw-r--r-- | gnuradio-runtime/lib/top_block_impl.cc | 22 | ||||
-rw-r--r-- | gnuradio-runtime/lib/top_block_impl.h | 3 |
7 files changed, 41 insertions, 21 deletions
diff --git a/gnuradio-runtime/lib/scheduler.cc b/gnuradio-runtime/lib/scheduler.cc index f054e4c753..b0e1f67dff 100644 --- a/gnuradio-runtime/lib/scheduler.cc +++ b/gnuradio-runtime/lib/scheduler.cc @@ -27,7 +27,11 @@ namespace gr { -scheduler::scheduler(flat_flowgraph_sptr ffg, int max_noutput_items) {} +scheduler::scheduler(flat_flowgraph_sptr ffg, + int max_noutput_items, + bool catch_exceptions) +{ +} scheduler::~scheduler() {} diff --git a/gnuradio-runtime/lib/scheduler.h b/gnuradio-runtime/lib/scheduler.h index 8041771f3c..e76b2ac005 100644 --- a/gnuradio-runtime/lib/scheduler.h +++ b/gnuradio-runtime/lib/scheduler.h @@ -48,7 +48,7 @@ public: * The scheduler will continue running until all blocks * report that they are done or the stop method is called. */ - scheduler(flat_flowgraph_sptr ffg, int max_noutput_items); + scheduler(flat_flowgraph_sptr ffg, int max_noutput_items, bool catch_exceptions); virtual ~scheduler(); diff --git a/gnuradio-runtime/lib/scheduler_tpb.cc b/gnuradio-runtime/lib/scheduler_tpb.cc index a255aa4946..7e240d7f61 100644 --- a/gnuradio-runtime/lib/scheduler_tpb.cc +++ b/gnuradio-runtime/lib/scheduler_tpb.cc @@ -51,13 +51,16 @@ public: } }; -scheduler_sptr scheduler_tpb::make(flat_flowgraph_sptr ffg, int max_noutput_items) +scheduler_sptr +scheduler_tpb::make(flat_flowgraph_sptr ffg, int max_noutput_items, bool catch_exceptions) { - return scheduler_sptr(new scheduler_tpb(ffg, max_noutput_items)); + return scheduler_sptr(new scheduler_tpb(ffg, max_noutput_items, catch_exceptions)); } -scheduler_tpb::scheduler_tpb(flat_flowgraph_sptr ffg, int max_noutput_items) - : scheduler(ffg, max_noutput_items) +scheduler_tpb::scheduler_tpb(flat_flowgraph_sptr ffg, + int max_noutput_items, + bool catch_exceptions) + : scheduler(ffg, max_noutput_items, catch_exceptions) { int block_max_noutput_items; @@ -91,7 +94,9 @@ scheduler_tpb::scheduler_tpb(flat_flowgraph_sptr ffg, int max_noutput_items) block_max_noutput_items = max_noutput_items; } d_threads.create_thread(thread::thread_body_wrapper<tpb_container>( - tpb_container(blocks[i], block_max_noutput_items, start_sync), name.str())); + tpb_container(blocks[i], block_max_noutput_items, start_sync), + name.str(), + catch_exceptions)); } start_sync->wait(); } diff --git a/gnuradio-runtime/lib/scheduler_tpb.h b/gnuradio-runtime/lib/scheduler_tpb.h index 152b11c8f3..35e8c557da 100644 --- a/gnuradio-runtime/lib/scheduler_tpb.h +++ b/gnuradio-runtime/lib/scheduler_tpb.h @@ -42,10 +42,12 @@ protected: * The scheduler will continue running until all blocks until they * report that they are done or the stop method is called. */ - scheduler_tpb(flat_flowgraph_sptr ffg, int max_noutput_items); + scheduler_tpb(flat_flowgraph_sptr ffg, int max_noutput_items, bool catch_exceptions); public: - static scheduler_sptr make(flat_flowgraph_sptr ffg, int max_noutput_items = 100000); + static scheduler_sptr make(flat_flowgraph_sptr ffg, + int max_noutput_items = 100000, + bool catch_exceptions = true); ~scheduler_tpb(); diff --git a/gnuradio-runtime/lib/top_block.cc b/gnuradio-runtime/lib/top_block.cc index 7485124bac..3e81d71951 100644 --- a/gnuradio-runtime/lib/top_block.cc +++ b/gnuradio-runtime/lib/top_block.cc @@ -33,15 +33,15 @@ #include <iostream> namespace gr { -top_block_sptr make_top_block(const std::string& name) +top_block_sptr make_top_block(const std::string& name, bool catch_exceptions) { - return gnuradio::get_initial_sptr(new top_block(name)); + return gnuradio::get_initial_sptr(new top_block(name, catch_exceptions)); } -top_block::top_block(const std::string& name) +top_block::top_block(const std::string& name, bool catch_exceptions) : hier_block2(name, io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)) { - d_impl = new top_block_impl(this); + d_impl = new top_block_impl(this, catch_exceptions); } top_block::~top_block() diff --git a/gnuradio-runtime/lib/top_block_impl.cc b/gnuradio-runtime/lib/top_block_impl.cc index 16acb3826d..79cb4088fd 100644 --- a/gnuradio-runtime/lib/top_block_impl.cc +++ b/gnuradio-runtime/lib/top_block_impl.cc @@ -40,7 +40,9 @@ 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, + bool catch_exceptions); static struct scheduler_table { const char* name; @@ -49,7 +51,8 @@ static struct 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, bool catch_exceptions) { static scheduler_maker factory = 0; @@ -72,11 +75,16 @@ static scheduler_sptr make_scheduler(flat_flowgraph_sptr ffg, int max_noutput_it } } } - return factory(ffg, max_noutput_items); + return factory(ffg, max_noutput_items, catch_exceptions); } -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, bool catch_exceptions = true) + : d_owner(owner), + d_ffg(), + d_state(IDLE), + d_lock_count(0), + d_retry_wait(false), + d_catch_exceptions(catch_exceptions) { } @@ -115,7 +123,7 @@ void top_block_impl::start(int max_noutput_items) p->get_bool("PerfCounters", "export", false)) d_ffg->enable_pc_rpc(); - d_scheduler = make_scheduler(d_ffg, d_max_noutput_items); + d_scheduler = make_scheduler(d_ffg, d_max_noutput_items, d_catch_exceptions); d_state = RUNNING; } @@ -195,7 +203,7 @@ void top_block_impl::restart() d_ffg = new_ffg; // Create a new scheduler to execute it - d_scheduler = make_scheduler(d_ffg, d_max_noutput_items); + d_scheduler = make_scheduler(d_ffg, d_max_noutput_items, d_catch_exceptions); d_retry_wait = true; } diff --git a/gnuradio-runtime/lib/top_block_impl.h b/gnuradio-runtime/lib/top_block_impl.h index 84611b3f85..888b0fe0ab 100644 --- a/gnuradio-runtime/lib/top_block_impl.h +++ b/gnuradio-runtime/lib/top_block_impl.h @@ -39,7 +39,7 @@ namespace gr { class GR_RUNTIME_API top_block_impl { public: - top_block_impl(top_block* owner); + top_block_impl(top_block* owner, bool catch_exceptions); ~top_block_impl(); // Create and start scheduler threads @@ -85,6 +85,7 @@ protected: bool d_retry_wait; boost::condition_variable d_lock_cond; int d_max_noutput_items; + bool d_catch_exceptions; private: void restart(); |