3 * Copyright 2008 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 3, 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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <gr_scheduler_tpb.h>
26 #include <gr_tpb_thread_body.h>
27 #include <gruel/thread_body_wrapper.h>
31 * You know, a lambda expression would be sooo much easier...
35 gr_block_sptr d_block;
38 tpb_container(gr_block_sptr block) : d_block(block) {}
42 gr_tpb_thread_body body(d_block);
48 gr_scheduler_tpb::make(gr_flat_flowgraph_sptr ffg)
50 return gr_scheduler_sptr(new gr_scheduler_tpb(ffg));
53 gr_scheduler_tpb::gr_scheduler_tpb(gr_flat_flowgraph_sptr ffg)
56 // Get a topologically sorted vector of all the blocks in use.
57 // Being topologically sorted probably isn't going to matter, but
58 // there's a non-zero chance it might help...
60 gr_basic_block_vector_t used_blocks = ffg->calc_used_blocks();
61 used_blocks = ffg->topological_sort(used_blocks);
62 gr_block_vector_t blocks = gr_flat_flowgraph::make_block_vector(used_blocks);
64 // Ensure that the done flag is clear on all blocks
66 for (size_t i = 0; i < blocks.size(); i++){
67 blocks[i]->detail()->set_done(false);
70 // Fire off a thead for each block
72 for (size_t i = 0; i < blocks.size(); i++){
73 std::stringstream name;
74 name << "thread-per-block[" << i << "]: " << blocks[i];
75 d_threads.create_thread(
76 gruel::thread_body_wrapper<tpb_container>(tpb_container(blocks[i]), name.str()));
80 gr_scheduler_tpb::~gr_scheduler_tpb()
86 gr_scheduler_tpb::stop()
88 d_threads.interrupt_all();
92 gr_scheduler_tpb::wait()