diff options
author | Josh Blum | 2012-10-04 20:38:01 -0700 |
---|---|---|
committer | Josh Blum | 2012-10-04 20:38:01 -0700 |
commit | d9aad55eb18f8a9dab383a0b0cb8626f12c3fd29 (patch) | |
tree | 350f00e4e84f63956f999dec73419c022e96bbdd /lib | |
parent | c74b464015541a5b3d8efd3551231431562f32cb (diff) | |
download | sandhi-d9aad55eb18f8a9dab383a0b0cb8626f12c3fd29.tar.gz sandhi-d9aad55eb18f8a9dab383a0b0cb8626f12c3fd29.tar.bz2 sandhi-d9aad55eb18f8a9dab383a0b0cb8626f12c3fd29.zip |
support for maximum_items output port config
Diffstat (limited to 'lib')
-rw-r--r-- | lib/block.cpp | 1 | ||||
-rw-r--r-- | lib/block_allocator.cpp | 35 | ||||
-rw-r--r-- | lib/gr_block.cpp | 49 |
3 files changed, 70 insertions, 15 deletions
diff --git a/lib/block.cpp b/lib/block.cpp index 15e5807..d6f6e2b 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -28,6 +28,7 @@ InputPortConfig::InputPortConfig(void) OutputPortConfig::OutputPortConfig(void) { reserve_items = 1; + maximum_items = 0; } Block::Block(void) diff --git a/lib/block_allocator.cpp b/lib/block_allocator.cpp index d2d7424..2161eb9 100644 --- a/lib/block_allocator.cpp +++ b/lib/block_allocator.cpp @@ -18,7 +18,6 @@ #include <gras_impl/block_actor.hpp> #include <boost/bind.hpp> #include <boost/foreach.hpp> -#include <boost/math/common_factor.hpp> using namespace gnuradio; @@ -43,31 +42,36 @@ void BlockActor::buffer_returner(const size_t index, SBuffer &buffer) static size_t recommend_length( const std::vector<OutputHintMessage> &hints, - const size_t output_multiple_bytes, - const size_t at_least_bytes + const size_t hint_bytes, + const size_t at_least_bytes, + const size_t at_most_bytes ){ - //step 1) find the LCM of all reserves to create a super-reserve - size_t lcm_bytes = output_multiple_bytes; + //step 1) find the min of all reserves to create a super-reserve + size_t min_bytes = at_least_bytes; BOOST_FOREACH(const OutputHintMessage &hint, hints) { - lcm_bytes = boost::math::lcm(lcm_bytes, hint.reserve_bytes); + min_bytes = std::max(min_bytes, hint.reserve_bytes); } //step 2) N x super reserve to minimize history edge case - size_t Nlcm_bytes = lcm_bytes; + size_t Nmin_bytes = min_bytes; BOOST_FOREACH(const OutputHintMessage &hint, hints) { - while (hint.history_bytes*EDGE_CASE_MITIGATION > Nlcm_bytes) + while (hint.history_bytes*EDGE_CASE_MITIGATION > Nmin_bytes) { - Nlcm_bytes += lcm_bytes; + Nmin_bytes += min_bytes; } } - while (at_least_bytes > Nlcm_bytes) + while (hint_bytes > Nmin_bytes) { - Nlcm_bytes += lcm_bytes; + Nmin_bytes += min_bytes; } - return std::min(Nlcm_bytes, AHH_TOO_MANY_BYTES); + //step 3) cap the maximum size by the upper bound (if set) + if (at_most_bytes) Nmin_bytes = std::min(Nmin_bytes, at_most_bytes); + else Nmin_bytes = std::min(Nmin_bytes, AHH_TOO_MANY_BYTES); + + return Nmin_bytes; } void BlockActor::handle_top_alloc(const TopAllocMessage &, const Theron::Address from) @@ -85,13 +89,14 @@ void BlockActor::handle_top_alloc(const TopAllocMessage &, const Theron::Address this->output_buffer_tokens.resize(num_outputs); for (size_t i = 0; i < num_outputs; i++) { - size_t at_least_items = this->hint; - if (at_least_items == 0) at_least_items = AT_LEAST_DEFAULT_ITEMS; + size_t hint_items = this->hint; + if (hint_items == 0) hint_items = AT_LEAST_DEFAULT_ITEMS; const size_t bytes = recommend_length( this->output_allocation_hints[i], + hint_items*this->output_items_sizes[i], this->output_configs[i].reserve_items*this->output_items_sizes[i], - at_least_items*this->output_items_sizes[i] + this->output_configs[i].maximum_items*this->output_items_sizes[i] ); SBufferDeleter deleter = boost::bind(&BlockActor::buffer_returner, this, i, _1); diff --git a/lib/gr_block.cpp b/lib/gr_block.cpp index 27c0eb4..dea455c 100644 --- a/lib/gr_block.cpp +++ b/lib/gr_block.cpp @@ -95,3 +95,52 @@ void gr_block::set_decimation(const size_t decim) { this->set_relative_rate(1.0/decim); } + +unsigned gr_block::history(void) const +{ + //implement off-by-one history compat + return this->input_config().lookahead_items+1; +} + +void gr_block::set_history(unsigned history) +{ + gnuradio::InputPortConfig config = this->input_config(); + //implement off-by-one history compat + if (history == 0) history++; + config.lookahead_items = history-1; + this->set_input_config(config); +} + +unsigned gr_block::output_multiple(void) const +{ + return this->output_config().reserve_items+1; +} + +void gr_block::set_output_multiple(unsigned multiple) +{ + gnuradio::OutputPortConfig config = this->output_config(); + config.reserve_items = multiple; + this->set_output_config(config); +} + +int gr_block::max_noutput_items(void) const +{ + return this->output_config().maximum_items; +} + +void gr_block::set_max_noutput_items(int max_items) +{ + gnuradio::OutputPortConfig config = this->output_config(); + config.maximum_items = max_items; + this->set_output_config(config); +} + +void gr_block::unset_max_noutput_items(void) +{ + this->set_max_noutput_items(0); +} + +bool gr_block::is_set_max_noutput_items(void) const +{ + return this->max_noutput_items() != 0; +} |