diff options
author | Jiří Pinkava <j-pi@seznam.cz> | 2015-04-09 08:55:04 +0200 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2016-06-25 09:47:40 -0700 |
commit | a99f8ac8cc9a15ab608081c10a7733fce125e276 (patch) | |
tree | 86c4d7b5fb53039a95d0e2f146b20d5b52cf2c6a /gnuradio-runtime/lib/top_block_impl.cc | |
parent | 0e18622160a33c10d5853fc3e3d0ee4ebaa41829 (diff) |
runtime: fix state handling in top_block
d_state is intended to track running state of top block.
* initial state is IDLE
* set state to RUNNING when start() is called
* set state to IDLE when stop() is called
* set state to IDLE when all work is done (reqires call of wait())
* unlock() resume/start execution only if state is RUNNING
Diffstat (limited to 'gnuradio-runtime/lib/top_block_impl.cc')
-rw-r--r-- | gnuradio-runtime/lib/top_block_impl.cc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/gnuradio-runtime/lib/top_block_impl.cc b/gnuradio-runtime/lib/top_block_impl.cc index 48404a6832..3f94867bc2 100644 --- a/gnuradio-runtime/lib/top_block_impl.cc +++ b/gnuradio-runtime/lib/top_block_impl.cc @@ -80,7 +80,7 @@ namespace gr { top_block_impl::top_block_impl(top_block *owner) : d_owner(owner), d_ffg(), - d_state(IDLE), d_lock_count(0) + d_state(IDLE), d_lock_count(0), d_retry_wait(false) { } @@ -125,8 +125,12 @@ namespace gr { void top_block_impl::stop() { + gr::thread::scoped_lock lock(d_mutex); + if(d_scheduler) d_scheduler->stop(); + + d_state = IDLE; } void @@ -137,6 +141,11 @@ namespace gr { { 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); @@ -149,8 +158,6 @@ namespace gr { { if(d_scheduler) d_scheduler->wait(); - - d_state = IDLE; } // N.B. lock() and unlock() cannot be called from a flow graph @@ -159,7 +166,8 @@ namespace gr { top_block_impl::lock() { gr::thread::scoped_lock lock(d_mutex); - stop(); + if(d_scheduler) + d_scheduler->stop(); d_lock_count++; } @@ -177,8 +185,8 @@ namespace gr { if(d_lock_count > 0 || d_state == IDLE) // nothing to do return; - d_lock_cond.notify_all(); restart(); + d_lock_cond.notify_all(); } /* @@ -197,7 +205,7 @@ namespace gr { // Create a new scheduler to execute it d_scheduler = make_scheduler(d_ffg, d_max_noutput_items); - d_state = RUNNING; + d_retry_wait = true; } std::string |