diff options
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/general/gr_head.cc | 6 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_head.h | 11 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_head.i | 14 | ||||
-rw-r--r-- | gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t | 5 | ||||
-rw-r--r-- | gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t | 5 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.cc | 8 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.h | 19 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block_detail.cc | 18 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block_detail.h | 10 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block_executor.cc | 13 |
10 files changed, 78 insertions, 31 deletions
diff --git a/gnuradio-core/src/lib/general/gr_head.cc b/gnuradio-core/src/lib/general/gr_head.cc index 94a00cc68..01035ffcd 100644 --- a/gnuradio-core/src/lib/general/gr_head.cc +++ b/gnuradio-core/src/lib/general/gr_head.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -35,10 +35,10 @@ gr_head::gr_head (size_t sizeof_stream_item, int nitems) { } -gr_block_sptr +gr_head_sptr gr_make_head (size_t sizeof_stream_item, int nitems) { - return gr_block_sptr (new gr_head (sizeof_stream_item, nitems)); + return gnuradio::get_initial_sptr(new gr_head (sizeof_stream_item, nitems)); } int diff --git a/gnuradio-core/src/lib/general/gr_head.h b/gnuradio-core/src/lib/general/gr_head.h index cd97d6399..430d5f8b9 100644 --- a/gnuradio-core/src/lib/general/gr_head.h +++ b/gnuradio-core/src/lib/general/gr_head.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,6 +26,9 @@ #include <gr_sync_block.h> #include <stddef.h> // size_t +class gr_head; +typedef boost::shared_ptr<gr_head> gr_head_sptr; + /*! * \brief copies the first N items to the output then signals done * \ingroup slicedice_blk @@ -35,7 +38,7 @@ class gr_head : public gr_sync_block { - friend gr_block_sptr gr_make_head (size_t sizeof_stream_item, int nitems); + friend gr_head_sptr gr_make_head (size_t sizeof_stream_item, int nitems); gr_head (size_t sizeof_stream_item, int nitems); int d_nitems; @@ -45,9 +48,11 @@ class gr_head : public gr_sync_block int work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + + void reset() { d_ncopied_items = 0; } }; -gr_block_sptr +gr_head_sptr gr_make_head (size_t sizeof_stream_item, int nitems); diff --git a/gnuradio-core/src/lib/general/gr_head.i b/gnuradio-core/src/lib/general/gr_head.i index 324bb08ec..2a88b885f 100644 --- a/gnuradio-core/src/lib/general/gr_head.i +++ b/gnuradio-core/src/lib/general/gr_head.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,11 +20,13 @@ * Boston, MA 02110-1301, USA. */ -%ignore gr_head; +GR_SWIG_BLOCK_MAGIC(gr,head); + +gr_head_sptr gr_make_head(size_t sizeof_stream_item, int nitems); + class gr_head : public gr_block { - friend gr_block_sptr gr_make_head (size_t sizeof_stream_item, int nitems); - gr_head (size_t sizeof_stream_item, int nitems); + gr_head(); +public: + void reset(); }; -%rename(head) gr_make_head; -gr_block_sptr gr_make_head (size_t sizeof_stream_item, int nitems); diff --git a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t index b5fdf88fd..7ba5ee9e9 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -50,7 +50,8 @@ class @NAME@ : public gr_sync_block { gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); - void clear() {d_data.clear();} + void reset() {d_data.clear();} + void clear() {reset(); } // deprecated std::vector<@TYPE@> data () const; }; diff --git a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t index 22d6faa1a..a49276a99 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -32,7 +32,8 @@ class @NAME@ : public gr_sync_block { @NAME@ (int vlen); public: - void clear() {d_data.clear();} + void clear(); // deprecated + void reset(); std::vector<@TYPE@> data () const; }; diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index b8b1bd9c7..8915f3360 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -99,6 +99,12 @@ gr_block::consume_each (int how_many_items) d_detail->consume_each (how_many_items); } +void +gr_block::produce (int which_output, int how_many_items) +{ + d_detail->produce (which_output, how_many_items); +} + int gr_block::fixed_rate_ninput_to_noutput(int ninput) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 354695c0b..b6f724dde 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2007 Free Software Foundation, Inc. + * Copyright 2004,2007,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -57,6 +57,12 @@ class gr_block : public gr_basic_block { public: + //! Magic return values from general_work + enum { + WORK_CALLED_PRODUCE = -2, + WORK_DONE = -1 + }; + virtual ~gr_block (); /*! @@ -70,7 +76,7 @@ class gr_block : public gr_basic_block { void set_history (unsigned history) { d_history = history; } /*! - * \brief return true if this block has a fixed input to output rate + * \brief Return true if this block has a fixed input to output rate. * * If true, then fixed_rate_in_to_out and fixed_rate_out_to_in may be called. */ @@ -150,6 +156,13 @@ class gr_block : public gr_basic_block { void consume_each (int how_many_items); /*! + * \brief Tell the scheduler \p how_many_items were produced on output stream \p which_output. + * + * If the block's general_work method calls produce, \p general_work must return WORK_CALLED_PRODUCE. + */ + void produce (int which_output, int how_many_items); + + /*! * \brief Set the approximate output rate / input rate * * Provide a hint to the buffer allocator and scheduler. @@ -191,7 +204,7 @@ class gr_block : public gr_basic_block { int d_output_multiple; double d_relative_rate; // approx output_rate / input_rate - gr_block_detail_sptr d_detail; // implementation details + gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index d33dfed84..38d4a13ca 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -36,7 +36,8 @@ gr_block_detail_ncurrently_allocated () } gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) - : d_ninputs (ninputs), d_noutputs (noutputs), + : d_produce_or(0), + d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), d_done (false) { @@ -100,11 +101,22 @@ gr_block_detail::consume_each (int how_many_items) } void +gr_block_detail::produce (int which_output, int how_many_items) +{ + if (how_many_items > 0){ + d_output[which_output]->update_write_pointer (how_many_items); + d_produce_or |= how_many_items; + } +} + +void gr_block_detail::produce_each (int how_many_items) { - if (how_many_items > 0) + if (how_many_items > 0){ for (int i = 0; i < noutputs (); i++) d_output[i]->update_write_pointer (how_many_items); + d_produce_or |= how_many_items; + } } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 9d6358602..c5787a5ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -74,18 +74,22 @@ class gr_block_detail { void consume_each (int how_many_items); /*! + * \brief Tell the scheduler \p how_many_items were produced on output stream \p which_output. + */ + void produce (int which_output, int how_many_items); + + /*! * \brief Tell the scheduler \p how_many_items were produced on each output stream. */ void produce_each (int how_many_items); - /*! * Accept msg, place in queue, arrange for thread to be awakened if it's not already. */ void _post(pmt::pmt_t msg); - gr_tpb_detail d_tpb; // used by thread-per-block scheduler + int d_produce_or; // ---------------------------------------------------------------------------- diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index e8d30b963..2c21a0b0f 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -290,6 +290,7 @@ gr_block_executor::run_one_iteration() setup_call_to_work: + d->d_produce_or = 0; for (int i = 0; i < d->noutputs (); i++) d_output_items[i] = d->output(i)->write_pointer(); @@ -299,11 +300,13 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - if (n == -1) // block is done + if (n == gr_block::WORK_DONE) goto were_done; - d->produce_each (n); // advance write pointers - if (n > 0) + if (n != gr_block::WORK_CALLED_PRODUCE) + d->produce_each (n); // advance write pointers + + if (d->d_produce_or > 0) // block produced something return READY; // We didn't produce any output even though we called general_work. @@ -312,7 +315,7 @@ gr_block_executor::run_one_iteration() // 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"; + << " produced no output. We're marking it DONE.\n"; // FIXME maybe we ought to raise an exception... goto were_done; } |