diff options
author | Tom Rondeau | 2012-11-22 10:42:03 -0500 |
---|---|---|
committer | Tom Rondeau | 2012-11-22 10:42:03 -0500 |
commit | 83e1adf6f3efee641a994a9f4bb8dc2f827c873b (patch) | |
tree | 51b2d9962f3375318d88ac9b65fa1c4fc622a2e1 /gnuradio-core/src/lib | |
parent | 20de05ea85ee09c7462fbddfe680eb1a87996dc7 (diff) | |
download | gnuradio-83e1adf6f3efee641a994a9f4bb8dc2f827c873b.tar.gz gnuradio-83e1adf6f3efee641a994a9f4bb8dc2f827c873b.tar.bz2 gnuradio-83e1adf6f3efee641a994a9f4bb8dc2f827c873b.zip |
runtime: moved setting of min/max buffer sizes from gr_basic_block to gr_block.
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_basic_block.cc | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_basic_block.h | 77 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_basic_block.i | 6 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.cc | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.h | 74 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.i | 8 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 20 |
7 files changed, 101 insertions, 92 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 3d809aa8b..d7263b92d 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -45,9 +45,7 @@ gr_basic_block::gr_basic_block(const std::string &name, d_input_signature(input_signature), d_output_signature(output_signature), d_unique_id(s_next_id++), - d_color(WHITE), - d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), - d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) + d_color(WHITE) { s_ncurrently_allocated++; } diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index b8e8148b2..cb6a983c4 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -29,9 +29,8 @@ #include <boost/enable_shared_from_this.hpp> #include <boost/function.hpp> #include <gr_msg_accepter.h> -#include <gr_io_signature.h> #include <string> -#include <iostream> +#include <gr_io_signature.h> /*! * \brief The abstract base class for all signal processing blocks. @@ -62,21 +61,7 @@ private: }; msg_handler_t d_msg_handler; - - /* - * Used to expand the vectors that hold the min/max buffer sizes. - * - * Specifically, when -1 is used, the vectors are just initialized - * with 1 value; this is used by the flat_flowgraph to expand when - * required to add a new value for new ports on these blocks. - */ - void expand_minmax_buffer(int port) { - if((size_t)port >= d_max_output_buffer.size()) - set_max_output_buffer(port, -1); - if((size_t)port >= d_min_output_buffer.size()) - set_min_output_buffer(port, -1); - } - + protected: friend class gr_flowgraph; friend class gr_flat_flowgraph; // TODO: will be redundant @@ -89,8 +74,6 @@ protected: gr_io_signature_sptr d_output_signature; long d_unique_id; vcolor d_color; - std::vector<long> d_max_output_buffer; - std::vector<long> d_min_output_buffer; gr_basic_block(void){} //allows pure virtual interface sub-classes @@ -124,62 +107,6 @@ public: gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion /*! - * \brief Returns max buffer size on output port \p i. - */ - long max_output_buffer(size_t i) { - if(i >= d_max_output_buffer.size()) - throw std::invalid_argument("gr_basic_block::max_output_buffer: port out of range."); - return d_max_output_buffer[i]; - } - - /*! - * \brief Sets max buffer size on all output ports. - */ - void set_max_output_buffer(long max_output_buffer) { - for(int i=0; i<output_signature()->max_streams(); i++) { - set_max_output_buffer(i, max_output_buffer); - } - } - - /*! - * \brief Sets max buffer size on output port \p port. - */ - void set_max_output_buffer(int port, long max_output_buffer) { - if((size_t)port >= d_max_output_buffer.size()) - d_max_output_buffer.push_back(max_output_buffer); - else - d_max_output_buffer[port] = max_output_buffer; - } - - /*! - * \brief Returns min buffer size on output port \p i. - */ - long min_output_buffer(size_t i) { - if(i >= d_min_output_buffer.size()) - throw std::invalid_argument("gr_basic_block::min_output_buffer: port out of range."); - return d_min_output_buffer[i]; - } - - /*! - * \brief Sets min buffer size on all output ports. - */ - void set_min_output_buffer(long min_output_buffer) { - for(int i=0; i<output_signature()->max_streams(); i++) { - set_min_output_buffer(i, min_output_buffer); - } - } - - /*! - * \brief Sets min buffer size on output port \p port. - */ - void set_min_output_buffer(int port, long min_output_buffer) { - if((size_t)port >= d_min_output_buffer.size()) - d_min_output_buffer.push_back(min_output_buffer); - else - d_min_output_buffer[port] = min_output_buffer; - } - - /*! * \brief Confirm that ninputs and noutputs is an acceptable combination. * * \param ninputs number of input streams connected diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 7713f2fe1..e43cc114c 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -42,12 +42,6 @@ public: long unique_id() const; gr_basic_block_sptr to_basic_block(); bool check_topology (int ninputs, int noutputs); - long max_output_buffer(int i); - void set_max_output_buffer(long max_output_buffer); - void set_max_output_buffer(int port, long max_output_buffer); - long min_output_buffer(int i); - void set_min_output_buffer(long min_output_buffer); - void set_min_output_buffer(int port, long min_output_buffer); }; %rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 7e01c0ba8..a88052ee0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -42,7 +42,9 @@ gr_block::gr_block (const std::string &name, d_fixed_rate(false), d_max_noutput_items_set(false), d_max_noutput_items(0), - d_tag_propagation_policy(TPP_ALL_TO_ALL) + d_tag_propagation_policy(TPP_ALL_TO_ALL), + d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), + d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) { } diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index c89138bb3..98339080d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -288,6 +288,76 @@ class GR_CORE_API gr_block : public gr_basic_block { */ bool is_set_max_noutput_items(); + /* + * Used to expand the vectors that hold the min/max buffer sizes. + * + * Specifically, when -1 is used, the vectors are just initialized + * with 1 value; this is used by the flat_flowgraph to expand when + * required to add a new value for new ports on these blocks. + */ + void expand_minmax_buffer(int port) { + if((size_t)port >= d_max_output_buffer.size()) + set_max_output_buffer(port, -1); + if((size_t)port >= d_min_output_buffer.size()) + set_min_output_buffer(port, -1); + } + + /*! + * \brief Returns max buffer size on output port \p i. + */ + long max_output_buffer(size_t i) { + if(i >= d_max_output_buffer.size()) + throw std::invalid_argument("gr_basic_block::max_output_buffer: port out of range."); + return d_max_output_buffer[i]; + } + + /*! + * \brief Sets max buffer size on all output ports. + */ + void set_max_output_buffer(long max_output_buffer) { + for(int i = 0; i < output_signature()->max_streams(); i++) { + set_max_output_buffer(i, max_output_buffer); + } + } + + /*! + * \brief Sets max buffer size on output port \p port. + */ + void set_max_output_buffer(int port, long max_output_buffer) { + if((size_t)port >= d_max_output_buffer.size()) + d_max_output_buffer.push_back(max_output_buffer); + else + d_max_output_buffer[port] = max_output_buffer; + } + + /*! + * \brief Returns min buffer size on output port \p i. + */ + long min_output_buffer(size_t i) { + if(i >= d_min_output_buffer.size()) + throw std::invalid_argument("gr_basic_block::min_output_buffer: port out of range."); + return d_min_output_buffer[i]; + } + + /*! + * \brief Sets min buffer size on all output ports. + */ + void set_min_output_buffer(long min_output_buffer) { + for(int i=0; i<output_signature()->max_streams(); i++) { + set_min_output_buffer(i, min_output_buffer); + } + } + + /*! + * \brief Sets min buffer size on output port \p port. + */ + void set_min_output_buffer(int port, long min_output_buffer) { + if((size_t)port >= d_min_output_buffer.size()) + d_min_output_buffer.push_back(min_output_buffer); + else + d_min_output_buffer[port] = min_output_buffer; + } + // ---------------------------------------------------------------------------- private: @@ -384,6 +454,10 @@ class GR_CORE_API gr_block : public gr_basic_block { uint64_t abs_end, const pmt::pmt_t &key); + std::vector<long> d_max_output_buffer; + std::vector<long> d_min_output_buffer; + + // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friend GR_CORE_APIs diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index e9341e8cb..db6c1d04a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -58,6 +58,14 @@ class gr_block : public gr_basic_block { void unset_max_noutput_items(); bool is_set_max_noutput_items(); + // Methods to manage block's min/max buffer sizes. + long max_output_buffer(int i); + void set_max_output_buffer(long max_output_buffer); + void set_max_output_buffer(int port, long max_output_buffer); + long min_output_buffer(int i); + void set_min_output_buffer(long min_output_buffer); + void set_min_output_buffer(int port, long min_output_buffer); + // internal use gr_block_detail_sptr detail () const { return d_detail; } void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index b70135b85..b82ef46af 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -79,19 +79,25 @@ gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block) int ninputs = calc_used_ports(block, true).size(); int noutputs = calc_used_ports(block, false).size(); gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); + gr_block_sptr grblock = cast_to_block_sptr(block); if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Creating block detail for " << block << std::endl; for (int i = 0; i < noutputs; i++) { - block->expand_minmax_buffer(i); + if(grblock) { + grblock->expand_minmax_buffer(i); + } + gr_buffer_sptr buffer = allocate_buffer(block, i); if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Allocated buffer for output " << block << ":" << i << std::endl; detail->set_output(i, buffer); - // Update the block's max_output_buffer based on what was actually allocated. - block->set_max_output_buffer(i, buffer->bufsize()); + if(grblock) { + // Update the block's max_output_buffer based on what was actually allocated. + grblock->set_max_output_buffer(i, buffer->bufsize()); + } } return detail; @@ -119,15 +125,15 @@ gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); // limit buffer size if indicated - if(block->max_output_buffer(port) > 0) { + if(grblock->max_output_buffer(port) > 0) { // std::cout << "constraining output items to " << block->max_output_buffer(port) << "\n"; - nitems = std::min((long)nitems, (long)block->max_output_buffer(port)); + nitems = std::min((long)nitems, (long)grblock->max_output_buffer(port)); nitems -= nitems%grblock->output_multiple(); if( nitems < 1 ) throw std::runtime_error("problems allocating a buffer with the given max output buffer constraint!"); } - else if(block->min_output_buffer(port) > 0) { - nitems = std::max((long)nitems, (long)block->min_output_buffer(port)); + else if(grblock->min_output_buffer(port) > 0) { + nitems = std::max((long)nitems, (long)grblock->min_output_buffer(port)); nitems -= nitems%grblock->output_multiple(); if( nitems < 1 ) throw std::runtime_error("problems allocating a buffer with the given min output buffer constraint!"); |