[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r3803 - gnuradio/branches/developers/jcorgan/cppwrap/g
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r3803 - gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++ |
Date: |
Tue, 17 Oct 2006 11:56:37 -0600 (MDT) |
Author: jcorgan
Date: 2006-10-17 11:56:37 -0600 (Tue, 17 Oct 2006)
New Revision: 3803
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/dialtone.cc
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.cc
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.h
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.cc
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.h
Log:
Work in progress.
Finished refactoring flow graph code.
Fixed threading issue with join().
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/dialtone.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/dialtone.cc
2006-10-17 16:21:32 UTC (rev 3802)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/dialtone.cc
2006-10-17 17:56:37 UTC (rev 3803)
@@ -27,15 +27,12 @@
int main()
{
gr_sig_source_f_sptr src0, src1;
-// gr_block_sptr sink0, sink1;
audio_alsa_sink_sptr sink;
gr_flow_graph_sptr fg;
src0 = gr_make_sig_source_f(48000, GR_SIN_WAVE, 350, 0.5);
src1 = gr_make_sig_source_f(48000, GR_SIN_WAVE, 440, 0.5);
sink = audio_alsa_make_sink(48000);
-// sink0 = gr_make_null_sink(sizeof(float));
-// sink1 = gr_make_null_sink(sizeof(float));
fg = gr_make_flow_graph();
fg->connect(src0, 0, sink, 0);
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.cc
2006-10-17 16:21:32 UTC (rev 3802)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.cc
2006-10-17 17:56:37 UTC (rev 3803)
@@ -24,9 +24,12 @@
#include <gr_io_signature.h>
#include <gr_buffer.h>
-#include <iostream>
#include <algorithm>
+#if GR_FLOWGRAPH_DEBUG
+#include <iostream>
+#endif
+
using namespace std;
/********** BEGIN PUBLIC METHODS **********/
@@ -65,7 +68,9 @@
void gr_basic_flowgraph::disconnect_all()
{
d_edges.clear();
- printf("Disconnected all blocks.\n");
+#if GR_FLOWGRAPH_DEBUG
+ cout << "Disconnected all blocks." << endl;
+#endif
}
// Returns list of lists of blocks comprising unique islands
@@ -73,11 +78,11 @@
gr_block_vector_vector_t gr_basic_flowgraph::calc_partitions()
{
gr_block_vector_vector_t result;
- gr_block_vector_t nodes = d_blocks;
+ gr_block_vector_t nodes = d_blocks; // Working copy
gr_block_vector_t graph;
while (nodes.size() > 0) {
- graph = calc_reachable_vertices(nodes[0], nodes);
+ graph = calc_reachable_blocks(nodes[0], nodes);
// Partition should be at least one block
assert(graph.size());
@@ -121,9 +126,10 @@
// Create edge instance and add to edge list
d_edges.push_back(gr_edge_t(src, dst));
-
+#if GR_FLOWGRAPH_DEBUG
cout << "Connected " << src.first << ":" << src.second << " to "
<< dst.second << ":" << dst.first << endl;
+#endif
}
// Removes an edge from the list of edges. All overloaded version sof
'disconnect'
@@ -136,9 +142,10 @@
d_edges.erase(edge_iter);
else
throw invalid_argument("gr_basic_flowgraph::disconnect_prim: not
connected");
-
+#if GR_FLOWGRAPH_DEBUG
cout << "Disconnected " << src.first << ":" << src.second << " from "
<< dst.second << ":" << dst.first << endl;
+#endif
}
// Ports must not be negative and must be less than max streams for block
@@ -193,8 +200,9 @@
if (block_iter == d_blocks.end())
d_blocks.push_back(dst_block);
}
-
+#if GR_FLOWGRAPH_DEBUG
cout << "Flow graph has " << d_blocks.size() << " unique blocks." << endl;
+#endif
}
// Based on connectivity, create block details, buffers, and assign to block
outputs
@@ -239,9 +247,10 @@
int src_port = edge_iter->first.second;
gr_block_sptr src_block = edge_iter->first.first;
gr_buffer_sptr src_buffer = src_block->detail()->output(src_port);
-
+#if GR_FLOWGRAPH_DEBUG
cout << "Setting input buffer on " << dst_port << ":"
<< edge_iter->second.first << endl;
+#endif
detail->set_input(dst_port, gr_buffer_add_reader(src_buffer,
(*block_iter)->history()-1));
}
}
@@ -268,33 +277,13 @@
int history = (*block_iter)->history();
nitems = max(nitems, 2*(decimation*multiple+history));
}
-
+#if GR_FLOWGRAPH_DEBUG
cout << "Block " << block << " has output buffer of " << nitems
<< " items, each of size " << item_size << endl;
-
+#endif
return gr_make_buffer(nitems, item_size);
}
-// Recursively mark all reachable blocks from given block and vertex list
-void gr_basic_flowgraph::reachable_dfs_visit(gr_block_sptr block,
gr_vertex_vector_t &vertices)
-{
- // Find vertex corresponding to block, mark visited
- // FIXME: pass in the vector when recursing instead of looking it up again
- gr_vertex_t vertex;
- gr_vertex_vector_iterator_t vertex_iter;
- for (vertex_iter = vertices.begin(); vertex_iter != vertices.end();
vertex_iter++)
- if (vertex_iter->first == block) {
- vertex = *vertex_iter;
- vertex_iter->second = GR_VERTEX_BLACK;
- }
-
- // Recurse into adjacent vertices
- gr_vertex_vector_t adjacent = calc_adjacent_vertices(vertex, vertices);
- for (vertex_iter = adjacent.begin(); vertex_iter != adjacent.end();
vertex_iter++)
- if (vertex_iter->second == GR_VERTEX_WHITE)
- reachable_dfs_visit(vertex_iter->first, vertices);
-}
-
// Return list of blocks sorted in topological order
gr_block_vector_t gr_basic_flowgraph::topological_sort(gr_block_vector_t
blocks)
{
@@ -387,50 +376,54 @@
}
// Return a list of blocks reachable from a given block via any port
-gr_block_vector_t gr_basic_flowgraph::calc_reachable_vertices(gr_block_sptr
block, gr_block_vector_t &blocks)
+gr_block_vector_t gr_basic_flowgraph::calc_reachable_blocks(gr_block_sptr
block, gr_block_vector_t &blocks)
{
gr_block_vector_t result;
- gr_vertex_vector_t vertices;
- // Create working list of vertices
+ // Mark all blocks as unvisited
gr_block_vector_iterator_t block_iter;
for(block_iter = blocks.begin(); block_iter != blocks.end(); block_iter++)
- vertices.push_back(make_pair(*block_iter, GR_VERTEX_WHITE));
+ (*block_iter)->detail()->set_color(gr_block_detail::WHITE);
- // Mark all reachable vertices from 'block'
- reachable_dfs_visit(block, vertices);
+ // Recursively mark all reachable vertices from 'block'
+ reachable_dfs_visit(block, blocks);
- // Collect all the blocks from the marked vertices into the result vector
- gr_vertex_vector_iterator_t vertex_iter;
- for (vertex_iter = vertices.begin(); vertex_iter != vertices.end();
vertex_iter++)
- if (vertex_iter->second == GR_VERTEX_BLACK)
- result.push_back(vertex_iter->first);
+ // Collect all the blocks that have been visited
+ for (block_iter = blocks.begin(); block_iter != blocks.end(); block_iter++)
+ if ((*block_iter)->detail()->color() == gr_block_detail::BLACK)
+ result.push_back(*block_iter);
return result;
}
-// Return a list of vertices adjacent to a given vertex
-gr_vertex_vector_t gr_basic_flowgraph::calc_adjacent_vertices(gr_vertex_t
vertex, gr_vertex_vector_t &vertices)
+// Recursively mark all reachable blocks from given block and block list
+void gr_basic_flowgraph::reachable_dfs_visit(gr_block_sptr block,
gr_block_vector_t &blocks)
{
- gr_vertex_vector_t result;
+ // Mark the current one as visited
+ block->detail()->set_color(gr_block_detail::BLACK);
+
+ // Recurse into adjacent vertices
+ gr_block_vector_t adjacent = calc_adjacent_blocks(block, blocks);
+
+ gr_block_vector_iterator_t block_iter;
+ for (block_iter = adjacent.begin(); block_iter != adjacent.end();
block_iter++)
+ if ((*block_iter)->detail()->color() == gr_block_detail::WHITE)
+ reachable_dfs_visit(*block_iter, blocks);
+}
+
+// Return a list of block adjacent to a given block along any edge
+gr_block_vector_t gr_basic_flowgraph::calc_adjacent_blocks(gr_block_sptr
block, gr_block_vector_t &blocks)
+{
+ gr_block_vector_t result;
// Find any blocks that are inputs or outputs
- gr_block_vector_t matches;
gr_edge_vector_iterator_t edge_iter;
for (edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++)
{
- if (edge_iter->first.first == vertex.first)
- matches.push_back(edge_iter->second.first);
- if (edge_iter->second.first == vertex.first)
- matches.push_back(edge_iter->first.first);
+ if (edge_iter->first.first == block)
+ result.push_back(edge_iter->second.first);
+ if (edge_iter->second.first == block)
+ result.push_back(edge_iter->first.first);
}
- // Then collect those vertices that match those blocks
- gr_vertex_vector_iterator_t vertex_iter;
- for (vertex_iter = vertices.begin(); vertex_iter != vertices.end();
vertex_iter++) {
- gr_block_vector_iterator_t match = find(matches.begin(), matches.end(),
vertex_iter->first);
- if (match != matches.end())
- result.push_back(*vertex_iter);
- }
-
return result;
}
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.h
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.h
2006-10-17 16:21:32 UTC (rev 3802)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_basic_flowgraph.h
2006-10-17 17:56:37 UTC (rev 3803)
@@ -22,6 +22,9 @@
#ifndef INCLUDED_GR_BASIC_FLOWGRAPH_H
#define INCLUDED_GR_BASIC_FLOWGRAPH_H
+// Define to 0 to eliminate flowgraph debugging
+#define GR_FLOWGRAPH_DEBUG 1
+
#include <gr_block.h>
#include <boost/enable_shared_from_this.hpp>
@@ -29,10 +32,6 @@
typedef boost::shared_ptr<gr_basic_flowgraph> gr_basic_flowgraph_sptr;
gr_basic_flowgraph_sptr gr_make_basic_flowgraph();
-// Dupe to gr_scheduler.h, but we can't include it here
-class gr_scheduler;
-typedef boost::shared_ptr<gr_scheduler> gr_scheduler_sptr;
-
// Oh, for the love of Python, of which the STL is but the faintest
approximation,
// that those poor souls who toil in C++ land might know some glimmer of the
// beauty and majesty of lists and list comprehensions. At least one may take
some
@@ -51,12 +50,6 @@
typedef std::vector<gr_edge_t> gr_edge_vector_t;
typedef std::vector<gr_edge_t>::iterator gr_edge_vector_iterator_t;
-// Flow graph vertices
-typedef enum { GR_VERTEX_WHITE, GR_VERTEX_GRAY, GR_VERTEX_BLACK }
gr_vertex_color_t;
-typedef std::pair<gr_block_sptr, gr_vertex_color_t> gr_vertex_t;
-typedef std::vector<gr_vertex_t> gr_vertex_vector_t;
-typedef std::vector<gr_vertex_t>::iterator gr_vertex_vector_iterator_t;
-
#define GR_FIXED_BUFFER_SIZE (32*(1L<<10))
// Implements container primitives
@@ -82,14 +75,13 @@
void create_block_list();
void connect_blocks();
gr_buffer_sptr allocate_buffer(gr_block_sptr block, int port);
- void reachable_dfs_visit(gr_block_sptr block, gr_vertex_vector_t
&vertices);
gr_block_vector_t topological_sort(gr_block_vector_t blocks);
-
std::vector<int> calc_used_ports(gr_block_sptr block, bool direction);
gr_block_vector_t calc_downstream_blocks(gr_endpoint_t src);
gr_edge_vector_t calc_input_edges(gr_block_sptr block);
- gr_block_vector_t calc_reachable_vertices(gr_block_sptr block,
gr_block_vector_t &blocks);
- gr_vertex_vector_t calc_adjacent_vertices(gr_vertex_t vertex,
gr_vertex_vector_t &vertices);
+ gr_block_vector_t calc_reachable_blocks(gr_block_sptr block,
gr_block_vector_t &blocks);
+ void reachable_dfs_visit(gr_block_sptr block, gr_block_vector_t &blocks);
+ gr_block_vector_t calc_adjacent_blocks(gr_block_sptr block,
gr_block_vector_t &blocks);
// Private data
static const int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE;
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.cc
2006-10-17 16:21:32 UTC (rev 3802)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.cc
2006-10-17 17:56:37 UTC (rev 3803)
@@ -31,6 +31,7 @@
}
gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) :
+ omni_thread(NULL, PRIORITY_NORMAL),
d_sts(gr_make_single_threaded_scheduler(graph))
{
// NOP
@@ -41,9 +42,16 @@
// NOP
}
-void gr_scheduler_thread::run(void *arg)
+void gr_scheduler_thread::start()
{
+ start_undetached();
+}
+
+void *gr_scheduler_thread::run_undetached(void *arg)
+{
+#if GR_SCHEDULER_DEBUG
cout << "Running thread..." << endl;
+#endif
d_sts->run();
}
@@ -60,8 +68,9 @@
gr_scheduler::gr_scheduler(gr_basic_flowgraph_sptr fg)
{
gr_block_vector_vector_t graphs = fg->calc_partitions();
+#if GR_SCHEDULER_DEBUG
cout << "Flowgraph has " << graphs.size() << " sub-graphs." << endl;
-
+#endif
gr_block_vector_vector_iterator_t graph_iter;
for (graph_iter = graphs.begin(); graph_iter != graphs.end(); graph_iter++)
d_threads.push_back(gr_make_scheduler_thread(*graph_iter));
@@ -74,8 +83,9 @@
void gr_scheduler::start()
{
- cout << "There are " << d_threads.size() << " to run." << endl;
-
+#if GR_SCHEDULER_DEBUG
+ cout << "There are " << d_threads.size() << " threads to run." << endl;
+#endif
gr_scheduler_thread_vector_iterator_t thread_iter;
for (thread_iter = d_threads.begin(); thread_iter != d_threads.end();
thread_iter++)
(*thread_iter)->start();
@@ -87,13 +97,12 @@
void gr_scheduler::wait()
{
- // Until join() exception is solved below
- while(1);
-
gr_scheduler_thread_vector_iterator_t thread_iter;
for (thread_iter = d_threads.begin(); thread_iter != d_threads.end();
thread_iter++) {
while(1) {
- printf("thread state is %i\n", (*thread_iter)->state());
+#if GR_SCHEDULER_DEBUG
+ cout << "Thread state is " << (*thread_iter)->state() << endl;
+#endif
(*thread_iter)->join(NULL);
if (!(*thread_iter)->state() == omni_thread::STATE_TERMINATED)
break;
Modified:
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.h
===================================================================
---
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.h
2006-10-17 16:21:32 UTC (rev 3802)
+++
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_scheduler.h
2006-10-17 17:56:37 UTC (rev 3803)
@@ -22,6 +22,8 @@
#ifndef INCLUDED_GR_SCHEDULER_H
#define INCLUDED_GR_SCHEDULER_H
+#define GR_SCHEDULER_DEBUG 1
+
#include <gr_flow_graph.h>
#include <omnithread.h>
#include <gr_single_threaded_scheduler.h>
@@ -44,7 +46,8 @@
public:
~gr_scheduler_thread();
- virtual void run(void *arg);
+ virtual void *run_undetached(void *arg);
+ void start();
void stop();
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r3803 - gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++,
jcorgan <=