summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib/block_executor.cc
diff options
context:
space:
mode:
authorTom Rondeau <tom@trondeau.com>2013-10-29 14:19:20 -0400
committerTom Rondeau <tom@trondeau.com>2013-10-29 14:21:15 -0400
commite140069eaa05a0b71bbacb014d596dc218383940 (patch)
treeecaf88321e4a42a12843ff670c9ede600269a668 /gnuradio-runtime/lib/block_executor.cc
parent9b9768baefeb995dc4516168287c6f865c92b60a (diff)
runtime: add concept up an automatic update_rate to gr::block.
When enabled, uses nitems_written/nitems_read to update the relative_rate of a block. Useful for blocks that change their relative rate based on activity in the work function. Disabled by default. digital: PFB clock sync blocks set update_rate to True.
Diffstat (limited to 'gnuradio-runtime/lib/block_executor.cc')
-rw-r--r--gnuradio-runtime/lib/block_executor.cc23
1 files changed, 12 insertions, 11 deletions
diff --git a/gnuradio-runtime/lib/block_executor.cc b/gnuradio-runtime/lib/block_executor.cc
index 85cf4bb2ab..ee22ef55e3 100644
--- a/gnuradio-runtime/lib/block_executor.cc
+++ b/gnuradio-runtime/lib/block_executor.cc
@@ -451,16 +451,12 @@ namespace gr {
m->set_is_unaligned(m->unaligned() != 0);
}
- if(n == block::WORK_DONE)
- goto were_done;
-
- if(n != block::WORK_CALLED_PRODUCE)
- d->produce_each (n); // advance write pointers
-
- // Wait til after we've consumed and produced and recalculate
- // the relative rate.
- if(!d->sink_p() && !d->source_p()) {
- rrate = ((double)m->nitems_written(0)) / ((double)m->nitems_read(0));
+ // For some blocks that can change their produce/consume ratio
+ // (the relative_rate), we might want to automatically update
+ // based on the amount of items written/read.
+ // In the block constructor, use enable_update_rate(true).
+ if(m->update_rate()) {
+ rrate = ((double)(m->nitems_written(0)+n)) / ((double)m->nitems_read(0));
if(rrate > 0)
m->set_relative_rate(rrate);
}
@@ -471,8 +467,13 @@ namespace gr {
d_returned_tags, m->unique_id()))
goto were_done;
+ if(n == block::WORK_DONE)
+ goto were_done;
+
+ if(n != block::WORK_CALLED_PRODUCE)
+ d->produce_each(n); // advance write pointers
- if(d->d_produce_or > 0) // block produced something
+ if(d->d_produce_or > 0) // block produced something
return READY;
// We didn't produce any output even though we called general_work.