summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc59
-rw-r--r--gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h9
2 files changed, 46 insertions, 22 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc
index e97fa13a4..adb1f5608 100644
--- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc
+++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc
@@ -63,8 +63,13 @@ gr_flat_flowgraph::setup_connections()
cast_to_block_sptr(*p)->set_detail(allocate_block_detail(*p));
// Connect inputs to outputs for each block
- for(gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++)
+ for(gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) {
connect_block_inputs(*p);
+
+ gr_block_sptr block = cast_to_block_sptr(*p);
+ setup_buffer_alignment(block);
+ }
+
}
gr_block_detail_sptr
@@ -245,27 +250,8 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg)
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);
- }
- }
+ // Make sure all buffers are aligned
+ setup_buffer_alignment(block);
}
// Now deal with the fact that the block details might have changed numbers of
@@ -273,6 +259,35 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg)
}
}
+void
+gr_flat_flowgraph::setup_buffer_alignment(gr_block_sptr 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;
+ //std::cout << "reader: " << r << " alignment: " << ri << std::endl;
+ 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;
+ size_t itemsize = block->detail()->output(i)->get_sizeof_item();
+ //std::cout << "writer: " << w << " alignment: " << wi << std::endl;
+ if(wi != 0) {
+ block->detail()->output(i)->update_write_pointer(wi/itemsize);
+ }
+ block->set_unaligned(0);
+ block->set_is_unaligned(false);
+ }
+}
+
void gr_flat_flowgraph::dump()
{
for (gr_edge_viter_t e = d_edges.begin(); e != d_edges.end(); e++)
diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h
index 2cc883686..ce863509b 100644
--- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h
+++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h
@@ -63,6 +63,15 @@ private:
gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block);
gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port);
void connect_block_inputs(gr_basic_block_sptr block);
+
+ /* When reusing a flowgraph's blocks, this call makes sure all of the
+ * buffer's are aligned at the machine's alignment boundary and tells
+ * the blocks that they are aligned.
+ *
+ * Called from both setup_connections and merge_connections for
+ * start and restarts.
+ */
+ void setup_buffer_alignment(gr_block_sptr block);
};
#endif /* INCLUDED_GR_FLAT_FLOWGRAPH_H */