From 170c4ba4b39889073b2a3f129e77ca9b2f91bbf2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 27 Mar 2012 14:14:03 -0400 Subject: core: when reseting buffers, make sure that the read/write pointers are always algined. This fixes problems when disconnecting and reconnecting blocks to a flowgraph. --- gnuradio-core/src/lib/runtime/gr_buffer.h | 3 +++ gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 23 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index e8e393756..9478e1ce0 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -93,6 +93,7 @@ class GR_CORE_API gr_buffer { uint64_t nitems_written() { return d_abs_write_offset; } + size_t get_sizeof_item() { return d_sizeof_item; } /*! * \brief Adds a new tag to the buffer. @@ -249,6 +250,8 @@ class GR_CORE_API gr_buffer_reader { uint64_t nitems_read() { return d_abs_read_offset; } + size_t get_sizeof_item() { return d_buffer->get_sizeof_item(); } + /*! * \brief Return the block that reads via this reader. * diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 5d1057e0f..e97fa13a4 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -243,6 +244,28 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "new block" << std::endl; connect_block_inputs(block); + + const int alignment = volk_get_alignment(); + for(int i = 0; i < block->detail()->ninputs(); i++) { + void *r = (void*)block->detail()->input(i)->read_pointer(); + unsigned long int ri = (unsigned long int)r % alignment; + if(ri != 0) { + size_t itemsize = block->detail()->input(i)->get_sizeof_item(); + block->detail()->input(i)->update_read_pointer(ri/itemsize); + block->set_unaligned(0); + block->set_is_unaligned(false); + } + } + for(int i = 0; i < block->detail()->noutputs(); i++) { + void *w = (void*)block->detail()->output(i)->write_pointer(); + unsigned long int wi = (unsigned long int)w % alignment; + if(wi != 0) { + size_t itemsize = block->detail()->output(i)->get_sizeof_item(); + block->detail()->output(i)->update_write_pointer(wi/itemsize); + block->set_unaligned(0); + block->set_is_unaligned(false); + } + } } // Now deal with the fact that the block details might have changed numbers of -- cgit