[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8790 - gnuradio/branches/developers/eb/sched-wip/gnur
From: |
eb |
Subject: |
[Commit-gnuradio] r8790 - gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime |
Date: |
Fri, 4 Jul 2008 11:06:25 -0600 (MDT) |
Author: eb
Date: 2008-07-04 11:06:24 -0600 (Fri, 04 Jul 2008)
New Revision: 8790
Added:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.h
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h
Removed:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h
Modified:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/Makefile.am
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_detail.h
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_executor.cc
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_executor.h
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_flowgraph.h
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
Log:
work-in-progress on thread-per-block scheduler
Modified:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/Makefile.am
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/Makefile.am
2008-07-04 16:58:23 UTC (rev 8789)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/Makefile.am
2008-07-04 17:06:24 UTC (rev 8790)
@@ -51,14 +51,16 @@
gr_realtime.cc \
gr_scheduler.cc \
gr_scheduler_sts.cc \
- gr_scheduler_thread.cc \
+ gr_scheduler_tpb.cc \
gr_single_threaded_scheduler.cc \
gr_sync_block.cc \
gr_sync_decimator.cc \
gr_sync_interpolator.cc \
+ gr_tmp_path.cc \
gr_top_block.cc \
gr_top_block_impl.cc \
- gr_tmp_path.cc \
+ gr_tpb_detail.cc \
+ gr_tpb_thread_body.cc \
gr_vmcircbuf.cc \
gr_vmcircbuf_mmap_shm_open.cc \
gr_vmcircbuf_mmap_tmpfile.cc \
@@ -100,7 +102,7 @@
gr_runtime_types.h \
gr_scheduler.h \
gr_scheduler_sts.h \
- gr_scheduler_thread.h \
+ gr_scheduler_tpb.h \
gr_select_handler.h \
gr_single_threaded_scheduler.h \
gr_sync_block.h \
@@ -108,6 +110,8 @@
gr_sync_interpolator.h \
gr_top_block.h \
gr_top_block_impl.h \
+ gr_tpb_detail.h \
+ gr_tpb_thread_body.h \
gr_timer.h \
gr_tmp_path.h \
gr_types.h \
Modified:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_detail.h
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_detail.h
2008-07-04 16:58:23 UTC (rev 8789)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_detail.h
2008-07-04 17:06:24 UTC (rev 8790)
@@ -24,6 +24,7 @@
#define INCLUDED_GR_BLOCK_DETAIL_H
#include <gr_runtime_types.h>
+#include <gr_tpb_detail.h>
#include <stdexcept>
/*!
@@ -34,7 +35,6 @@
* of almost all users of GNU Radio. This decoupling also means that
* we can make changes to the guts without having to recompile everything.
*/
-
class gr_block_detail {
public:
~gr_block_detail ();
@@ -75,6 +75,9 @@
void produce_each (int how_many_items);
+
+ gr_tpb_detail d_tpb; // used by
thread-per-block scheduler
+
//
----------------------------------------------------------------------------
private:
@@ -84,8 +87,11 @@
std::vector<gr_buffer_sptr> d_output;
bool d_done;
+
gr_block_detail (unsigned int ninputs, unsigned int noutputs);
+ friend class gr_tpb_detail;
+
friend gr_block_detail_sptr
gr_make_block_detail (unsigned int ninputs, unsigned int noutputs);
};
Modified:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_executor.cc
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_executor.cc
2008-07-04 16:58:23 UTC (rev 8789)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_executor.cc
2008-07-04 17:06:24 UTC (rev 8790)
@@ -105,23 +105,19 @@
d_block->stop(); // stop any drivers, etc.
}
-
-bool
+gr_block_executor::state
gr_block_executor::run_one_iteration()
{
- int noutput_items;
- int max_items_avail;
- bool making_progress;
+ int noutput_items;
+ int max_items_avail;
- making_progress = false;
-
gr_block *m = d_block.get();
gr_block_detail *d = m->detail().get();
LOG(*d_log << std::endl << m);
if (d->done())
- goto next_block;
+ return DONE;
if (d->source_p ()){
d_ninput_items_required.resize (0);
@@ -137,7 +133,7 @@
if (noutput_items == 0){ // we're output blocked
LOG(*d_log << " BLKD_OUT\n");
- goto next_block;
+ return BLKD_OUT;
}
goto setup_call_to_work; // jump to common code
@@ -168,7 +164,7 @@
if (noutput_items == 0){ // we're blocked on input
LOG(*d_log << " BLKD_IN\n");
- goto next_block;
+ return BLKD_IN;
}
goto try_again; // Jump to code shared with regular case.
@@ -203,20 +199,9 @@
if (noutput_items == 0){ // we're output blocked
LOG(*d_log << " BLKD_OUT\n");
- goto next_block;
+ return BLKD_OUT;
}
-#if 0
- // Compute best estimate of noutput_items that we can really use.
- noutput_items =
- std::min ((unsigned) noutput_items,
- std::max ((unsigned) m->output_multiple(),
- round_up ((unsigned) (max_items_avail *
m->relative_rate()),
- m->output_multiple ())));
-
- LOG(*d_log << " revised noutput_items = " << noutput_items << std::endl);
-#endif
-
try_again:
if (m->fixed_rate()){
// try to work it forward starting with max_items_avail.
@@ -265,7 +250,7 @@
goto were_done;
}
- goto next_block;
+ return BLKD_IN;
}
// We've got enough data on each input to produce noutput_items.
@@ -290,16 +275,23 @@
d->produce_each (n); // advance write pointers
if (n > 0)
- making_progress = true;
+ return READY;
- goto next_block;
+ // We didn't produce any output even though we called general_work.
+ // Call this BLKD_IN, since we didn't do anything productive.
+ // If this is a source, it's broken.
+ if (d->source_p()){
+ std::cerr << "gr_block_executor: source " << m
+ << " returned 0 from work. We're marking it DONE.\n";
+ // FIXME maybe we ought to raise an exception...
+ goto were_done;
+ }
+ return BLKD_IN;
}
assert (0);
were_done:
LOG(*d_log << " were_done\n");
d->set_done (true);
-
- next_block:
- return making_progress;
+ return DONE;
}
Modified:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_executor.h
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_executor.h
2008-07-04 16:58:23 UTC (rev 8789)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_block_executor.h
2008-07-04 17:06:24 UTC (rev 8790)
@@ -51,11 +51,17 @@
gr_block_executor(gr_block_sptr block);
~gr_block_executor ();
+ enum state {
+ READY, // We made progress; everything's cool.
+ BLKD_IN, // no progress; we're blocked waiting for input data.
+ BLKD_OUT, // no progress; we're blocked waiting for output buffer space.
+ DONE, // we're done; don't call me again.
+ };
+
/*
* \brief Run one iteration.
- * \returns true if progress was made, else false.
*/
- bool run_one_iteration();
+ state run_one_iteration();
};
#endif /* INCLUDED_GR_BLOCK_EXECUTOR_H */
Modified:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_flowgraph.h
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_flowgraph.h
2008-07-04 16:58:23 UTC (rev 8789)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_flowgraph.h
2008-07-04 17:06:24 UTC (rev 8790)
@@ -122,6 +122,9 @@
// Return vector of connected blocks
gr_basic_block_vector_t calc_used_blocks();
+ // Return toplogically sorted vector of blocks. All the sources come first.
+ gr_basic_block_vector_t topological_sort(gr_basic_block_vector_t &blocks);
+
// Return vector of vectors of disjointly connected blocks, topologically
// sorted.
std::vector<gr_basic_block_vector_t> partition();
@@ -149,7 +152,6 @@
gr_basic_block_vector_t calc_reachable_blocks(gr_basic_block_sptr block,
gr_basic_block_vector_t &blocks);
void reachable_dfs_visit(gr_basic_block_sptr block, gr_basic_block_vector_t
&blocks);
gr_basic_block_vector_t calc_adjacent_blocks(gr_basic_block_sptr block,
gr_basic_block_vector_t &blocks);
- gr_basic_block_vector_t topological_sort(gr_basic_block_vector_t &blocks);
gr_basic_block_vector_t sort_sources_first(gr_basic_block_vector_t &blocks);
bool source_p(gr_basic_block_sptr block);
void topological_dfs_visit(gr_basic_block_sptr block,
gr_basic_block_vector_t &output);
Modified:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h
2008-07-04 16:58:23 UTC (rev 8789)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h
2008-07-04 17:06:24 UTC (rev 8790)
@@ -29,7 +29,6 @@
*/
class gr_scheduler_sts : public gr_scheduler
{
- std::vector<gr_basic_block_vector_t> d_graphs;
boost::thread_group d_threads;
protected:
Deleted:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc
Deleted:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h
Copied:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc
(from rev 8765,
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc)
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc
(rev 0)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc
2008-07-04 17:06:24 UTC (rev 8790)
@@ -0,0 +1,89 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <gr_scheduler_tpb.h>
+#include <gr_tpb_thread_body.h>
+#include <gruel/thread_body_wrapper.h>
+#include <sstream>
+
+/*
+ * You know, a lambda expression would be sooo much easier...
+ */
+class tpb_container
+{
+ gr_block_sptr d_block;
+
+public:
+ tpb_container(gr_block_sptr block) : d_block(block) {}
+
+ void operator()()
+ {
+ gr_tpb_thread_body body(d_block);
+ }
+};
+
+
+gr_scheduler_sptr
+gr_scheduler_tpb::make(gr_flat_flowgraph_sptr ffg)
+{
+ return gr_scheduler_sptr(new gr_scheduler_tpb(ffg));
+}
+
+gr_scheduler_tpb::gr_scheduler_tpb(gr_flat_flowgraph_sptr ffg)
+ : gr_scheduler(ffg)
+{
+ // Get a topologically sorted vector of all the blocks in use.
+ // Being topologically sorted probably isn't going to matter, but
+ // there's a non-zero chance it might help...
+
+ gr_basic_block_vector_t used_blocks = ffg->calc_used_blocks();
+ used_blocks = ffg->topological_sort(used_blocks);
+ gr_block_vector_t blocks = gr_flat_flowgraph::make_block_vector(used_blocks);
+
+ // Fire off a thead for each block
+
+ for (size_t i = 0; i < blocks.size(); i++){
+ std::stringstream name;
+ name << "thread-per-block[" << i << "]: " << blocks[i];
+ d_threads.create_thread(
+ gruel::thread_body_wrapper<tpb_container>(tpb_container(blocks[i]),
name.str()));
+ }
+}
+
+gr_scheduler_tpb::~gr_scheduler_tpb()
+{
+ stop();
+}
+
+void
+gr_scheduler_tpb::stop()
+{
+ d_threads.interrupt_all();
+}
+
+void
+gr_scheduler_tpb::wait()
+{
+ d_threads.join_all();
+}
Copied:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h
(from rev 8762,
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h)
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h
(rev 0)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h
2008-07-04 17:06:24 UTC (rev 8790)
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_GR_SCHEDULER_TPB_H
+#define INCLUDED_GR_SCHEDULER_TPB_H
+
+#include <gr_scheduler.h>
+#include <boost/thread.hpp>
+
+/*!
+ * \brief Concrete scheduler that uses a kernel thread-per-block
+ */
+class gr_scheduler_tpb : public gr_scheduler
+{
+ boost::thread_group d_threads;
+
+protected:
+ /*!
+ * \brief Construct a scheduler and begin evaluating the graph.
+ *
+ * The scheduler will continue running until all blocks until they
+ * report that they are done or the stop method is called.
+ */
+ gr_scheduler_tpb(gr_flat_flowgraph_sptr ffg);
+
+public:
+ static gr_scheduler_sptr make(gr_flat_flowgraph_sptr ffg);
+
+ ~gr_scheduler_tpb();
+
+ /*!
+ * \brief Tell the scheduler to stop executing.
+ */
+ void stop();
+
+ /*!
+ * \brief Block until the graph is done.
+ */
+ void wait();
+};
+
+
+#endif /* INCLUDED_GR_SCHEDULER_TPB_H */
Modified:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
2008-07-04 16:58:23 UTC (rev 8789)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
2008-07-04 17:06:24 UTC (rev 8790)
@@ -28,6 +28,7 @@
#include <gr_top_block_impl.h>
#include <gr_flat_flowgraph.h>
#include <gr_scheduler_sts.h>
+#include <gr_scheduler_tpb.h>
#include <stdexcept>
#include <iostream>
@@ -36,6 +37,23 @@
#define GR_TOP_BLOCK_IMPL_DEBUG 0
+
+#define USE_STS 0
+#define USE_TPB 1
+
+
+static gr_scheduler_sptr
+make_scheduler(gr_flat_flowgraph_sptr ffg)
+{
+#if (USE_STS)
+ return gr_scheduler_sts::make(ffg);
+#endif
+#if (USE_TPB)
+ return gr_scheduler_tpb::make(ffg);
+#endif
+}
+
+
gr_top_block_impl::gr_top_block_impl(gr_top_block *owner)
: d_owner(owner), d_ffg(),
d_state(IDLE), d_lock_count(0)
@@ -65,7 +83,7 @@
d_ffg->validate();
d_ffg->setup_connections();
- d_scheduler = gr_scheduler_sts::make(d_ffg);
+ d_scheduler = make_scheduler(d_ffg);
d_state = RUNNING;
}
@@ -128,7 +146,7 @@
d_ffg = new_ffg;
// Create a new scheduler to execute it
- d_scheduler = gr_scheduler_sts::make(d_ffg);
+ d_scheduler = make_scheduler(d_ffg);
d_state = RUNNING;
}
Added:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc
(rev 0)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc
2008-07-04 17:06:24 UTC (rev 8790)
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <gr_tpb_detail.h>
+#include <gr_block_detail.h>
+
+/*
+ * We assume that no worker threads are ever running when the
+ * graph structure is being manipulated, thus it's safe for us to poke
+ * around in our neighbors w/o holding any locks.
+ */
+
+void
+gr_tpb_detail::notify_upstream(gr_block_detail *d)
+{
+ // For each of our inputs, tell the guy upstream that we've consumed
+ // some input, and that he most likely has more output buffer space
+ // available.
+
+ for (size_t i = 0; i < d->d_input.size(); i++){
+ }
+}
+
+void
+gr_tpb_detail::notify_downstream(gr_block_detail *d)
+{
+}
+
Property changes on:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.h
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.h
(rev 0)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.h
2008-07-04 17:06:24 UTC (rev 8790)
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_GR_TPB_DETAIL_H
+#define INCLUDED_GR_TPB_DETAIL_H
+
+#include <boost/thread.hpp>
+
+class gr_block_detail;
+
+/*!
+ * \brief used by thread-per-block scheduler
+ */
+struct gr_tpb_detail {
+ typedef boost::unique_lock<boost::mutex> scoped_lock;
+
+ boost::mutex mutex; //< protects all vars
+ bool input_changed;
+ boost::condition_variable input_cond;
+ bool output_changed;
+ boost::condition_variable output_cond;
+
+ gr_tpb_detail()
+ : input_changed(false), output_changed(false) {}
+
+
+ //! Called by us to tell all our upstream blocks that their output may have
changed.
+ void notify_upstream(gr_block_detail *d);
+
+ //! Called by us to tell all our downstream blocks that their input may have
changed.
+ void notify_downstream(gr_block_detail *d);
+
+ //! Called by us
+ void clear_changed()
+ {
+ scoped_lock guard(mutex);
+ input_changed = false;
+ output_changed = false;
+ }
+
+private:
+
+ //! Used by notify_downstream
+ void set_input_changed()
+ {
+ scoped_lock guard(mutex);
+ input_changed = true;
+ input_cond.notify_one();
+ }
+
+ //! Used by notify_upstream
+ void set_output_changed()
+ {
+ scoped_lock guard(mutex);
+ output_changed = true;
+ output_cond.notify_one();
+ }
+
+};
+
+#endif /* INCLUDED_GR_TPB_DETAIL_H */
Property changes on:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_detail.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc
(rev 0)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc
2008-07-04 17:06:24 UTC (rev 8790)
@@ -0,0 +1,72 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <gr_tpb_thread_body.h>
+#include <iostream>
+
+gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block)
+ : d_exec(block)
+{
+ // std::cerr << "gr_tpb_thread_body: " << block << std::endl;
+
+ gr_block_detail *d = block->detail().get();
+ gr_block_executor::state s;
+
+ while (1){
+ d->d_tpb.clear_changed();
+ s = d_exec.run_one_iteration();
+
+ switch(s){
+ case gr_block_executor::READY: // Tell neighbors we made
progress.
+ d->d_tpb.notify_downstream(d);
+ d->d_tpb.notify_upstream(d);
+ break;
+
+ case gr_block_executor::DONE: // Game over.
+ return;
+
+ case gr_block_executor::BLKD_IN: // Wait for input.
+ {
+ gr_tpb_detail::scoped_lock guard(d->d_tpb.mutex);
+ while(!d->d_tpb.input_changed)
+ d->d_tpb.input_cond.wait(guard);
+ }
+ break;
+
+ case gr_block_executor::BLKD_OUT: // Wait for output buffer space.
+ {
+ gr_tpb_detail::scoped_lock guard(d->d_tpb.mutex);
+ while(!d->d_tpb.output_changed)
+ d->d_tpb.output_cond.wait(guard);
+ }
+ break;
+
+ default:
+ assert(0);
+ }
+ }
+}
+
+gr_tpb_thread_body::~gr_tpb_thread_body()
+{
+}
Property changes on:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h
===================================================================
---
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h
(rev 0)
+++
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h
2008-07-04 17:06:24 UTC (rev 8790)
@@ -0,0 +1,45 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_GR_TPB_THREAD_BODY_H
+#define INCLUDED_GR_TPB_THREAD_BODY_H
+
+#include <gr_block_executor.h>
+#include <gr_block.h>
+#include <gr_block_detail.h>
+
+/*!
+ * \brief The body of each thread-per-block thread.
+ *
+ * One of these is instantiated in its own thread for each block. The
+ * constructor turns into the main loop which returns when the block is
+ * done or is interrupted.
+ */
+
+class gr_tpb_thread_body {
+ gr_block_executor d_exec;
+
+public:
+ gr_tpb_thread_body(gr_block_sptr block);
+ ~gr_tpb_thread_body();
+};
+
+
+#endif /* INCLUDED_GR_TPB_THREAD_BODY_H */
Property changes on:
gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h
___________________________________________________________________
Name: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8790 - gnuradio/branches/developers/eb/sched-wip/gnuradio-core/src/lib/runtime,
eb <=