3 * Copyright 2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #define GR_RUNTIME_IMPL_DEBUG 0
29 #include <gr_runtime_impl.h>
30 #include <gr_simple_flowgraph.h>
31 #include <gr_hier_block2.h>
32 #include <gr_hier_block2_detail.h>
36 gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) :
38 d_top_block(top_block),
39 d_sfg(gr_make_simple_flowgraph()),
44 gr_runtime_impl::~gr_runtime_impl()
49 gr_runtime_impl::start()
52 throw std::runtime_error("already running");
56 d_sfg->d_detail->reset();
57 d_top_block->d_detail->flatten(d_sfg);
58 d_sfg->d_detail->validate();
59 d_sfg->d_detail->setup_connections();
61 d_graphs = d_sfg->d_detail->partition();
62 if (GR_RUNTIME_IMPL_DEBUG)
63 std::cout << "Flow graph has " << d_graphs.size()
64 << " sub-graphs." << std::endl;
67 for (std::vector<gr_block_vector_t>::iterator p = d_graphs.begin();
68 p != d_graphs.end(); p++) {
69 gr_scheduler_thread_sptr thread = gr_make_scheduler_thread(*p);
71 d_threads.push_back(thread);
76 gr_runtime_impl::stop()
81 for (gr_scheduler_thread_viter_t p = d_threads.begin();
82 p != d_threads.end(); p++)
89 gr_runtime_impl::wait()
91 for (gr_scheduler_thread_viter_t p = d_threads.begin();
92 p != d_threads.end(); p++) {
95 if (!(*p)->state() == omni_thread::STATE_TERMINATED)
101 gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph)
103 return gr_scheduler_thread_sptr(new gr_scheduler_thread(graph));
106 gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) :
107 omni_thread(NULL, PRIORITY_NORMAL),
108 d_sts(gr_make_single_threaded_scheduler(graph))
112 gr_scheduler_thread::~gr_scheduler_thread()
116 void gr_scheduler_thread::start()
121 void *gr_scheduler_thread::run_undetached(void *arg)
127 void gr_scheduler_thread::stop()