diff options
author | Marcus Müller <marcus.mueller@ettus.com> | 2015-08-30 15:00:51 +0200 |
---|---|---|
committer | Marcus Müller <marcus.mueller@ettus.com> | 2015-08-30 15:00:51 +0200 |
commit | 90ba3ea311f4c395366fdafe36b1a9d416c70cc5 (patch) | |
tree | fac82b9f261c2d2c053006003f066d79122dc040 | |
parent | 31de0f5d7542e1d323af399a022bc59c54d00de6 (diff) |
Provided thread safety to dynamic repeat
... by wrapping the actual setter in a message handler and writing a
delegate _post()er.
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/repeat.h | 4 | ||||
-rw-r--r-- | gr-blocks/lib/repeat_impl.cc | 17 | ||||
-rw-r--r-- | gr-blocks/lib/repeat_impl.h | 2 |
3 files changed, 21 insertions, 2 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/repeat.h b/gr-blocks/include/gnuradio/blocks/repeat.h index 1de2a74417..b34bda1ec5 100644 --- a/gr-blocks/include/gnuradio/blocks/repeat.h +++ b/gr-blocks/include/gnuradio/blocks/repeat.h @@ -32,6 +32,10 @@ namespace gr { /*! * \brief repeat each input \p repeat times * \ingroup stream_operators_blk + * + * Message Ports: + * * interpolation (in): + * Takes a pmt_pair(pmt::mp("interpolation"), pmt_long interp), setting the interpolation to interp. */ class BLOCKS_API repeat : virtual public sync_interpolator { diff --git a/gr-blocks/lib/repeat_impl.cc b/gr-blocks/lib/repeat_impl.cc index b32efef4bf..fb62265134 100644 --- a/gr-blocks/lib/repeat_impl.cc +++ b/gr-blocks/lib/repeat_impl.cc @@ -43,13 +43,26 @@ namespace gr { d_itemsize(itemsize), d_interp(interp) { + message_port_register_in(pmt::mp("interpolation")); + set_msg_handler(pmt::mp("interpolation"), + boost::bind(&repeat_impl::msg_set_interpolation, this, _1)); } void + repeat_impl::msg_set_interpolation(pmt::pmt_t msg) + { + // Dynamization by Kevin McQuiggin: + d_interp = pmt::to_long(pmt::cdr(msg)); + sync_interpolator::set_interpolation(d_interp); + } + void repeat_impl::set_interpolation(int interp) { - d_interp = interp; - sync_interpolator::set_interpolation(d_interp); + // This ensures that interpolation is only changed between calls to work + // (and not in the middle of an ongoing work) + _post( pmt::mp("interpolation"), /* port */ + pmt::cons(pmt::mp("interpolation"), pmt::from_long(interp)) /* pair */ + ); } int diff --git a/gr-blocks/lib/repeat_impl.h b/gr-blocks/lib/repeat_impl.h index 2f4f411b82..486a47a1ad 100644 --- a/gr-blocks/lib/repeat_impl.h +++ b/gr-blocks/lib/repeat_impl.h @@ -43,6 +43,8 @@ namespace gr { int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + private: + void msg_set_interpolation(pmt::pmt_t msg); }; } /* namespace blocks */ |