diff options
author | Josh Blum | 2012-10-04 21:15:11 -0700 |
---|---|---|
committer | Josh Blum | 2012-10-04 21:15:11 -0700 |
commit | 709f8e97cc642e446d357612a6d6512d5a4c5330 (patch) | |
tree | 203a53e63fca96fe9e9a72d3fe386102d817b8d2 | |
parent | 3600e927bf31ca46bb99ef2df83512112fa6a8b2 (diff) | |
download | sandhi-709f8e97cc642e446d357612a6d6512d5a4c5330.tar.gz sandhi-709f8e97cc642e446d357612a6d6512d5a4c5330.tar.bz2 sandhi-709f8e97cc642e446d357612a6d6512d5a4c5330.zip |
implementation for the top block global config
-rw-r--r-- | include/gnuradio/gr_top_block.h | 12 | ||||
-rw-r--r-- | include/gnuradio/top_block.hpp | 2 | ||||
-rw-r--r-- | lib/block.cpp | 1 | ||||
-rw-r--r-- | lib/block_allocator.cpp | 5 | ||||
-rw-r--r-- | lib/block_handlers.cpp | 13 | ||||
-rw-r--r-- | lib/element_impl.hpp | 1 | ||||
-rw-r--r-- | lib/gras_impl/block_actor.hpp | 6 | ||||
-rw-r--r-- | lib/gras_impl/debug.hpp | 2 | ||||
-rw-r--r-- | lib/gras_impl/messages.hpp | 5 | ||||
-rw-r--r-- | lib/register_messages.cpp | 3 | ||||
-rw-r--r-- | lib/top_block.cpp | 14 | ||||
-rw-r--r-- | swig/gras.i | 12 | ||||
-rw-r--r-- | swig/runtime.i | 1 |
13 files changed, 53 insertions, 24 deletions
diff --git a/include/gnuradio/gr_top_block.h b/include/gnuradio/gr_top_block.h index 3a56bf6..0fa5496 100644 --- a/include/gnuradio/gr_top_block.h +++ b/include/gnuradio/gr_top_block.h @@ -34,7 +34,12 @@ struct GRAS_API gr_top_block : gnuradio::TopBlock void unlock(void) { - this->update(); + this->commit(); + } + + void start(void) + { + gnuradio::TopBlock::start(); } void start(const size_t max_items) @@ -43,6 +48,11 @@ struct GRAS_API gr_top_block : gnuradio::TopBlock gnuradio::TopBlock::start(); } + void run(void) + { + gnuradio::TopBlock::run(); + } + void run(const size_t max_items) { this->set_max_noutput_items(max_items); diff --git a/include/gnuradio/top_block.hpp b/include/gnuradio/top_block.hpp index bab67ee..19daafc 100644 --- a/include/gnuradio/top_block.hpp +++ b/include/gnuradio/top_block.hpp @@ -42,7 +42,7 @@ struct GRAS_API TopBlock : HierBlock TopBlock(const std::string &name); //! Get the global block config settings - const GlobalBlockConfig &global_config(void) const; + GlobalBlockConfig global_config(void) const; //! Set the global block config settings void set_global_config(const GlobalBlockConfig &config); diff --git a/lib/block.cpp b/lib/block.cpp index d6f6e2b..84ae09e 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -46,7 +46,6 @@ Block::Block(const std::string &name): (*this)->block->topology_init = false; (*this)->block->forecast_fail = false; (*this)->block->block_ptr = this; - (*this)->block->hint = 0; (*this)->block->block_state = BlockActor::BLOCK_STATE_INIT; //call block methods to init stuff diff --git a/lib/block_allocator.cpp b/lib/block_allocator.cpp index 2161eb9..9b70824 100644 --- a/lib/block_allocator.cpp +++ b/lib/block_allocator.cpp @@ -89,12 +89,9 @@ 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 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], + AT_LEAST_DEFAULT_ITEMS*this->output_items_sizes[i], this->output_configs[i].reserve_items*this->output_items_sizes[i], this->output_configs[i].maximum_items*this->output_items_sizes[i] ); diff --git a/lib/block_handlers.cpp b/lib/block_handlers.cpp index 2e71ac1..1366e68 100644 --- a/lib/block_handlers.cpp +++ b/lib/block_handlers.cpp @@ -108,13 +108,20 @@ void BlockActor::handle_top_token( this->Send(0, from); //ACK } -void BlockActor::handle_top_hint( - const TopHintMessage &message, +void BlockActor::handle_top_config( + const GlobalBlockConfig &message, const Theron::Address from ){ MESSAGE_TRACER(); - this->hint = message.hint; + //overwrite with global config only if maxium_items is not set (zero) + for (size_t i = 0; i < this->output_configs.size(); i++) + { + if (this->output_configs[i].maximum_items == 0) + { + this->output_configs[i].maximum_items = message.maximum_output_items; + } + } this->Send(0, from); //ACK } diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp index 90c4fe2..95f4f3a 100644 --- a/lib/element_impl.hpp +++ b/lib/element_impl.hpp @@ -45,6 +45,7 @@ struct ElementImpl //top block stuff SharedThreadGroup thread_group; Token token; + GlobalBlockConfig top_config; //things may be in this element boost::shared_ptr<Apology::Topology> topology; diff --git a/lib/gras_impl/block_actor.hpp b/lib/gras_impl/block_actor.hpp index bbe6d6c..023011d 100644 --- a/lib/gras_impl/block_actor.hpp +++ b/lib/gras_impl/block_actor.hpp @@ -21,6 +21,7 @@ #include <gras_impl/bitset.hpp> #include <gnuradio/gras.hpp> #include <gnuradio/block.hpp> +#include <gnuradio/top_block.hpp> #include <Apology/Worker.hpp> #include <gras_impl/token.hpp> #include <gras_impl/messages.hpp> @@ -59,7 +60,7 @@ struct BlockActor : Apology::Worker this->RegisterHandler(this, &BlockActor::handle_top_active); this->RegisterHandler(this, &BlockActor::handle_top_inert); this->RegisterHandler(this, &BlockActor::handle_top_token); - this->RegisterHandler(this, &BlockActor::handle_top_hint); + this->RegisterHandler(this, &BlockActor::handle_top_config); this->RegisterHandler(this, &BlockActor::handle_top_thread_group); this->RegisterHandler(this, &BlockActor::handle_input_tag); @@ -85,7 +86,7 @@ struct BlockActor : Apology::Worker void handle_top_active(const TopActiveMessage &, const Theron::Address); void handle_top_inert(const TopInertMessage &, const Theron::Address); void handle_top_token(const TopTokenMessage &, const Theron::Address); - void handle_top_hint(const TopHintMessage &, const Theron::Address); + void handle_top_config(const GlobalBlockConfig &, const Theron::Address); void handle_top_thread_group(const SharedThreadGroup &, const Theron::Address); void handle_input_tag(const InputTagMessage &, const Theron::Address); @@ -180,7 +181,6 @@ struct BlockActor : Apology::Worker BLOCK_STATE_LIVE, BLOCK_STATE_DONE, } block_state; - size_t hint; //some kind of allocation hint Affinity buffer_affinity; std::vector<std::vector<OutputHintMessage> > output_allocation_hints; diff --git a/lib/gras_impl/debug.hpp b/lib/gras_impl/debug.hpp index 03ad30f..2fae424 100644 --- a/lib/gras_impl/debug.hpp +++ b/lib/gras_impl/debug.hpp @@ -37,7 +37,7 @@ extern void *operator new(std::size_t n) throw (std::bad_alloc); //-- define to enable these debugs: //---------------------------------------------------------------------- //#define WORK_DEBUG -//#define ASSERTING +#define ASSERTING //#define MESSAGE_TRACING //---------------------------------------------------------------------- diff --git a/lib/gras_impl/messages.hpp b/lib/gras_impl/messages.hpp index 81c66b7..ef87398 100644 --- a/lib/gras_impl/messages.hpp +++ b/lib/gras_impl/messages.hpp @@ -50,11 +50,6 @@ struct TopTokenMessage Token token; }; -struct TopHintMessage -{ - size_t hint; -}; - //---------------------------------------------------------------------- //-- message to an input port //-- do not ack diff --git a/lib/register_messages.cpp b/lib/register_messages.cpp index 18a3cd8..7c894fa 100644 --- a/lib/register_messages.cpp +++ b/lib/register_messages.cpp @@ -15,6 +15,7 @@ // along with io_sig program. If not, see <http://www.gnu.org/licenses/>. #include <Theron/Register.h> +#include <gnuradio/top_block.hpp> #include <gras_impl/messages.hpp> #include <gras_impl/interruptible_thread.hpp> #include <Apology/Worker.hpp> @@ -24,7 +25,7 @@ THERON_REGISTER_MESSAGE(gnuradio::TopAllocMessage); THERON_REGISTER_MESSAGE(gnuradio::TopActiveMessage); THERON_REGISTER_MESSAGE(gnuradio::TopInertMessage); THERON_REGISTER_MESSAGE(gnuradio::TopTokenMessage); -THERON_REGISTER_MESSAGE(gnuradio::TopHintMessage); +THERON_REGISTER_MESSAGE(gnuradio::GlobalBlockConfig); THERON_REGISTER_MESSAGE(gnuradio::SharedThreadGroup); THERON_REGISTER_MESSAGE(gnuradio::InputTagMessage); diff --git a/lib/top_block.cpp b/lib/top_block.cpp index c93bda5..4973b59 100644 --- a/lib/top_block.cpp +++ b/lib/top_block.cpp @@ -53,6 +53,16 @@ void ElementImpl::top_block_cleanup(void) << std::flush; } +GlobalBlockConfig TopBlock::global_config(void) const +{ + return (*this)->top_config; +} + +void TopBlock::set_global_config(const GlobalBlockConfig &config) +{ + (*this)->top_config = config; +} + void TopBlock::commit(void) { this->start(); //ok to re-start, means update @@ -70,6 +80,10 @@ void TopBlock::start(void) (*this)->executor->post_all(message); } { + //send the global block config before alloc + (*this)->executor->post_all((*this)->top_config); + } + { (*this)->executor->post_all(TopAllocMessage()); } { diff --git a/swig/gras.i b/swig/gras.i index 4a605f5..e6804e0 100644 --- a/swig/gras.i +++ b/swig/gras.i @@ -44,6 +44,7 @@ %include <gr_io_signature.h> %include <gr_block.h> %include <gr_hier_block2.h> +%include <gr_top_block.h> %include <gr_sync_block.h> %include <gr_sync_decimator.h> %include <gr_sync_interpolator.h> @@ -58,16 +59,19 @@ namespace gnuradio { -struct TopBlockPython : TopBlock +//typedef TopBlock TopBlockBase; +typedef gr_top_block TopBlockBase; //maximal set of all API + +struct TopBlockPython : TopBlockBase { TopBlockPython(void): - TopBlock("top") + TopBlockBase("top") { //NOP } TopBlockPython(const std::string &name): - TopBlock(name) + TopBlockBase(name) { //NOP } @@ -76,7 +80,7 @@ struct TopBlockPython : TopBlock { GR_PYTHON_BLOCKING_CODE ( - TopBlock::wait(); + TopBlockBase::wait(); ) } diff --git a/swig/runtime.i b/swig/runtime.i index 6b1999b..7b2625d 100644 --- a/swig/runtime.i +++ b/swig/runtime.i @@ -32,6 +32,7 @@ #include <gnuradio/tags.hpp> #include <gr_io_signature.h> #include <gr_block.h> +#include <gr_top_block.h> #include <gr_hier_block2.h> #include <gr_message.h> #include <gr_msg_handler.h> |