summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/gnuradio/block.hpp19
-rw-r--r--lib/block_allocator.cpp32
-rw-r--r--lib/block_handlers.cpp2
-rw-r--r--swig/gras.i2
4 files changed, 43 insertions, 12 deletions
diff --git a/include/gnuradio/block.hpp b/include/gnuradio/block.hpp
index cf0cebf..ae09149 100644
--- a/include/gnuradio/block.hpp
+++ b/include/gnuradio/block.hpp
@@ -224,6 +224,25 @@ struct GRAS_API Block : Element
*/
void set_buffer_affinity(const Affinity &affinity);
+ /*!
+ * The output buffer allocator method.
+ * This method is called by the scheduler to allocate output buffers.
+ * The user may overload this method to create a custom allocator.
+ *
+ * Example use case:
+ * //TODO code example
+ *
+ * \param which_output the output port index number
+ * \param token the token for the buffer's returner
+ * \param recommend_length the schedulers recommended length in bytes
+ * \return the token used for the buffer allocation (may be the same)
+ */
+ virtual SBufferToken output_buffer_allocator(
+ const size_t which_output,
+ const SBufferToken &token,
+ const size_t recommend_length
+ );
+
//TODO overload for allocate output buffer(index)
};
diff --git a/lib/block_allocator.cpp b/lib/block_allocator.cpp
index 708b35b..24369c7 100644
--- a/lib/block_allocator.cpp
+++ b/lib/block_allocator.cpp
@@ -86,17 +86,27 @@ void ElementImpl::handle_allocation(const tsbe::TaskInterface &task_iface)
);
SBufferDeleter deleter = boost::bind(&ElementImpl::buffer_returner, this, i, _1);
- this->output_buffer_tokens[i] = SBufferToken(new SBufferDeleter(deleter));
- for (size_t j = 0; j < THIS_MANY_BUFFERS; j++)
- {
- SBufferConfig config;
- config.memory = NULL;
- config.length = bytes;
- config.affinity = this->buffer_affinity;
- config.token = this->output_buffer_tokens[i];
- SBuffer buff(config);
- //buffer derefs here and the token messages it back to the block
- }
+ this->output_buffer_tokens[i] = block_ptr->output_buffer_allocator(
+ i, SBufferToken(new SBufferDeleter(deleter)), bytes
+ );
+ }
+}
+
+SBufferToken Block::output_buffer_allocator(
+ const size_t which_output,
+ const SBufferToken &token,
+ const size_t recommend_length
+){
+ for (size_t j = 0; j < THIS_MANY_BUFFERS; j++)
+ {
+ SBufferConfig config;
+ config.memory = NULL;
+ config.length = recommend_length;
+ config.affinity = (*this)->buffer_affinity;
+ config.token = token;
+ SBuffer buff(config);
+ //buffer derefs here and the token messages it back to the block
}
+ return token;
}
diff --git a/lib/block_handlers.cpp b/lib/block_handlers.cpp
index d61a7e2..684b6fa 100644
--- a/lib/block_handlers.cpp
+++ b/lib/block_handlers.cpp
@@ -93,7 +93,7 @@ void ElementImpl::handle_block_msg(
//tell the upstream about the input requirements
BufferHintMessage message;
message.history_bytes = this->input_history_items[i]*this->input_items_sizes[i];
- message.reserve_bytes = input_multiple_items[i];
+ message.reserve_bytes = this->input_multiple_items[i];
message.token = this->input_tokens[i];
task_iface.post_upstream(i, message);
diff --git a/swig/gras.i b/swig/gras.i
index fc1447b..cc0f51a 100644
--- a/swig/gras.i
+++ b/swig/gras.i
@@ -31,6 +31,8 @@
%ignore gnuradio::IOSignature::operator->();
%ignore gnuradio::IOSignature::operator->() const;
+%ignore gnuradio::Block::output_buffer_allocator;
+
%include <gnuradio/sbuffer.hpp>
%include <gnuradio/element.hpp>
%include <gnuradio/tags.hpp>