From 5d69a524f81f234b3fbc41d49ba18d6f6886baba Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 3 Aug 2006 04:51:51 +0000 Subject: Houston, we have a trunk. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3122 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 109 +++++++ gnuradio-core/src/lib/runtime/gr_block.cc | 131 ++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 247 ++++++++++++++ gnuradio-core/src/lib/runtime/gr_block.i | 66 ++++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 108 +++++++ gnuradio-core/src/lib/runtime/gr_block_detail.h | 99 ++++++ gnuradio-core/src/lib/runtime/gr_block_detail.i | 66 ++++ gnuradio-core/src/lib/runtime/gr_buffer.cc | 248 ++++++++++++++ gnuradio-core/src/lib/runtime/gr_buffer.h | 196 +++++++++++ gnuradio-core/src/lib/runtime/gr_buffer.i | 63 ++++ gnuradio-core/src/lib/runtime/gr_complex.h | 46 +++ gnuradio-core/src/lib/runtime/gr_dispatcher.cc | 192 +++++++++++ gnuradio-core/src/lib/runtime/gr_dispatcher.h | 67 ++++ gnuradio-core/src/lib/runtime/gr_dispatcher.i | 55 ++++ gnuradio-core/src/lib/runtime/gr_error_handler.cc | 244 ++++++++++++++ gnuradio-core/src/lib/runtime/gr_error_handler.h | 114 +++++++ gnuradio-core/src/lib/runtime/gr_error_handler.i | 69 ++++ gnuradio-core/src/lib/runtime/gr_io_signature.cc | 54 ++++ gnuradio-core/src/lib/runtime/gr_io_signature.h | 65 ++++ gnuradio-core/src/lib/runtime/gr_io_signature.i | 49 +++ .../src/lib/runtime/gr_local_sighandler.cc | 186 +++++++++++ .../src/lib/runtime/gr_local_sighandler.h | 60 ++++ gnuradio-core/src/lib/runtime/gr_message.cc | 77 +++++ gnuradio-core/src/lib/runtime/gr_message.h | 89 +++++ gnuradio-core/src/lib/runtime/gr_message.i | 65 ++++ gnuradio-core/src/lib/runtime/gr_msg_handler.cc | 30 ++ gnuradio-core/src/lib/runtime/gr_msg_handler.h | 41 +++ gnuradio-core/src/lib/runtime/gr_msg_handler.i | 32 ++ gnuradio-core/src/lib/runtime/gr_msg_queue.cc | 127 ++++++++ gnuradio-core/src/lib/runtime/gr_msg_queue.h | 89 +++++ gnuradio-core/src/lib/runtime/gr_msg_queue.i | 111 +++++++ gnuradio-core/src/lib/runtime/gr_pagesize.cc | 56 ++++ gnuradio-core/src/lib/runtime/gr_pagesize.h | 32 ++ gnuradio-core/src/lib/runtime/gr_preferences.cc | 101 ++++++ gnuradio-core/src/lib/runtime/gr_preferences.h | 32 ++ gnuradio-core/src/lib/runtime/gr_realtime.cc | 71 ++++ gnuradio-core/src/lib/runtime/gr_realtime.h | 39 +++ gnuradio-core/src/lib/runtime/gr_realtime.i | 4 + gnuradio-core/src/lib/runtime/gr_runtime.h | 44 +++ gnuradio-core/src/lib/runtime/gr_select_handler.cc | 36 +++ gnuradio-core/src/lib/runtime/gr_select_handler.h | 83 +++++ .../lib/runtime/gr_single_threaded_scheduler.cc | 360 +++++++++++++++++++++ .../src/lib/runtime/gr_single_threaded_scheduler.h | 61 ++++ .../src/lib/runtime/gr_single_threaded_scheduler.i | 52 +++ .../src/lib/runtime/gr_swig_block_magic.i | 45 +++ gnuradio-core/src/lib/runtime/gr_timer.h | 82 +++++ gnuradio-core/src/lib/runtime/gr_tmp_path.cc | 52 +++ gnuradio-core/src/lib/runtime/gr_tmp_path.h | 31 ++ gnuradio-core/src/lib/runtime/gr_types.h | 63 ++++ gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc | 291 +++++++++++++++++ gnuradio-core/src/lib/runtime/gr_vmcircbuf.h | 120 +++++++ .../lib/runtime/gr_vmcircbuf_createfilemapping.cc | 191 +++++++++++ .../lib/runtime/gr_vmcircbuf_createfilemapping.h | 74 +++++ .../src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc | 205 ++++++++++++ .../src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h | 65 ++++ .../src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc | 198 ++++++++++++ .../src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h | 65 ++++ .../src/lib/runtime/gr_vmcircbuf_sysv_shm.cc | 192 +++++++++++ .../src/lib/runtime/gr_vmcircbuf_sysv_shm.h | 65 ++++ gnuradio-core/src/lib/runtime/qa_gr_block.cc | 89 +++++ gnuradio-core/src/lib/runtime/qa_gr_block.h | 48 +++ gnuradio-core/src/lib/runtime/qa_gr_buffer.cc | 307 ++++++++++++++++++ gnuradio-core/src/lib/runtime/qa_gr_buffer.h | 53 +++ .../src/lib/runtime/qa_gr_io_signature.cc | 55 ++++ gnuradio-core/src/lib/runtime/qa_gr_io_signature.h | 47 +++ gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc | 40 +++ gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h | 39 +++ gnuradio-core/src/lib/runtime/qa_runtime.cc | 49 +++ gnuradio-core/src/lib/runtime/qa_runtime.h | 37 +++ gnuradio-core/src/lib/runtime/runtime.i | 49 +++ .../src/lib/runtime/test_shared_block_ptr.cc | 53 +++ 71 files changed, 6771 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/Makefile.am create mode 100644 gnuradio-core/src/lib/runtime/gr_block.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_block.h create mode 100644 gnuradio-core/src/lib/runtime/gr_block.i create mode 100644 gnuradio-core/src/lib/runtime/gr_block_detail.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_block_detail.h create mode 100644 gnuradio-core/src/lib/runtime/gr_block_detail.i create mode 100644 gnuradio-core/src/lib/runtime/gr_buffer.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_buffer.h create mode 100644 gnuradio-core/src/lib/runtime/gr_buffer.i create mode 100644 gnuradio-core/src/lib/runtime/gr_complex.h create mode 100644 gnuradio-core/src/lib/runtime/gr_dispatcher.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_dispatcher.h create mode 100644 gnuradio-core/src/lib/runtime/gr_dispatcher.i create mode 100644 gnuradio-core/src/lib/runtime/gr_error_handler.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_error_handler.h create mode 100644 gnuradio-core/src/lib/runtime/gr_error_handler.i create mode 100644 gnuradio-core/src/lib/runtime/gr_io_signature.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_io_signature.h create mode 100644 gnuradio-core/src/lib/runtime/gr_io_signature.i create mode 100644 gnuradio-core/src/lib/runtime/gr_local_sighandler.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_local_sighandler.h create mode 100644 gnuradio-core/src/lib/runtime/gr_message.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_message.h create mode 100644 gnuradio-core/src/lib/runtime/gr_message.i create mode 100644 gnuradio-core/src/lib/runtime/gr_msg_handler.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_msg_handler.h create mode 100644 gnuradio-core/src/lib/runtime/gr_msg_handler.i create mode 100644 gnuradio-core/src/lib/runtime/gr_msg_queue.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_msg_queue.h create mode 100644 gnuradio-core/src/lib/runtime/gr_msg_queue.i create mode 100644 gnuradio-core/src/lib/runtime/gr_pagesize.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_pagesize.h create mode 100644 gnuradio-core/src/lib/runtime/gr_preferences.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_preferences.h create mode 100644 gnuradio-core/src/lib/runtime/gr_realtime.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_realtime.h create mode 100644 gnuradio-core/src/lib/runtime/gr_realtime.i create mode 100644 gnuradio-core/src/lib/runtime/gr_runtime.h create mode 100644 gnuradio-core/src/lib/runtime/gr_select_handler.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_select_handler.h create mode 100644 gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h create mode 100644 gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i create mode 100644 gnuradio-core/src/lib/runtime/gr_swig_block_magic.i create mode 100644 gnuradio-core/src/lib/runtime/gr_timer.h create mode 100644 gnuradio-core/src/lib/runtime/gr_tmp_path.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_tmp_path.h create mode 100644 gnuradio-core/src/lib/runtime/gr_types.h create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf.h create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_block.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_block.h create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_buffer.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_buffer.h create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_io_signature.h create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h create mode 100644 gnuradio-core/src/lib/runtime/qa_runtime.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_runtime.h create mode 100644 gnuradio-core/src/lib/runtime/runtime.i create mode 100644 gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am new file mode 100644 index 000000000..7ee94ba1b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -0,0 +1,109 @@ +# +# Copyright 2003,2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# + +include $(top_srcdir)/Makefile.common + +INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) + +noinst_LTLIBRARIES = libruntime.la libruntime-qa.la + +libruntime_la_LIBADD = \ + $(SHM_OPEN_LIBS) + + +libruntime_la_SOURCES = \ + gr_block.cc \ + gr_block_detail.cc \ + gr_buffer.cc \ + gr_dispatcher.cc \ + gr_error_handler.cc \ + gr_io_signature.cc \ + gr_local_sighandler.cc \ + gr_message.cc \ + gr_msg_handler.cc \ + gr_msg_queue.cc \ + gr_pagesize.cc \ + gr_preferences.cc \ + gr_realtime.cc \ + gr_single_threaded_scheduler.cc \ + gr_tmp_path.cc \ + gr_vmcircbuf.cc \ + gr_vmcircbuf_mmap_shm_open.cc \ + gr_vmcircbuf_mmap_tmpfile.cc \ + gr_vmcircbuf_createfilemapping.cc \ + gr_vmcircbuf_sysv_shm.cc \ + gr_select_handler.cc + +libruntime_qa_la_SOURCES = \ + qa_gr_block.cc \ + qa_gr_buffer.cc \ + qa_gr_io_signature.cc \ + qa_gr_vmcircbuf.cc \ + qa_runtime.cc + +grinclude_HEADERS = \ + gr_block.h \ + gr_block_detail.h \ + gr_buffer.h \ + gr_complex.h \ + gr_dispatcher.h \ + gr_error_handler.h \ + gr_io_signature.h \ + gr_local_sighandler.h \ + gr_message.h \ + gr_msg_handler.h \ + gr_msg_queue.h \ + gr_pagesize.h \ + gr_preferences.h \ + gr_realtime.h \ + gr_runtime.h \ + gr_select_handler.h \ + gr_single_threaded_scheduler.h \ + gr_timer.h \ + gr_tmp_path.h \ + gr_types.h \ + gr_vmcircbuf.h + +noinst_HEADERS = \ + gr_vmcircbuf_mmap_shm_open.h \ + gr_vmcircbuf_mmap_tmpfile.h \ + gr_vmcircbuf_sysv_shm.h \ + gr_vmcircbuf_createfilemapping.h \ + qa_gr_block.h \ + qa_gr_buffer.h \ + qa_gr_io_signature.h \ + qa_gr_vmcircbuf.h \ + qa_runtime.h + +swiginclude_HEADERS = \ + gr_block.i \ + gr_block_detail.i \ + gr_buffer.i \ + gr_dispatcher.i \ + gr_error_handler.i \ + gr_io_signature.i \ + gr_message.i \ + gr_msg_handler.i \ + gr_msg_queue.i \ + gr_realtime.i \ + gr_single_threaded_scheduler.i \ + gr_swig_block_magic.i \ + runtime.i diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc new file mode 100644 index 000000000..8378c8f7d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -0,0 +1,131 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +static long s_next_id = 0; +static long s_ncurrently_allocated = 0; + +long +gr_block_ncurrently_allocated () +{ + return s_ncurrently_allocated; +} + +gr_block::gr_block (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature) + : d_name (name), + d_input_signature (input_signature), + d_output_signature (output_signature), + d_output_multiple (1), + d_relative_rate (1.0), + d_unique_id (s_next_id++), + d_history(1), + d_fixed_rate(false) +{ + s_ncurrently_allocated++; +} + +gr_block::~gr_block () +{ + s_ncurrently_allocated--; +} + +// stub implementation: 1:1 + +void +gr_block::forecast (int noutput_items, gr_vector_int &ninput_items_required) +{ + unsigned ninputs = ninput_items_required.size (); + for (unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = noutput_items; +} + +// default implementation + +bool +gr_block::check_topology (int ninputs, int noutputs) +{ + return true; +} + +bool +gr_block::start() +{ + return true; +} + +bool +gr_block::stop() +{ + return true; +} + +void +gr_block::set_output_multiple (int multiple) +{ + if (multiple < 1) + throw std::invalid_argument ("gr_block::set_output_multiple"); + + d_output_multiple = multiple; +} + +void +gr_block::set_relative_rate (double relative_rate) +{ + if (relative_rate < 0.0) + throw std::invalid_argument ("gr_block::set_relative_rate"); + + d_relative_rate = relative_rate; +} + + +void +gr_block::consume (int which_input, int how_many_items) +{ + d_detail->consume (which_input, how_many_items); +} + +void +gr_block::consume_each (int how_many_items) +{ + d_detail->consume_each (how_many_items); +} + +int +gr_block::fixed_rate_ninput_to_noutput(int ninput) +{ + throw std::runtime_error("Unimplemented"); +} + +int +gr_block::fixed_rate_noutput_to_ninput(int noutput) +{ + throw std::runtime_error("Unimplemented"); +} diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h new file mode 100644 index 000000000..df72e1a3f --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -0,0 +1,247 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_BLOCK_H +#define INCLUDED_GR_BLOCK_H + +#include +#include + +/*! + * \brief The abstract base class for all signal processing blocks. + * \ingroup block + * + * Blocks have a set of input streams and output streams. The + * input_signature and output_signature define the number of input + * streams and output streams respectively, and the type of the data + * items in each stream. + * + * Although blocks may consume data on each input stream at a + * different rate, all outputs streams must produce data at the same + * rate. That rate may be different from any of the input rates. + * + * User derived blocks override two methods, forecast and general_work, + * to implement their signal processing behavior. forecast is called + * by the system scheduler to determine how many items are required on + * each input stream in order to produce a given number of output + * items. + * + * general_work is called to perform the signal processing in the block. + * It reads the input items and writes the output items. + */ + +class gr_block { + + public: + + virtual ~gr_block (); + + std::string name () const { return d_name; } + gr_io_signature_sptr input_signature () const { return d_input_signature; } + gr_io_signature_sptr output_signature () const { return d_output_signature; } + long unique_id () const { return d_unique_id; } + + /*! + * Assume block computes y_i = f(x_i, x_i-1, x_i-2, x_i-3...) + * History is the number of x_i's that are examined to produce one y_i. + * This comes in handy for FIR filters, where we use history to + * ensure that our input contains the appropriate "history" for the + * filter. History should be equal to the number of filter taps. + */ + unsigned history () const { return d_history; } + void set_history (unsigned history) { d_history = history; } + + /*! + * \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. + */ + bool fixed_rate() const { return d_fixed_rate; } + + // ---------------------------------------------------------------- + // override these to define your behavior + // ---------------------------------------------------------------- + + /*! + * \brief Estimate input requirements given output request + * + * \param noutput_items number of output items to produce + * \param ninput_items_required number of input items required on each input stream + * + * Given a request to product \p noutput_items, estimate the number of + * data items required on each input stream. The estimate doesn't have + * to be exact, but should be close. + */ + virtual void forecast (int noutput_items, + gr_vector_int &ninput_items_required); + + /*! + * \brief compute output items from input items + * + * \param noutput_items number of output items to write on each output stream + * \param ninput_items number of input items available on each input stream + * \param input_items vector of pointers to the input items, one entry per input stream + * \param output_items vector of pointers to the output items, one entry per output stream + * + * \returns number of items actually written to each output stream, or -1 on EOF. + * It is OK to return a value less than noutput_items. -1 <= return value <= noutput_items + * + * general_work must call consume or consume_each to indicate how many items + * were consumed on each input stream. + */ + virtual int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) = 0; + + /*! + * \brief Confirm that ninputs and noutputs is an acceptable combination. + * + * \param ninputs number of input streams connected + * \param noutputs number of output streams connected + * + * \returns true if this is a valid configuration for this block. + * + * This function is called by the runtime system whenever the + * topology changes. Most classes do not need to override this. + * This check is in addition to the constraints specified by the input + * and output gr_io_signatures. + */ + virtual bool check_topology (int ninputs, int noutputs); + + /*! + * \brief Called to enable drivers, etc for i/o devices. + * + * This allows a block to enable an associated driver to begin + * transfering data just before we start to execute the scheduler. + * The end result is that this reduces latency in the pipeline when + * dealing with audio devices, usrps, etc. + */ + virtual bool start(); + + /*! + * \brief Called to disable drivers, etc for i/o devices. + */ + virtual bool stop(); + + // ---------------------------------------------------------------- + + /*! + * \brief Constrain the noutput_items argument passed to forecast and general_work + * + * set_output_multiple causes the scheduler to ensure that the noutput_items + * argument passed to forecast and general_work will be an integer multiple + * of \param multiple The default value of output multiple is 1. + */ + void set_output_multiple (int multiple); + int output_multiple () const { return d_output_multiple; } + + /*! + * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed. + */ + void consume (int which_input, int how_many_items); + + /*! + * \brief Tell the scheduler \p how_many_items were consumed on each input stream. + */ + void consume_each (int how_many_items); + + /*! + * \brief Set the approximate output rate / input rate + * + * Provide a hint to the buffer allocator and scheduler. + * The default relative_rate is 1.0 + * + * decimators have relative_rates < 1.0 + * interpolators have relative_rates > 1.0 + */ + void set_relative_rate (double relative_rate); + + /*! + * \brief return the approximate output rate / input rate + */ + double relative_rate () const { return d_relative_rate; } + + /* + * The following two methods provide special case info to the + * scheduler in the event that a block has a fixed input to output + * ratio. gr_sync_block, gr_sync_decimator and gr_sync_interpolator + * override these. If you're fixed rate, subclass one of those. + */ + /*! + * \brief Given ninput samples, return number of output samples that will be produced. + * N.B. this is only defined if fixed_rate returns true. + * Generally speaking, you don't need to override this. + */ + virtual int fixed_rate_ninput_to_noutput(int ninput); + + /*! + * \brief Given noutput samples, return number of input samples required to produce noutput. + * N.B. this is only defined if fixed_rate returns true. + * Generally speaking, you don't need to override this. + */ + virtual int fixed_rate_noutput_to_ninput(int noutput); + + // ---------------------------------------------------------------------------- + + private: + + std::string d_name; + gr_io_signature_sptr d_input_signature; + gr_io_signature_sptr d_output_signature; + int d_output_multiple; + double d_relative_rate; // approx output_rate / input_rate + gr_block_detail_sptr d_detail; // implementation details + long d_unique_id; // convenient for debugging + unsigned d_history; + bool d_fixed_rate; + + + protected: + + gr_block (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + + //! may only be called during constructor + void set_input_signature (gr_io_signature_sptr iosig){ + d_input_signature = iosig; + } + + //! may only be called during constructor + void set_output_signature (gr_io_signature_sptr iosig){ + d_output_signature = iosig; + } + + void set_fixed_rate(bool fixed_rate){ d_fixed_rate = fixed_rate; } + + // These are really only for internal use, but leaving them public avoids + // having to work up an ever-varying list of friends + + public: + gr_block_detail_sptr detail () const { return d_detail; } + void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } +}; + +long gr_block_ncurrently_allocated (); + +#endif /* INCLUDED_GR_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i new file mode 100644 index 000000000..f1f0332e8 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +class gr_block; +typedef boost::shared_ptr gr_block_sptr; +%template(gr_block_sptr) boost::shared_ptr; + +// support vectors of these... +namespace std { + %template(x_vector_gr_block_sptr) vector; +}; + +class gr_block { + protected: + gr_block (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + + public: + + virtual ~gr_block (); + + std::string name () const; + gr_io_signature_sptr input_signature () const; + gr_io_signature_sptr output_signature () const; + long unique_id () const; + unsigned history () const; + + int output_multiple () const; + double relative_rate () const; + + bool check_topology (int ninputs, int noutputs); + bool start(); + bool stop(); + + // internal use + gr_block_detail_sptr detail () const { return d_detail; } + void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } +}; + +%rename(block_ncurrently_allocated) gr_block_ncurrently_allocated; +long gr_block_ncurrently_allocated (); + +%pythoncode %{ +gr_block_sptr.__repr__ = lambda self: "" % (self.name(), self.unique_id ()) +gr_block_sptr.block = lambda self: self +%} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc new file mode 100644 index 000000000..0ad5da49c --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -0,0 +1,108 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +static long s_ncurrently_allocated = 0; + +long +gr_block_detail_ncurrently_allocated () +{ + return s_ncurrently_allocated; +} + +gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) + : d_ninputs (ninputs), d_noutputs (noutputs), + d_input (ninputs), d_output (noutputs), + d_done (false) +{ + s_ncurrently_allocated++; +} + +gr_block_detail::~gr_block_detail () +{ + // should take care of itself + s_ncurrently_allocated--; +} + +void +gr_block_detail::set_input (unsigned int which, gr_buffer_reader_sptr reader) +{ + if (which >= d_ninputs) + throw std::invalid_argument ("gr_block_detail::set_input"); + + d_input[which] = reader; +} + +void +gr_block_detail::set_output (unsigned int which, gr_buffer_sptr buffer) +{ + if (which >= d_noutputs) + throw std::invalid_argument ("gr_block_detail::set_output"); + + d_output[which] = buffer; +} + +gr_block_detail_sptr +gr_make_block_detail (unsigned int ninputs, unsigned int noutputs) +{ + return gr_block_detail_sptr (new gr_block_detail (ninputs, noutputs)); +} + +void +gr_block_detail::set_done (bool done) +{ + d_done = done; + for (unsigned int i = 0; i < d_noutputs; i++) + d_output[i]->set_done (done); + + for (unsigned int i = 0; i < d_ninputs; i++) + d_input[i]->set_done (done); +} + +void +gr_block_detail::consume (int which_input, int how_many_items) +{ + if (how_many_items > 0) + input (which_input)->update_read_pointer (how_many_items); +} + +void +gr_block_detail::consume_each (int how_many_items) +{ + if (how_many_items > 0) + for (int i = 0; i < ninputs (); i++) + d_input[i]->update_read_pointer (how_many_items); +} + +void +gr_block_detail::produce_each (int how_many_items) +{ + if (how_many_items > 0) + for (int i = 0; i < noutputs (); i++) + d_output[i]->update_write_pointer (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 new file mode 100644 index 000000000..90c912c25 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -0,0 +1,99 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 detail. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_BLOCK_DETAIL_H +#define INCLUDED_GR_BLOCK_DETAIL_H + +#include +#include + +/*! + * \brief Implementation details to support the signal processing abstraction + * \ingroup internal + * + * This class contains implementation detail that should be "out of sight" + * 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 (); + + int ninputs () const { return d_ninputs; } + int noutputs () const { return d_noutputs; } + bool sink_p () const { return d_noutputs == 0; } + bool source_p () const { return d_ninputs == 0; } + + void set_done (bool done); + bool done () const { return d_done; } + + void set_input (unsigned int which, gr_buffer_reader_sptr reader); + gr_buffer_reader_sptr input (unsigned int which) + { + if (which >= d_ninputs) + throw std::invalid_argument ("gr_block_detail::input"); + return d_input[which]; + } + + void set_output (unsigned int which, gr_buffer_sptr buffer); + gr_buffer_sptr output (unsigned int which) + { + if (which >= d_noutputs) + throw std::invalid_argument ("gr_block_detail::output"); + return d_output[which]; + } + + /*! + * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed. + */ + void consume (int which_input, int how_many_items); + + /*! + * \brief Tell the scheduler \p how_many_items were consumed on each input stream. + */ + void consume_each (int how_many_items); + + void produce_each (int how_many_items); + + // ---------------------------------------------------------------------------- + + private: + unsigned int d_ninputs; + unsigned int d_noutputs; + std::vector d_input; + std::vector d_output; + bool d_done; + + gr_block_detail (unsigned int ninputs, unsigned int noutputs); + + friend gr_block_detail_sptr + gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); +}; + +gr_block_detail_sptr +gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); + +long +gr_block_detail_ncurrently_allocated (); + +#endif /* INCLUDED_GR_BLOCK_DETAIL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.i b/gnuradio-core/src/lib/runtime/gr_block_detail.i new file mode 100644 index 000000000..9d3843ebe --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.i @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +class gr_block_detail; +typedef boost::shared_ptr gr_block_detail_sptr; +%template(gr_block_detail_sptr) boost::shared_ptr; +%rename(block_detail) gr_make_block_detail; +%ignore gr_block_detail; + +gr_block_detail_sptr gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); + +class gr_block_detail { + public: + + ~gr_block_detail (); + + int ninputs () const { return d_ninputs; } + int noutputs () const { return d_noutputs; } + bool sink_p () const { return d_noutputs == 0; } + bool source_p () const { return d_ninputs == 0; } + + void set_input (unsigned int which, gr_buffer_reader_sptr reader); + gr_buffer_reader_sptr input (unsigned int which) + { + if (which >= d_ninputs) + throw std::invalid_argument ("gr_block_detail::input"); + return d_input[which]; + } + + void set_output (unsigned int which, gr_buffer_sptr buffer); + gr_buffer_sptr output (unsigned int which) + { + if (which >= d_noutputs) + throw std::invalid_argument ("gr_block_detail::output"); + return d_output[which]; + } + + // ---------------------------------------------------------------------------- + + private: + gr_block_detail (unsigned int ninputs, unsigned int noutputs); + +}; + + +%rename(block_detail_ncurrently_allocated) gr_block_detail_ncurrently_allocated; +long gr_block_detail_ncurrently_allocated (); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc new file mode 100644 index 000000000..d3d123096 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -0,0 +1,248 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +static long s_buffer_count = 0; // counts for debugging storage mgmt +static long s_buffer_reader_count = 0; + +// ---------------------------------------------------------------------------- +// Notes on storage management +// +// Pretty much all the fundamental classes are now using the +// shared_ptr stuff for automatic reference counting. To ensure that +// no mistakes are made, we make the constructors for classes private, +// and then provide a free factory function that returns a smart +// pointer to the desired class. +// +// gr_buffer and gr_buffer_reader are no exceptions. However, they +// both want pointers to each other, and unless we do something, we'll +// never delete any of them because of the circular structure. +// They'll always have a reference count of at least one. We could +// use boost::weak_ptr's from gr_buffer to gr_buffer_reader but that +// introduces it's own problems. (gr_buffer_reader's destructor needs +// to call gr_buffer::drop_reader, but has no easy way to get a +// shared_ptr to itself.) +// +// Instead, we solve this problem by having gr_buffer hold a raw +// pointer to gr_buffer_reader in its d_reader vector. +// gr_buffer_reader's destructor calls gr_buffer::drop_reader, so +// we're never left with an dangling pointer. gr_buffer_reader still +// has a shared_ptr to the buffer ensuring that the buffer doesn't go +// away under it. However, when the reference count of a +// gr_buffer_reader goes to zero, we can successfully reclaim it. +// ---------------------------------------------------------------------------- + + +/* + * Compute the minimum number of buffer items that work (i.e., + * address space wrap-around works). To work is to satisfy this + * contraint for integer buffer_size and k: + * + * type_size * nitems == k * page_size + */ +static long +minimum_buffer_items (long type_size, long page_size) +{ + return page_size / gr_gcd (type_size, page_size); +} + + +gr_buffer::gr_buffer (int nitems, size_t sizeof_item) + : d_base (0), d_bufsize (0), d_vmcircbuf (0), + d_sizeof_item (sizeof_item), d_write_index (0), + d_done (false) +{ + if (!allocate_buffer (nitems, sizeof_item)) + throw std::bad_alloc (); + + s_buffer_count++; +} + +gr_buffer_sptr +gr_make_buffer (int nitems, size_t sizeof_item) +{ + return gr_buffer_sptr (new gr_buffer (nitems, sizeof_item)); +} + +gr_buffer::~gr_buffer () +{ + delete d_vmcircbuf; + assert (d_readers.size() == 0); + s_buffer_count--; +} + +/*! + * sets d_vmcircbuf, d_base, d_bufsize. + * returns true iff successful. + */ +bool +gr_buffer::allocate_buffer (int nitems, size_t sizeof_item) +{ + int orig_nitems = nitems; + + // Any buffersize we come up with must be a multiple of min_nitems. + + int granularity = gr_vmcircbuf_sysconfig::granularity (); + int min_nitems = minimum_buffer_items (sizeof_item, granularity); + + // Round-up nitems to a multiple of min_nitems. + + if (nitems % min_nitems != 0) + nitems = ((nitems / min_nitems) + 1) * min_nitems; + + // If we rounded-up a whole bunch, give the user a heads up. + // This only happens if sizeof_item is not a power of two. + + if (nitems > 2 * orig_nitems && nitems * (int) sizeof_item > granularity){ + std::cerr << "gr_buffer::allocate_buffer: warning: tried to allocate\n" + << " " << orig_nitems << " items of size " + << sizeof_item << ". Due to alignment requirements\n" + << " " << nitems << " were allocated. If this isn't OK, consider padding\n" + << " your structure to a power-of-two bytes.\n" + << " On this platform, our allocation granularity is " << granularity << " bytes.\n"; + } + + d_bufsize = nitems; + d_vmcircbuf = gr_vmcircbuf_sysconfig::make (d_bufsize * d_sizeof_item); + if (d_vmcircbuf == 0){ + std::cerr << "gr_buffer::allocate_buffer: failed to allocate buffer of size " + << d_bufsize * d_sizeof_item / 1024 << " KB\n"; + return false; + } + + d_base = (char *) d_vmcircbuf->pointer_to_first_copy (); + return true; +} + + +int +gr_buffer::space_available () const +{ + if (d_readers.empty ()) + return d_bufsize - 1; // See comment below + + else { + + // Find out the maximum amount of data available to our readers + + int most_data = d_readers[0]->items_available (); + for (unsigned int i = 1; i < d_readers.size (); i++) + most_data = std::max (most_data, d_readers[i]->items_available ()); + + // The -1 ensures that the case d_write_index == d_read_index is + // unambiguous. It indicates that there is no data for the reader + + return d_bufsize - most_data - 1; + } +} + +void * +gr_buffer::write_pointer () +{ + return &d_base[d_write_index * d_sizeof_item]; +} + +void +gr_buffer::update_write_pointer (int nitems) +{ + d_write_index = index_add (d_write_index, nitems); +} + +gr_buffer_reader_sptr +gr_buffer_add_reader (gr_buffer_sptr buf, int history) +{ + gr_buffer_reader_sptr r (new gr_buffer_reader (buf, + buf->index_sub(buf->d_write_index, + history-1))); + buf->d_readers.push_back (r.get ()); + + return r; +} + +void +gr_buffer::drop_reader (gr_buffer_reader *reader) +{ + // isn't C++ beautiful... GAG! + + std::vector::iterator result = + std::find (d_readers.begin (), d_readers.end (), reader); + + if (result == d_readers.end ()) + throw std::invalid_argument ("gr_buffer::drop_reader"); // we didn't find it... + + d_readers.erase (result); +} + +long +gr_buffer_ncurrently_allocated () +{ + return s_buffer_count; +} + +// ---------------------------------------------------------------------------- + +gr_buffer_reader::gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index) + : d_buffer (buffer), d_read_index (read_index) +{ + s_buffer_reader_count++; +} + +gr_buffer_reader::~gr_buffer_reader () +{ + d_buffer->drop_reader(this); + s_buffer_reader_count--; +} + +int +gr_buffer_reader::items_available () const +{ + return d_buffer->index_sub (d_buffer->d_write_index, d_read_index); +} + +const void * +gr_buffer_reader::read_pointer () +{ + return &d_buffer->d_base[d_read_index * d_buffer->d_sizeof_item]; +} + +void +gr_buffer_reader::update_read_pointer (int nitems) +{ + d_read_index = d_buffer->index_add (d_read_index, nitems); +} + +long +gr_buffer_reader_ncurrently_allocated () +{ + return s_buffer_reader_count; +} diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h new file mode 100644 index 000000000..6f85f275e --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -0,0 +1,196 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_BUFFER_H +#define INCLUDED_GR_BUFFER_H + +#include + +class gr_vmcircbuf; + +/*! + * \brief Allocate a buffer that holds at least \p nitems of size \p sizeof_item. + * + * The total size of the buffer will be rounded up to a system + * dependent boundary. This is typically the system page size, but + * under MS windows is 64KB. + */ +gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item); + + +/*! + * \brief Single writer, multiple reader fifo. + * \ingroup internal + */ +class gr_buffer { + public: + virtual ~gr_buffer (); + + /*! + * \brief return number of items worth of space available for writing + */ + int space_available () const; + + /*! + * \brief return pointer to write buffer. + * + * The return value points at space that can hold at least + * space_available() items. + */ + void *write_pointer (); + + /*! + * \brief tell buffer that we wrote \p nitems into it + */ + void update_write_pointer (int nitems); + + + void set_done (bool done) { d_done = done; } + bool done () const { return d_done; } + + // ------------------------------------------------------------------------- + + private: + + friend class gr_buffer_reader; + friend gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item); + friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int history); + + protected: + char *d_base; // base address of buffer + unsigned int d_bufsize; // in items + private: + gr_vmcircbuf *d_vmcircbuf; + size_t d_sizeof_item; // in bytes + unsigned int d_write_index; // in items [0,d_bufsize) + std::vector d_readers; + bool d_done; + + unsigned + index_add (unsigned a, unsigned b) + { + unsigned s = a + b; + + if (s >= d_bufsize) + s -= d_bufsize; + + assert (s < d_bufsize); + return s; + } + + unsigned + index_sub (unsigned a, unsigned b) + { + int s = a - b; + + if (s < 0) + s += d_bufsize; + + assert ((unsigned) s < d_bufsize); + return s; + } + + virtual bool allocate_buffer (int nitems, size_t sizeof_item); + + /*! + * \brief constructor is private. Use gr_make_buffer to create instances. + * + * Allocate a buffer that holds at least \p nitems of size \p sizeof_item. + * + * The total size of the buffer will be rounded up to a system + * dependent boundary. This is typically the system page size, but + * under MS windows is 64KB. + */ + gr_buffer (int nitems, size_t sizeof_item); + + /*! + * \brief disassociate \p reader from this buffer + */ + void drop_reader (gr_buffer_reader *reader); + +}; + +//! create a new gr_buffer_reader and attach it to buffer \p buf +gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int history); + +//! returns # of gr_buffers currently allocated +long gr_buffer_ncurrently_allocated (); + + +// --------------------------------------------------------------------------- + +/*! + * \brief How we keep track of the readers of a gr_buffer. + * \ingroup internal + */ + +class gr_buffer_reader { + + public: + ~gr_buffer_reader (); + + /*! + * \brief Return number of items available for reading. + */ + int items_available () const; + + /*! + * \brief Return maximum number of items that could ever be available for reading. + * This is used as a sanity check in the scheduler to avoid looping forever. + */ + int max_possible_items_available () const { return d_buffer->d_bufsize - 1; } + + /*! + * \brief return pointer to read buffer. + * + * The return value points to items_available() number of items + */ + const void *read_pointer (); + + /* + * \brief tell buffer we read \p items from it + */ + void update_read_pointer (int nitems); + + void set_done (bool done) { d_buffer->set_done (done); } + bool done () const { return d_buffer->done (); } + + // ------------------------------------------------------------------------- + + private: + + friend class gr_buffer; + friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int history); + + + gr_buffer_sptr d_buffer; + unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) + + //! constructor is private. Use gr_buffer::add_reader to create instances + gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index); +}; + +//! returns # of gr_buffer_readers currently allocated +long gr_buffer_reader_ncurrently_allocated (); + + +#endif /* INCLUDED_GR_BUFFER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.i b/gnuradio-core/src/lib/runtime/gr_buffer.i new file mode 100644 index 000000000..80f92ece1 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_buffer.i @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +class gr_buffer; +typedef boost::shared_ptr gr_buffer_sptr; +%template(gr_buffer_sptr) boost::shared_ptr; +%rename(buffer) gr_make_buffer; +%ignore gr_buffer; + +gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item); + +class gr_buffer { + public: + ~gr_buffer (); + + private: + gr_buffer (int nitems, size_t sizeof_item); +}; + + +class gr_buffer_reader; +typedef boost::shared_ptr gr_buffer_reader_sptr; +%template(gr_buffer_reader_sptr) boost::shared_ptr; +%ignore gr_buffer_reader; + +%rename(buffer_add_reader) gr_buffer_add_reader; +gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int history); + +class gr_buffer_reader { + public: + ~gr_buffer_reader (); + + private: + friend class gr_buffer; + gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index); +}; + + +%rename(buffer_ncurrently_allocated) gr_buffer_ncurrently_allocated; +long gr_buffer_ncurrently_allocated (); + +%rename(buffer_reader_ncurrently_allocated) gr_buffer_reader_ncurrently_allocated; +long gr_buffer_reader_ncurrently_allocated (); + diff --git a/gnuradio-core/src/lib/runtime/gr_complex.h b/gnuradio-core/src/lib/runtime/gr_complex.h new file mode 100644 index 000000000..242b2f54d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_complex.h @@ -0,0 +1,46 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef INCLUDED_GR_COMPLEX_H +#define INCLUDED_GR_COMPLEX_H + +#include +typedef std::complex gr_complex; +typedef std::complex gr_complexd; + + +inline bool is_complex (gr_complex x) { return true;} +inline bool is_complex (gr_complexd x) { return true;} +inline bool is_complex (float x) { return false;} +inline bool is_complex (double x) { return false;} +inline bool is_complex (int x) { return false;} +inline bool is_complex (char x) { return false;} +inline bool is_complex (short x) { return false;} + + +// this doesn't really belong here, but there are worse places for it... + +#define ASSERT_COMPLEXES_EQUAL(expected,actual,delta) \ + CPPUNIT_ASSERT_DOUBLES_EQUAL (expected.real(), actual.real(), delta); \ + CPPUNIT_ASSERT_DOUBLES_EQUAL (expected.imag(), actual.imag(), delta); + +#endif /* INCLUDED_GR_COMPLEX_H */ + diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.cc b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc new file mode 100644 index 000000000..c2a1eb50a --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc @@ -0,0 +1,192 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#ifdef HAVE_SELECT +# ifdef HAVE_SYS_SELECT_H +# include +# else +# ifdef HAVE_SYS_TIME_H +# include +# endif +# ifdef HAVE_SYS_TYPES_H +# include +# endif +# ifdef HAVE_UNISTD_H +# include +# endif +# endif +#endif + + +static gr_dispatcher_sptr s_singleton; + +gr_dispatcher_sptr +gr_make_dispatcher() +{ + return gr_dispatcher_sptr(new gr_dispatcher()); +} + +gr_dispatcher_sptr +gr_dispatcher_singleton() +{ + if (s_singleton) + return s_singleton; + + s_singleton = gr_make_dispatcher(); + return s_singleton; +} + +#if !defined(HAVE_SELECT) // Stub it out + +gr_dispatcher::gr_dispatcher() +{ +} + +gr_dispatcher::~gr_dispatcher() +{ +} + +bool +gr_dispatcher::add_handler(gr_select_handler_sptr handler) +{ + return true; +} + +bool +gr_dispatcher::del_handler(gr_select_handler_sptr handler) +{ + return true; +} + +bool +gr_dispatcher::del_handler(gr_select_handler *handler) +{ + return true; +} + +void +gr_dispatcher::loop(double timeout) +{ +} + +#else // defined(HAVE_SELECT) + +gr_dispatcher::gr_dispatcher() + : d_handler(FD_SETSIZE), d_max_index(-1) +{ +} + +gr_dispatcher::~gr_dispatcher() +{ +} + +bool +gr_dispatcher::add_handler(gr_select_handler_sptr handler) +{ + int fd = handler->fd(); + if (fd < 0 || fd >= FD_SETSIZE) + return false; + + d_max_index = std::max(d_max_index, fd); + d_handler[fd] = handler; + return true; +} + +bool +gr_dispatcher::del_handler(gr_select_handler_sptr handler) +{ + return del_handler(handler.get()); +} + +bool +gr_dispatcher::del_handler(gr_select_handler *handler) +{ + int fd = handler->fd(); + if (fd < 0 || fd >= FD_SETSIZE) + return false; + + d_handler[fd].reset(); + + if (fd == d_max_index){ + int i; + for (i = fd - 1; i >= 0 && !d_handler[i]; i--) + ; + d_max_index = i; + } + return true; +} + + +void +gr_dispatcher::loop(double timeout) +{ + struct timeval master; + struct timeval tmp; + fd_set rd_set; + fd_set wr_set; + + double secs = floor (timeout); + master.tv_sec = (long) secs; + master.tv_usec = (long) ((timeout - secs) * 1e6); + + while (d_max_index >= 0){ + FD_ZERO(&rd_set); + FD_ZERO(&wr_set); + + for (int i = 0; i <= d_max_index; i++){ + if (d_handler[i] && d_handler[i]->readable()) + FD_SET(i, &rd_set); + if (d_handler[i] && d_handler[i]->writable()) + FD_SET(i, &wr_set); + } + + tmp = master; + int retval = select(d_max_index+1, &rd_set, &wr_set, 0, &tmp); + if (retval == 0) // timed out with nothing ready + continue; + if (retval < 0){ + if (errno == EINTR) + continue; + perror ("gr_dispatcher/select"); + return; + } + + for (int i = 0; i <= d_max_index; i++){ + if (FD_ISSET(i, &rd_set)) + if (d_handler[i]) + d_handler[i]->handle_read(); + if (FD_ISSET(i, &wr_set)) + if (d_handler[i]) + d_handler[i]->handle_write(); + } + } +} + +#endif diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.h b/gnuradio-core/src/lib/runtime/gr_dispatcher.h new file mode 100644 index 000000000..a3d857972 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_DISPATCHER_H +#define INCLUDED_GR_DISPATCHER_H + +#include +#include + +class gr_dispatcher; +typedef boost::shared_ptr gr_dispatcher_sptr; + +gr_dispatcher_sptr gr_dispatcher_singleton(); +gr_dispatcher_sptr gr_make_dispatcher(); + +/*! + * \brief invoke callbacks based on select. + * + * \sa gr_select_handler + */ +class gr_dispatcher +{ + gr_dispatcher(); + friend gr_dispatcher_sptr gr_make_dispatcher(); + + std::vector d_handler; + int d_max_index; + +public: + ~gr_dispatcher(); + + bool add_handler(gr_select_handler_sptr handler); + bool del_handler(gr_select_handler_sptr handler); + bool del_handler(gr_select_handler *handler); + + /*! + * \brief Event dispatching loop. + * + * Enter a polling loop that only terminates after all gr_select_handlers + * have been removed. \p timeout sets the timeout parameter to the select() + * call, measured in seconds. + * + * \param timeout maximum number of seconds to block in select. + */ + void loop(double timeout=10); +}; + +#endif /* INCLUDED_GR_DISPATCHER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.i b/gnuradio-core/src/lib/runtime/gr_dispatcher.i new file mode 100644 index 000000000..5feca7571 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.i @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +class gr_dispatcher; +typedef boost::shared_ptr gr_dispatcher_sptr; +%template(gr_dispatcher_sptr) boost::shared_ptr; + +%rename(dispatcher) gr_make_dispatcher; +gr_dispatcher_sptr gr_make_dispatcher(); + +%rename(dispatcher_singleton) gr_dispatcher_singleton; +gr_dispatcher_sptr gr_dispatcher_singleton(); + +/*! + * \brief invoke callbacks based on select. + * + * \sa gr_select_handler + */ +class gr_dispatcher +{ + gr_dispatcher(); + +public: + ~gr_dispatcher(); + + /*! + * \brief Event dispatching loop. + * + * Enter a polling loop that only terminates after all gr_select_handlers + * have been removed. \p timeout sets the timeout parameter to the select() + * call, measured in seconds. + * + * \param timeout maximum number of seconds to block in select. + */ + void loop(double timeout=10); +}; diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.cc b/gnuradio-core/src/lib/runtime/gr_error_handler.cc new file mode 100644 index 000000000..a3148cfde --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.cc @@ -0,0 +1,244 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +/* + * This code is based on error.cc from the "Click Modular Router". + * Original copyright follows: + */ +/* + * error.{cc,hh} -- flexible classes for error reporting + * Eddie Kohler + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#ifdef HAVE_IO_H +#include +#endif + +static gr_error_handler *s_default_handler = 0; +static gr_error_handler *s_silent_handler = 0; + +bool +gr_error_handler::has_default_handler() +{ + return s_default_handler != 0; +} + +void +gr_error_handler::set_default_handler(gr_error_handler *errh) +{ + s_default_handler = errh; +} + +gr_error_handler * +gr_error_handler::default_handler() +{ + assert (s_default_handler != 0); + return s_default_handler; +} + +gr_error_handler * +gr_error_handler::silent_handler() +{ + assert (s_silent_handler != 0); + return s_silent_handler; +} + +// ---------------------------------------------------------------- + +gr_error_handler::~gr_error_handler() +{ + // nop +} + +void +gr_error_handler::debug(const char *format, ...) +{ + va_list val; + va_start(val, format); + verror(ERR_DEBUG, format, val); + va_end(val); +} + +void +gr_error_handler::message(const char *format, ...) +{ + va_list val; + va_start(val, format); + verror(ERR_MESSAGE, format, val); + va_end(val); +} + +void +gr_error_handler::warning(const char *format, ...) +{ + va_list val; + va_start(val, format); + verror(ERR_WARNING, format, val); + va_end(val); +} + +void +gr_error_handler::error(const char *format, ...) +{ + va_list val; + va_start(val, format); + verror(ERR_ERROR, format, val); + va_end(val); +} + +void +gr_error_handler::fatal(const char *format, ...) +{ + va_list val; + va_start(val, format); + verror(ERR_FATAL, format, val); + va_end(val); +} + +void +gr_error_handler::verror(seriousness s, const char *format, va_list val) +{ + std::string text = make_text(s, format, val); + handle_text(s, text); + count_error(s); +} + +void +gr_error_handler::verror_text(seriousness s, const std::string &text) +{ + // text is already made + handle_text(s, text); + count_error(s); +} + +std::string +gr_error_handler::make_text(seriousness s, const char *format, va_list val) +{ + char text_buf[4096]; + vsnprintf(text_buf, sizeof(text_buf), format, val); + text_buf[sizeof(text_buf)-1] = 0; + return text_buf; +} + +// ---------------------------------------------------------------- + +void +gr_base_error_handler::count_error(seriousness s) +{ + if (s < ERR_WARNING) + /* do nothing */; + else if (s < ERR_ERROR) + d_nwarnings++; + else + d_nerrors++; +} + +// ---------------------------------------------------------------- + +gr_file_error_handler::gr_file_error_handler(FILE *file) + : d_file(file), d_fd(-1) +{ +} + +gr_file_error_handler::gr_file_error_handler(int file_descriptor) +{ + d_fd = dup(file_descriptor); // so we can fclose it + if (d_fd == -1){ + perror("gr_file_error_handler:dup"); + throw std::invalid_argument("gr_file_error_handler:dup"); + } + d_file = fdopen(d_fd, "w"); + if (d_file == 0){ + perror("gr_file_error_handler:fdopen"); + throw std::invalid_argument("gr_file_error_handler:fdopen"); + } +} + +gr_file_error_handler::~gr_file_error_handler() +{ + if (d_fd != -1){ + fclose(d_file); + } +} + +void +gr_file_error_handler::handle_text(seriousness s, const std::string &text) +{ + if (text.length() <= 0) + return; + + fwrite(text.data(), 1, text.length(), d_file); + if (text[text.length()-1] != '\n') + fwrite("\n", 1, 1, d_file); + + if (d_fd != -1) + fflush(d_file); // keep synced with any other users of fd +} + + +// ---------------------------------------------------------------- +// static error handlers +// + +class gr_silent_error_handler : public gr_base_error_handler +{ +public: + gr_silent_error_handler() {} + void handle_text(seriousness s, const std::string &str); +}; + +void +gr_silent_error_handler::handle_text(seriousness s, const std::string &str) +{ + // nop +} + +class force_init { +public: + force_init() + { + s_default_handler = new gr_file_error_handler(stdout); + s_silent_handler = new gr_silent_error_handler(); + } +}; + +static force_init kludge; diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.h b/gnuradio-core/src/lib/runtime/gr_error_handler.h new file mode 100644 index 000000000..275db64c3 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.h @@ -0,0 +1,114 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +/* + * This code is based on error.hh from the "Click Modular Router". + * Original copyright follows: + */ +/* + * error.{cc,hh} -- flexible classes for error reporting + * Eddie Kohler + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#ifndef INCLUDED_GR_ERROR_HANDLER_H +#define INCLUDED_GR_ERROR_HANDLER_H + +#include +#include + +/*! + * \brief abstract error handler + */ +class gr_error_handler { +public: + enum seriousness { + ERR_DEBUG = 0x00000000, + ERR_MESSAGE = 0x00010000, + ERR_WARNING = 0x00020000, + ERR_ERROR = 0x00030000, + ERR_FATAL = 0x00040000 + }; + + gr_error_handler() {} + virtual ~gr_error_handler(); + + static gr_error_handler *default_handler(); + static gr_error_handler *silent_handler(); + + static bool has_default_handler(); + static void set_default_handler(gr_error_handler *errh); + + void debug(const char *format, ...); + void message(const char *format, ...); + void warning(const char *format, ...); + void error(const char *format, ...); + void fatal(const char *format, ...); + + virtual int nwarnings() const = 0; + virtual int nerrors() const = 0; + virtual void reset_counts() = 0; + + void verror(seriousness s, const char *format, va_list); + void verror_text(seriousness s, const std::string &text); + +protected: + virtual void count_error(seriousness s) = 0; + virtual void handle_text(seriousness s, const std::string &str) = 0; + std::string make_text(seriousness s, const char *format, va_list); +}; + + +class gr_base_error_handler : public gr_error_handler { + int d_nwarnings; + int d_nerrors; + +public: + gr_base_error_handler() : d_nwarnings(0), d_nerrors(0) {} + int nwarnings() const { return d_nwarnings; } + int nerrors() const { return d_nerrors; } + void reset_counts() { d_nwarnings = d_nerrors = 0; } + void count_error(seriousness s); +}; + +class gr_file_error_handler : public gr_base_error_handler { + FILE *d_file; + int d_fd; +public: + gr_file_error_handler(FILE *file); + gr_file_error_handler(int file_descriptor); + ~gr_file_error_handler(); + + void handle_text(seriousness s, const std::string &str); +}; + +#endif /* INCLUDED_GR_ERROR_HANDLER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.i b/gnuradio-core/src/lib/runtime/gr_error_handler.i new file mode 100644 index 000000000..d0e61496f --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.i @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +%rename(error_handler) gr_error_handler; +%rename(file_error_handler) gr_file_error_handler; + +class gr_error_handler { +public: + enum seriousness { + ERR_DEBUG = 0x00000000, + ERR_MESSAGE = 0x00010000, + ERR_WARNING = 0x00020000, + ERR_ERROR = 0x00030000, + ERR_FATAL = 0x00040000 + }; + + gr_error_handler() {} + virtual ~gr_error_handler(); + + static gr_error_handler *default_handler(); + static gr_error_handler *silent_handler(); + + static bool has_default_handler(); + static void set_default_handler(gr_error_handler *errh); + + virtual int nwarnings() const = 0; + virtual int nerrors() const = 0; + virtual void reset_counts() = 0; + + void verror_text(seriousness s, const std::string &text); +}; + +%ignore gr_base_error_handler; +class gr_base_error_handler : public gr_error_handler { + int d_nwarnings; + int d_nerrors; + +public: + gr_base_error_handler() : d_nwarnings(0), d_nerrors(0) {} + int nwarnings() const { return d_nwarnings; } + int nerrors() const { return d_nerrors; } + void reset_counts() { d_nwarnings = d_nerrors = 0; } + void count_error(seriousness s); +}; + +class gr_file_error_handler : public gr_base_error_handler { +public: + gr_file_error_handler(int file_descriptor); + ~gr_file_error_handler(); +}; diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.cc b/gnuradio-core/src/lib/runtime/gr_io_signature.cc new file mode 100644 index 000000000..7277108ca --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.cc @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include + +gr_io_signature::gr_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item) +{ + if (min_streams < 0 + || (max_streams != IO_INFINITE && max_streams < min_streams)) + throw std::invalid_argument ("gr_io_signature"); + + d_min_streams = min_streams; + d_max_streams = max_streams; + d_sizeof_stream_item = sizeof_stream_item; +} + +gr_io_signature::~gr_io_signature () +{ + // NOP for now + // std::cout << "destroying gr_io_signature: " << this << '\n'; +} + +gr_io_signature_sptr +gr_make_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item) +{ + return gr_io_signature_sptr (new gr_io_signature (min_streams, max_streams, + sizeof_stream_item)); +} + + diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h new file mode 100644 index 000000000..e0d979070 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_IO_SIGNATURE_H +#define INCLUDED_IO_SIGNATURE_H + +#include + +/*! + * \brief i/o signature for input and output ports. + * + * For now, we restrict all streams to be the same type. + * We can fix this later. + */ + +class gr_io_signature { + public: + + static const int IO_INFINITE = -1; + + ~gr_io_signature (); + + int min_streams () const { return d_min_streams; } + int max_streams () const { return d_max_streams; } + size_t sizeof_stream_item (int index) const { return d_sizeof_stream_item; } + + // ---------------------------------------------------------------------------- + + private: + + int d_min_streams; + int d_max_streams; + size_t d_sizeof_stream_item; + + gr_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item); + + friend gr_io_signature_sptr gr_make_io_signature (int min_streams, + int max_streams, + size_t sizeof_stream_item); +}; + +gr_io_signature_sptr +gr_make_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item); + + +#endif /* INCLUDED_IO_SIGNATURE_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.i b/gnuradio-core/src/lib/runtime/gr_io_signature.i new file mode 100644 index 000000000..601142e28 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.i @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +class gr_io_signature; +typedef boost::shared_ptr gr_io_signature_sptr; +%template(gr_io_signature_sptr) boost::shared_ptr; + +%rename(io_signature) gr_make_io_signature; + +gr_io_signature_sptr +gr_make_io_signature (int min_streams, + int max_streams, + size_t sizeof_stream_item); + +class gr_io_signature { + public: + + // disabled. Suspected bug in SWIG 1.3.24 + // static const int IO_INFINITE = -1; + + ~gr_io_signature (); + + int min_streams () const { return d_min_streams; } + int max_streams () const { return d_max_streams; } + size_t sizeof_stream_item (int index) const { return d_sizeof_stream_item; } + + private: + gr_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item); +}; + diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc new file mode 100644 index 000000000..c6da0978c --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc @@ -0,0 +1,186 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + + +gr_local_sighandler::gr_local_sighandler (int signum, + void (*new_handler)(int)) + : d_signum (signum) +{ +#ifdef HAVE_SIGACTION + struct sigaction new_action; + memset (&new_action, 0, sizeof (new_action)); + + new_action.sa_handler = new_handler; + sigemptyset (&new_action.sa_mask); + new_action.sa_flags = 0; + + if (sigaction (d_signum, &new_action, &d_old_action) < 0){ + perror ("sigaction (install new)"); + throw std::runtime_error ("sigaction"); + } +#endif +} + +gr_local_sighandler::~gr_local_sighandler () +{ +#ifdef HAVE_SIGACTION + if (sigaction (d_signum, &d_old_action, 0) < 0){ + perror ("sigaction (restore old)"); + throw std::runtime_error ("sigaction"); + } +#endif +} + +void +gr_local_sighandler::throw_signal (int signum) +{ + throw gr_signal (signum); +} + +/* + * Semi-hideous way to may a signal number into a signal name + */ + +#define SIGNAME(x) case x: return #x + +std::string +gr_signal::name () const +{ + char tmp[128]; + + switch (signal ()){ +#ifdef SIGHUP + SIGNAME (SIGHUP); +#endif +#ifdef SIGINT + SIGNAME (SIGINT); +#endif +#ifdef SIGQUIT + SIGNAME (SIGQUIT); +#endif +#ifdef SIGILL + SIGNAME (SIGILL); +#endif +#ifdef SIGTRAP + SIGNAME (SIGTRAP); +#endif +#ifdef SIGABRT + SIGNAME (SIGABRT); +#endif +#ifdef SIGBUS + SIGNAME (SIGBUS); +#endif +#ifdef SIGFPE + SIGNAME (SIGFPE); +#endif +#ifdef SIGKILL + SIGNAME (SIGKILL); +#endif +#ifdef SIGUSR1 + SIGNAME (SIGUSR1); +#endif +#ifdef SIGSEGV + SIGNAME (SIGSEGV); +#endif +#ifdef SIGUSR2 + SIGNAME (SIGUSR2); +#endif +#ifdef SIGPIPE + SIGNAME (SIGPIPE); +#endif +#ifdef SIGALRM + SIGNAME (SIGALRM); +#endif +#ifdef SIGTERM + SIGNAME (SIGTERM); +#endif +#ifdef SIGSTKFLT + SIGNAME (SIGSTKFLT); +#endif +#ifdef SIGCHLD + SIGNAME (SIGCHLD); +#endif +#ifdef SIGCONT + SIGNAME (SIGCONT); +#endif +#ifdef SIGSTOP + SIGNAME (SIGSTOP); +#endif +#ifdef SIGTSTP + SIGNAME (SIGTSTP); +#endif +#ifdef SIGTTIN + SIGNAME (SIGTTIN); +#endif +#ifdef SIGTTOU + SIGNAME (SIGTTOU); +#endif +#ifdef SIGURG + SIGNAME (SIGURG); +#endif +#ifdef SIGXCPU + SIGNAME (SIGXCPU); +#endif +#ifdef SIGXFSZ + SIGNAME (SIGXFSZ); +#endif +#ifdef SIGVTALRM + SIGNAME (SIGVTALRM); +#endif +#ifdef SIGPROF + SIGNAME (SIGPROF); +#endif +#ifdef SIGWINCH + SIGNAME (SIGWINCH); +#endif +#ifdef SIGIO + SIGNAME (SIGIO); +#endif +#ifdef SIGPWR + SIGNAME (SIGPWR); +#endif +#ifdef SIGSYS + SIGNAME (SIGSYS); +#endif + default: +#if defined (HAVE_SNPRINTF) +#if defined (SIGRTMIN) && defined (SIGRTMAX) + if (signal () >= SIGRTMIN && signal () <= SIGRTMAX){ + snprintf (tmp, sizeof (tmp), "SIGRTMIN + %d", signal ()); + return tmp; + } +#endif + snprintf (tmp, sizeof (tmp), "SIGNAL %d", signal ()); + return tmp; +#else + return "Unknown signal"; +#endif + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h new file mode 100644 index 000000000..69eb65d80 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_LOCAL_SIGHANDLER_H +#define INCLUDED_GR_LOCAL_SIGHANDLER_H + +#include +#include + +/*! + * \brief Get and set signal handler. + * + * Constructor installs new handler, destructor reinstalls + * original value. + */ +class gr_local_sighandler { + int d_signum; +#ifdef HAVE_SIGACTION + struct sigaction d_old_action; +#endif +public: + gr_local_sighandler (int signum, void (*new_handler)(int)); + ~gr_local_sighandler (); + + /* throw gr_signal (signum) */ + static void throw_signal (int signum); +}; + +/*! + * \brief Representation of signal. + */ +class gr_signal +{ + int d_signum; +public: + gr_signal (int signum) : d_signum (signum) {} + int signal () const { return d_signum; } + std::string name () const; +}; + +#endif /* INCLUDED_GR_LOCAL_SIGHANDLER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_message.cc b/gnuradio-core/src/lib/runtime/gr_message.cc new file mode 100644 index 000000000..e9427e64d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_message.cc @@ -0,0 +1,77 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include + +static long s_ncurrently_allocated = 0; + +gr_message_sptr +gr_make_message (long type, double arg1, double arg2, size_t length) +{ + return gr_message_sptr (new gr_message (type, arg1, arg2, length)); +} + +gr_message_sptr +gr_make_message_from_string(const std::string s, long type, double arg1, double arg2) +{ + gr_message_sptr m = gr_make_message(type, arg1, arg2, s.size()); + memcpy(m->msg(), s.data(), s.size()); + return m; +} + + +gr_message::gr_message (long type, double arg1, double arg2, size_t length) + : d_type(type), d_arg1(arg1), d_arg2(arg2) +{ + if (length == 0) + d_buf_start = d_msg_start = d_msg_end = d_buf_end = 0; + else { + d_buf_start = new unsigned char [length]; + d_msg_start = d_buf_start; + d_msg_end = d_buf_end = d_buf_start + length; + } + s_ncurrently_allocated++; +} + +gr_message::~gr_message () +{ + assert (d_next == 0); + delete [] d_buf_start; + d_msg_start = d_msg_end = d_buf_end = 0; + s_ncurrently_allocated--; +} + +std::string +gr_message::to_string() const +{ + return std::string((char *)d_msg_start, length()); +} + +long +gr_message_ncurrently_allocated () +{ + return s_ncurrently_allocated; +} diff --git a/gnuradio-core/src/lib/runtime/gr_message.h b/gnuradio-core/src/lib/runtime/gr_message.h new file mode 100644 index 000000000..272a82ee4 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_message.h @@ -0,0 +1,89 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef INCLUDED_GR_MESSAGE_H +#define INCLUDED_GR_MESSAGE_H + +#include +#include + +class gr_message; +typedef boost::shared_ptr gr_message_sptr; + +/*! + * \brief public constructor for gr_message + */ +gr_message_sptr +gr_make_message(long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0); + +gr_message_sptr +gr_make_message_from_string(const std::string s, long type = 0, double arg1 = 0, double arg2 = 0); + +/*! + * \brief Message. + * + * The ideas and method names for adjustable message length were + * lifted from the click modular router "Packet" class. + */ +class gr_message { + gr_message_sptr d_next; // link field for msg queue + long d_type; // type of the message + double d_arg1; // optional arg1 + double d_arg2; // optional arg2 + + unsigned char *d_buf_start; // start of allocated buffer + unsigned char *d_msg_start; // where the msg starts + unsigned char *d_msg_end; // one beyond end of msg + unsigned char *d_buf_end; // one beyond end of allocated buffer + + gr_message (long type, double arg1, double arg2, size_t length); + + friend gr_message_sptr + gr_make_message (long type, double arg1, double arg2, size_t length); + + friend gr_message_sptr + gr_make_message_from_string (const std::string s, long type, double arg1, double arg2); + + friend class gr_msg_queue; + + unsigned char *buf_data() const { return d_buf_start; } + size_t buf_len() const { return d_buf_end - d_buf_start; } + +public: + ~gr_message (); + + long type() const { return d_type; } + double arg1() const { return d_arg1; } + double arg2() const { return d_arg2; } + + void set_type(long type) { d_type = type; } + void set_arg1(double arg1) { d_arg1 = arg1; } + void set_arg2(double arg2) { d_arg2 = arg2; } + + unsigned char *msg() const { return d_msg_start; } + size_t length() const { return d_msg_end - d_msg_start; } + std::string to_string() const; + +}; + +long gr_message_ncurrently_allocated (); + +#endif /* INCLUDED_GR_MESSAGE_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_message.i b/gnuradio-core/src/lib/runtime/gr_message.i new file mode 100644 index 000000000..19d5d1cd1 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_message.i @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +class gr_message; +typedef boost::shared_ptr gr_message_sptr; +%template(gr_message_sptr) boost::shared_ptr; + +%rename(message_from_string) gr_make_message_from_string; +gr_message_sptr +gr_make_message_from_string(const std::string s, long type = 0, double arg1 = 0, double arg2 = 0); + +%rename(message) gr_make_message; +gr_message_sptr +gr_make_message(long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0); + +/*! + * \brief Message. + * + * The ideas and method names for adjustable message length were + * lifted from the click modular router "Packet" class. + */ +class gr_message { + gr_message (long type, double arg1, double arg2, size_t length); + + unsigned char *buf_data() const { return d_buf_start; } + size_t buf_len() const { return d_buf_end - d_buf_start; } + +public: + ~gr_message (); + + long type() const { return d_type; } + double arg1() const { return d_arg1; } + double arg2() const { return d_arg2; } + + void set_type(long type) { d_type = type; } + void set_arg1(double arg1) { d_arg1 = arg1; } + void set_arg2(double arg2) { d_arg2 = arg2; } + + size_t length() const; + std::string to_string() const; + +}; + +%rename(message_ncurrently_allocated) gr_message_ncurrently_allocated; +long gr_message_ncurrently_allocated(); + diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.cc b/gnuradio-core/src/lib/runtime/gr_msg_handler.cc new file mode 100644 index 000000000..98007e239 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.cc @@ -0,0 +1,30 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include + +gr_msg_handler::~gr_msg_handler () +{ +} diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.h b/gnuradio-core/src/lib/runtime/gr_msg_handler.h new file mode 100644 index 000000000..15aab338a --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.h @@ -0,0 +1,41 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef INCLUDED_GR_MSG_HANDLER_H +#define INCLUDED_GR_MSG_HANDLER_H + +#include + +class gr_msg_handler; +typedef boost::shared_ptr gr_msg_handler_sptr; + +/*! + * \brief abstract class of message handlers + */ +class gr_msg_handler { +public: + virtual ~gr_msg_handler (); + + //! handle \p msg + virtual void handle (gr_message_sptr msg) = 0; +}; + +#endif /* INCLUDED_GR_MSG_HANDLER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.i b/gnuradio-core/src/lib/runtime/gr_msg_handler.i new file mode 100644 index 000000000..5571665ac --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.i @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/*! + * \brief abstract class of message handlers + */ +class gr_msg_handler { +public: + virtual ~gr_msg_handler () = 0; + + //! handle \p msg + virtual void handle (gr_message_sptr msg) = 0; +}; diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc new file mode 100644 index 000000000..6b53fc7ea --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc @@ -0,0 +1,127 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include + + +gr_msg_queue_sptr +gr_make_msg_queue(unsigned int limit) +{ + return gr_msg_queue_sptr (new gr_msg_queue(limit)); +} + + +gr_msg_queue::gr_msg_queue(unsigned int limit) + : d_not_empty(&d_mutex), d_not_full(&d_mutex), + /*d_head(0), d_tail(0),*/ d_count(0), d_limit(limit) +{ +} + +gr_msg_queue::~gr_msg_queue() +{ + flush (); +} + +void +gr_msg_queue::insert_tail(gr_message_sptr msg) +{ + if (msg->d_next) + throw std::invalid_argument("gr_msg_queue::insert_tail: msg already in queue"); + + omni_mutex_lock l(d_mutex); + + while (full_p()) + d_not_full.wait(); + + if (d_tail == 0){ + d_tail = d_head = msg; + //msg->d_next = 0; + msg->d_next.reset(); + } + else { + d_tail->d_next = msg; + d_tail = msg; + //msg->d_next = 0; + msg->d_next.reset(); + } + d_count++; + d_not_empty.signal(); +} + +gr_message_sptr +gr_msg_queue::delete_head() +{ + omni_mutex_lock l(d_mutex); + gr_message_sptr m; + + while ((m = d_head) == 0) + d_not_empty.wait(); + + d_head = m->d_next; + if (d_head == 0){ + //d_tail = 0; + d_tail.reset(); + } + + d_count--; + // m->d_next = 0; + m->d_next.reset(); + d_not_full.signal(); + return m; +} + +gr_message_sptr +gr_msg_queue::delete_head_nowait() +{ + omni_mutex_lock l(d_mutex); + gr_message_sptr m; + + if ((m = d_head) == 0){ + //return 0; + return gr_message_sptr(); + } + + d_head = m->d_next; + if (d_head == 0){ + //d_tail = 0; + d_tail.reset(); + } + + d_count--; + //m->d_next = 0; + m->d_next.reset(); + d_not_full.signal(); + return m; +} + +void +gr_msg_queue::flush() +{ + gr_message_sptr m; + + while ((m = delete_head_nowait ()) != 0) + ; +} diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.h b/gnuradio-core/src/lib/runtime/gr_msg_queue.h new file mode 100644 index 000000000..6a9147ee3 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.h @@ -0,0 +1,89 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef INCLUDED_GR_MSG_QUEUE_H +#define INCLUDED_GR_MSG_QUEUE_H + +#include +#include + +class gr_msg_queue; +typedef boost::shared_ptr gr_msg_queue_sptr; + +gr_msg_queue_sptr gr_make_msg_queue(unsigned int limit=0); + +/*! + * \brief thread-safe message queue + */ +class gr_msg_queue : public gr_msg_handler { + omni_mutex d_mutex; + omni_condition d_not_empty; + omni_condition d_not_full; + gr_message_sptr d_head; + gr_message_sptr d_tail; + unsigned int d_count; // # of messages in queue. + unsigned int d_limit; // max # of messages in queue. 0 -> unbounded + +public: + gr_msg_queue(unsigned int limit); + ~gr_msg_queue(); + + //! Generic msg_handler method: insert the message. + void handle(gr_message_sptr msg) { insert_tail (msg); } + + /*! + * \brief Insert message at tail of queue. + * \param msg message + * + * Block if queue if full. + */ + void insert_tail(gr_message_sptr msg); + + /*! + * \brief Delete message from head of queue and return it. + * Block if no message is available. + */ + gr_message_sptr delete_head(); + + /*! + * \brief If there's a message in the q, delete it and return it. + * If no message is available, return 0. + */ + gr_message_sptr delete_head_nowait(); + + //! Delete all messages from the queue + void flush(); + + //! is the queue empty? + bool empty_p() const { return d_count == 0; } + + //! is the queue full? + bool full_p() const { return d_limit != 0 && d_count >= d_limit; } + + //! return number of messages in queue + unsigned int count() const { return d_count; } + + //! return limit on number of message in queue. 0 -> unbounded + unsigned int limit() const { return d_limit; } + +}; + +#endif /* INCLUDED_GR_MSG_QUEUE_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i new file mode 100644 index 000000000..28292d66f --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -0,0 +1,111 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +class gr_msg_queue; +typedef boost::shared_ptr gr_msg_queue_sptr; +%template(gr_msg_queue_sptr) boost::shared_ptr; + +%rename(msg_queue) gr_make_msg_queue; +gr_msg_queue_sptr gr_make_msg_queue(unsigned limit=0); + +/*! + * \brief thread-safe message queue + */ +%ignore gr_msg_queue; +class gr_msg_queue : public gr_msg_handler { + omni_mutex d_mutex; + omni_condition d_cond; + gr_message_sptr d_head; + gr_message_sptr d_tail; + int d_count; + +public: + gr_msg_queue(); + ~gr_msg_queue(); + + //! Generic msg_handler method: insert the message. + //void handle(gr_message_sptr msg) { insert_tail (msg); } + + /*! + * \brief Insert message at tail of queue. + * \param msg message + * + * Block if queue if full. + */ + //void insert_tail(gr_message_sptr msg); + + /*! + * \brief Delete message from head of queue and return it. + * Block if no message is available. + */ + //gr_message_sptr delete_head(); + + /*! + * \brief If there's a message in the q, delete it and return it. + * If no message is available, return 0. + */ + gr_message_sptr delete_head_nowait(); + + //! is the queue empty? + bool empty_p() const; + + //! is the queue full? + bool full_p() const; + + //! return number of messages in queue + unsigned int count() const; + + //! Delete all messages from the queue + void flush(); +}; + +/* + * The following kludge-o-rama releases the Python global interpreter + * lock around these potentially blocking calls. We don't want + * libgnuradio-core to be dependent on Python, thus we create these + * functions that serve as replacements for the normal C++ delete_head + * and insert_tail methods. The %pythoncode smashes these new C++ + * functions into the gr.msg_queue wrapper class, so that everything + * appears normal. (An evil laugh is heard in the distance...) + */ +%inline { + gr_message_sptr gr_py_msg_queue__delete_head(gr_msg_queue_sptr q) { + gr_message_sptr msg; + Py_BEGIN_ALLOW_THREADS; // release global interpreter lock + msg = q->delete_head(); // possibly blocking call + Py_END_ALLOW_THREADS; // acquire global interpreter lock + return msg; + } + + void gr_py_msg_queue__insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg) { + Py_BEGIN_ALLOW_THREADS; // release global interpreter lock + q->insert_tail(msg); // possibly blocking call + Py_END_ALLOW_THREADS; // acquire global interpreter lock + } +} + +// smash in new python delete_head and insert_tail methods... +%pythoncode %{ +gr_msg_queue_sptr.delete_head = gr_py_msg_queue__delete_head +gr_msg_queue_sptr.insert_tail = gr_py_msg_queue__insert_tail +gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail +%} diff --git a/gnuradio-core/src/lib/runtime/gr_pagesize.cc b/gnuradio-core/src/lib/runtime/gr_pagesize.cc new file mode 100644 index 000000000..dec40678b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_pagesize.cc @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#if defined(_WIN32) && defined(HAVE_GETPAGESIZE) +extern "C" size_t getpagesize(void); +#endif + +int +gr_pagesize () +{ + static int s_pagesize = -1; + + if (s_pagesize == -1){ +#if defined(HAVE_GETPAGESIZE) + s_pagesize = getpagesize (); +#elif defined (HAVE_SYSCONF) + s_pagesize = sysconf (_SC_PAGESIZE); + if (s_pagesize == -1){ + perror ("_SC_PAGESIZE"); + s_pagesize = 4096; + } +#else + fprintf (stderr, "gr_pagesize: no info; setting pagesize = 4096\n"); + s_pagesize = 4096; +#endif + } + return s_pagesize; +} + diff --git a/gnuradio-core/src/lib/runtime/gr_pagesize.h b/gnuradio-core/src/lib/runtime/gr_pagesize.h new file mode 100644 index 000000000..a5cadb707 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_pagesize.h @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef _GR_PAGESIZE_H_ +#define _GR_PAGESIZE_H_ + +/*! + * \brief return the page size in bytes + */ + +int gr_pagesize (); + + +#endif /* _GR_PAGESIZE_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc new file mode 100644 index 000000000..854314447 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -0,0 +1,101 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + + +#ifdef MKDIR_TAKES_ONE_ARG +#define gr_mkdir(pathname, mode) mkdir(pathname) +#else +#define gr_mkdir(pathname, mode) mkdir((pathname), (mode)) +#endif + +/* + * The simplest thing that could possibly work: + * the key is the filename; the value is the file contents. + */ + +static const char * +pathname (const char *key) +{ + static char buf[200]; + snprintf (buf, sizeof (buf), "%s/.gnuradio/prefs/%s", getenv ("HOME"), key); + return buf; +} + +static void +ensure_dir_path () +{ + char path[200]; + struct stat statbuf; + + snprintf (path, sizeof (path), "%s/.gnuradio/prefs", getenv ("HOME")); + if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) + return; + + // blindly try to make it // FIXME make this robust. C++ SUCKS! + + snprintf (path, sizeof (path), "%s/.gnuradio", getenv ("HOME")); + gr_mkdir (path, 0750); + snprintf (path, sizeof (path), "%s/.gnuradio/prefs", getenv ("HOME")); + gr_mkdir (path, 0750); +} + +const char * +gr_preferences::get (const char *key) +{ + static char buf[1024]; + + FILE *fp = fopen (pathname (key), "r"); + if (fp == 0) + return 0; + + memset (buf, 0, sizeof (buf)); + fread (buf, 1, sizeof (buf) - 1, fp); + fclose (fp); + return buf; +} + +void +gr_preferences::set (const char *key, const char *value) +{ + ensure_dir_path (); + + FILE *fp = fopen (pathname (key), "w"); + if (fp == 0){ + perror (pathname (key)); + return; + } + + fwrite (value, 1, strlen (value), fp); + fclose (fp); +}; diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.h b/gnuradio-core/src/lib/runtime/gr_preferences.h new file mode 100644 index 000000000..5a7cad454 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_preferences.h @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _GR_PREFERENCES_H_ +#define _GR_PREFERENCES_H_ + +class gr_preferences { + public: + static const char *get (const char *key); + static void set (const char *key, const char *value); +}; + +#endif /* _GR_PREFERENCES_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.cc b/gnuradio-core/src/lib/runtime/gr_realtime.cc new file mode 100644 index 000000000..4f23ea0c6 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_realtime.cc @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include + +#ifdef HAVE_SCHED_H +#include +#endif + +#include +#include +#include + +#if defined(HAVE_SCHED_SETSCHEDULER) + +gr_rt_status_t +gr_enable_realtime_scheduling() +{ + int policy = SCHED_FIFO; + int pri = (sched_get_priority_max (policy) - sched_get_priority_min (policy)) / 2; + int pid = 0; // this process + + struct sched_param param; + memset(¶m, 0, sizeof(param)); + param.sched_priority = pri; + int result = sched_setscheduler(pid, policy, ¶m); + if (result != 0){ + if (errno == EPERM) + return RT_NO_PRIVS; + else { + perror ("sched_setscheduler: failed to set real time priority"); + return RT_OTHER_ERROR; + } + } + //printf("SCHED_FIFO enabled with priority = %d\n", pri); + return RT_OK; +} + +// #elif // could try negative niceness + +#else + +gr_rt_status_t +gr_enable_realtime_scheduling() +{ + return RT_NOT_IMPLEMENTED; +} + +#endif diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.h b/gnuradio-core/src/lib/runtime/gr_realtime.h new file mode 100644 index 000000000..3aeafa533 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_realtime.h @@ -0,0 +1,39 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_REALTIME_H +#define INCLUDED_GR_REALTIME_H + +typedef enum { + RT_OK = 0, + RT_NOT_IMPLEMENTED, + RT_NO_PRIVS, + RT_OTHER_ERROR +} gr_rt_status_t; + +/*! + * \brief If possible, enable high-priority "real time" scheduling. + */ +gr_rt_status_t +gr_enable_realtime_scheduling(); + +#endif /* INCLUDED_GR_REALTIME_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.i b/gnuradio-core/src/lib/runtime/gr_realtime.i new file mode 100644 index 000000000..cb43e0514 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_realtime.i @@ -0,0 +1,4 @@ +%rename(enable_realtime_scheduling) gr_enable_realtime_scheduling; + +%include + diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.h b/gnuradio-core/src/lib/runtime/gr_runtime.h new file mode 100644 index 000000000..f138e6ac4 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_runtime.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_RUNTIME_H +#define INCLUDED_GR_RUNTIME_H + +#include + +/* + * typedefs for smart pointers we use throughout the runtime system + */ + +class gr_block; +class gr_block_detail; +class gr_io_signature; +class gr_buffer; +class gr_buffer_reader; + +typedef boost::shared_ptr gr_block_sptr; +typedef boost::shared_ptr gr_block_detail_sptr; +typedef boost::shared_ptr gr_io_signature_sptr; +typedef boost::shared_ptr gr_buffer_sptr; +typedef boost::shared_ptr gr_buffer_reader_sptr; + +#endif /* INCLUDED_GR_RUNTIME_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.cc b/gnuradio-core/src/lib/runtime/gr_select_handler.cc new file mode 100644 index 000000000..d85883a65 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.cc @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +gr_select_handler::gr_select_handler(int fd) + : d_fd(fd) +{ +} + +gr_select_handler::~gr_select_handler() +{ +} diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.h b/gnuradio-core/src/lib/runtime/gr_select_handler.h new file mode 100644 index 000000000..d07ff007f --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.h @@ -0,0 +1,83 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_SELECT_HANDLER_H +#define INCLUDED_GR_SELECT_HANDLER_H + +#include + +class gr_select_handler; +typedef boost::shared_ptr gr_select_handler_sptr; + + +/*! + * \brief Abstract handler for select based notification. + * + * \sa gr_dispatcher + */ +class gr_select_handler +{ + int d_fd; + +protected: + gr_select_handler(int file_descriptor); + +public: + virtual ~gr_select_handler(); + + int fd() const { return d_fd; } + int file_descriptor() const { return d_fd; } + + /*! + * \brief Called when file_descriptor is readable. + * + * Called when the dispatcher detects that file_descriptor can + * be read without blocking. + */ + virtual void handle_read() = 0; + + /*! + * \brief Called when file_descriptor is writable. + * + * Called when dispatcher detects that file descriptor can be + * written without blocking. + */ + virtual void handle_write() = 0; + + /*! + * Called each time around the dispatcher loop to determine whether + * this handler's file descriptor should be added to the list on which + * read events can occur. The default method returns true, indicating + * that by default, all handlers are interested in read events. + */ + virtual bool readable() { return true; } + + /*! + * Called each time around the dispatcher loop to determine whether + * this handler's file descriptor should be added to the list on which + * write events can occur. The default method returns true, indicating + * that by default, all handlers are interested in write events. + */ + virtual bool writable() { return true; } +}; + +#endif /* INCLUDED_GR_SELECT_HANDLER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc new file mode 100644 index 000000000..3d401557b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc @@ -0,0 +1,360 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +// must be defined to either 0 or 1 +#define ENABLE_LOGGING 0 + +#if (ENABLE_LOGGING) +#define LOG(x) do { x; } while(0) +#else +#define LOG(x) do {;} while(0) +#endif + +static int which_scheduler = 0; + + +std::ostream& +operator << (std::ostream& os, const gr_block *m) +{ + os << "name() << " (" << m->unique_id() << ")>"; + return os; +} + +gr_single_threaded_scheduler_sptr +gr_make_single_threaded_scheduler (const std::vector &blocks) +{ + return + gr_single_threaded_scheduler_sptr (new gr_single_threaded_scheduler (blocks)); +} + +gr_single_threaded_scheduler::gr_single_threaded_scheduler ( + const std::vector &blocks) + : d_blocks (blocks), d_enabled (true), d_log(0) +{ + if (ENABLE_LOGGING){ + char name[100]; + snprintf(name, sizeof(name), "sst-%d.log", which_scheduler++); + d_log = new std::ofstream(name); + *d_log << "gr_single_threaded_scheduler: " + << d_blocks.size () + << " blocks\n"; + } +} + +gr_single_threaded_scheduler::~gr_single_threaded_scheduler () +{ + if (ENABLE_LOGGING) + delete d_log; +} + +void +gr_single_threaded_scheduler::run () +{ + d_enabled = true; + main_loop (); +} + + +inline static unsigned int +round_up (unsigned int n, unsigned int multiple) +{ + return ((n + multiple - 1) / multiple) * multiple; +} + +inline static unsigned int +round_down (unsigned int n, unsigned int multiple) +{ + return (n / multiple) * multiple; +} + +// +// Return minimum available write space in all our downstream buffers +// or -1 if we're output blocked and the output we're blocked +// on is done. +// +static int +min_available_space (gr_block_detail *d, int output_multiple) +{ + int min_space = std::numeric_limits::max(); + + for (int i = 0; i < d->noutputs (); i++){ + int n = round_down (d->output(i)->space_available (), output_multiple); + if (n == 0){ // We're blocked on output. + if (d->output(i)->done()){ // Downstream is done, therefore we're done. + return -1; + } + return 0; + } + min_space = std::min (min_space, n); + } + return min_space; +} + +void +gr_single_threaded_scheduler::main_loop () +{ + static const int DEFAULT_CAPACITY = 16; + + int noutput_items; + gr_vector_int ninput_items_required (DEFAULT_CAPACITY); + gr_vector_int ninput_items (DEFAULT_CAPACITY); + gr_vector_const_void_star input_items (DEFAULT_CAPACITY); + gr_vector_void_star output_items (DEFAULT_CAPACITY); + unsigned int bi; + unsigned int nalive; + int max_items_avail; + bool made_progress_last_pass; + bool making_progress; + + for (unsigned i = 0; i < d_blocks.size (); i++) + d_blocks[i]->detail()->set_done (false); // reset any done flags + + for (unsigned i = 0; i < d_blocks.size (); i++) // enable any drivers, etc. + d_blocks[i]->start(); + + + bi = 0; + made_progress_last_pass = true; + making_progress = false; + + // Loop while there are still blocks alive + + nalive = d_blocks.size (); + while (d_enabled && nalive > 0){ + + gr_block *m = d_blocks[bi].get (); + gr_block_detail *d = m->detail().get (); + + LOG(*d_log << std::endl << m); + + if (d->done ()) + goto next_block; + + if (d->source_p ()){ + // Invoke sources as a last resort. As long as the previous pass + // made progress, don't call a source. + if (made_progress_last_pass){ + LOG(*d_log << " Skipping source\n"); + goto next_block; + } + + ninput_items_required.resize (0); + ninput_items.resize (0); + input_items.resize (0); + output_items.resize (d->noutputs ()); + + // determine the minimum available output space + noutput_items = min_available_space (d, m->output_multiple ()); + LOG(*d_log << " source\n noutput_items = " << noutput_items << std::endl); + if (noutput_items == -1) // we're done + goto were_done; + + if (noutput_items == 0){ // we're output blocked + LOG(*d_log << " BLKD_OUT\n"); + goto next_block; + } + + goto setup_call_to_work; // jump to common code + } + + else if (d->sink_p ()){ + ninput_items_required.resize (d->ninputs ()); + ninput_items.resize (d->ninputs ()); + input_items.resize (d->ninputs ()); + output_items.resize (0); + LOG(*d_log << " sink\n"); + + max_items_avail = 0; + for (int i = 0; i < d->ninputs (); i++){ + ninput_items[i] = d->input(i)->items_available(); + //if (ninput_items[i] == 0 && d->input(i)->done()) + if (ninput_items[i] < m->output_multiple() && d->input(i)->done()) + goto were_done; + + max_items_avail = std::max (max_items_avail, ninput_items[i]); + } + + // take a swag at how much output we can sink + noutput_items = (int) (max_items_avail * m->relative_rate ()); + noutput_items = round_down (noutput_items, m->output_multiple ()); + LOG(*d_log << " max_items_avail = " << max_items_avail << std::endl); + LOG(*d_log << " noutput_items = " << noutput_items << std::endl); + + if (noutput_items == 0){ // we're blocked on input + LOG(*d_log << " BLKD_IN\n"); + goto next_block; + } + + goto try_again; // Jump to code shared with regular case. + } + + else { + // do the regular thing + ninput_items_required.resize (d->ninputs ()); + ninput_items.resize (d->ninputs ()); + input_items.resize (d->ninputs ()); + output_items.resize (d->noutputs ()); + + max_items_avail = 0; + for (int i = 0; i < d->ninputs (); i++){ + ninput_items[i] = d->input(i)->items_available (); + max_items_avail = std::max (max_items_avail, ninput_items[i]); + } + + // determine the minimum available output space + noutput_items = min_available_space (d, m->output_multiple ()); + if (ENABLE_LOGGING){ + *d_log << " regular "; + if (m->relative_rate() >= 1.0) + *d_log << "1:" << m->relative_rate() << std::endl; + else + *d_log << 1.0/m->relative_rate() << ":1\n"; + *d_log << " max_items_avail = " << max_items_avail << std::endl; + *d_log << " noutput_items = " << noutput_items << std::endl; + } + if (noutput_items == -1) // we're done + goto were_done; + + if (noutput_items == 0){ // we're output blocked + LOG(*d_log << " BLKD_OUT\n"); + goto next_block; + } + +#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. + // We want to try to consume all the input we've got. + int reqd_noutput_items = m->fixed_rate_ninput_to_noutput(max_items_avail); + reqd_noutput_items = round_up(reqd_noutput_items, m->output_multiple()); + if (reqd_noutput_items > 0 && reqd_noutput_items <= noutput_items) + noutput_items = reqd_noutput_items; + } + + // ask the block how much input they need to produce noutput_items + m->forecast (noutput_items, ninput_items_required); + + // See if we've got sufficient input available + + int i; + for (i = 0; i < d->ninputs (); i++) + if (ninput_items_required[i] > ninput_items[i]) // not enough + break; + + if (i < d->ninputs ()){ // not enough input on input[i] + // if we can, try reducing the size of our output request + if (noutput_items > m->output_multiple ()){ + noutput_items /= 2; + noutput_items = round_up (noutput_items, m->output_multiple ()); + goto try_again; + } + + // We're blocked on input + LOG(*d_log << " BLKD_IN\n"); + if (d->input(i)->done()) // If the upstream block is done, we're done + goto were_done; + + // Is it possible to ever fulfill this request? + if (ninput_items_required[i] > d->input(i)->max_possible_items_available ()){ + // Nope, never going to happen... + std::cerr << "\nsched: name() + << " (" << m->unique_id() << ")>" + << " is requesting more input data\n" + << " than we can provide.\n" + << " ninput_items_required = " + << ninput_items_required[i] << "\n" + << " max_possible_items_available = " + << d->input(i)->max_possible_items_available() << "\n" + << " If this is a filter, consider reducing the number of taps.\n"; + goto were_done; + } + + goto next_block; + } + + // We've got enough data on each input to produce noutput_items. + // Finish setting up the call to work. + + for (int i = 0; i < d->ninputs (); i++) + input_items[i] = d->input(i)->read_pointer(); + + setup_call_to_work: + + for (int i = 0; i < d->noutputs (); i++) + output_items[i] = d->output(i)->write_pointer(); + + // Do the actual work of the block + int n = m->general_work (noutput_items, ninput_items, + input_items, output_items); + LOG(*d_log << " general_work: noutput_items = " << noutput_items + << " result = " << n << std::endl); + + if (n == -1) // block is done + goto were_done; + + d->produce_each (n); // advance write pointers + if (n > 0) + making_progress = true; + + goto next_block; + } + assert (0); + + were_done: + LOG(*d_log << " were_done\n"); + d->set_done (true); + nalive--; + + next_block: + if (++bi >= d_blocks.size ()){ + bi = 0; + made_progress_last_pass = making_progress; + making_progress = false; + } + } + + for (unsigned i = 0; i < d_blocks.size (); i++) // disable any drivers, etc. + d_blocks[i]->stop(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h new file mode 100644 index 000000000..1272831e5 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h @@ -0,0 +1,61 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_SINGLE_THREADED_SCHEDULER_H +#define INCLUDED_GR_SINGLE_THREADED_SCHEDULER_H + +#include +#include + +class gr_single_threaded_scheduler; +typedef boost::shared_ptr gr_single_threaded_scheduler_sptr; + + +/*! + * \brief Simple scheduler for stream computations. + * \ingroup internal + */ + +class gr_single_threaded_scheduler { + public: + ~gr_single_threaded_scheduler (); + + void run (); + void stop () { d_enabled = false; } + + private: + const std::vector d_blocks; + volatile bool d_enabled; + std::ofstream *d_log; + + gr_single_threaded_scheduler (const std::vector &blocks); + + void main_loop (); + + friend gr_single_threaded_scheduler_sptr + gr_make_single_threaded_scheduler (const std::vector &blocks); +}; + +gr_single_threaded_scheduler_sptr +gr_make_single_threaded_scheduler (const std::vector &blocks); + +#endif /* INCLUDED_GR_SINGLE_THREADED_SCHEDULER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i new file mode 100644 index 000000000..40058228b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +class gr_single_threaded_scheduler; +typedef boost::shared_ptr gr_single_threaded_scheduler_sptr; +%template(gr_single_threaded_scheduler_sptr) boost::shared_ptr; +%rename(single_threaded_scheduler) gr_make_single_threaded_scheduler; +%ignore gr_single_threaded_scheduler; + +gr_single_threaded_scheduler_sptr +gr_make_single_threaded_scheduler (const std::vector &modules); + +class gr_single_threaded_scheduler { + public: + ~gr_single_threaded_scheduler (); + + // void run (); + void stop (); + + private: + gr_single_threaded_scheduler (const std::vector &modules); +}; + +%inline { + void sts_pyrun (gr_single_threaded_scheduler_sptr s) { + Py_BEGIN_ALLOW_THREADS; // release global interpreter lock + s->run (); + Py_END_ALLOW_THREADS; // acquire global interpreter lock + } +} + diff --git a/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i b/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i new file mode 100644 index 000000000..ca4f6e600 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i @@ -0,0 +1,45 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +%define GR_SWIG_BLOCK_MAGIC(PKG, BASE_NAME) +_GR_SWIG_BLOCK_MAGIC_HELPER(PKG, PKG ## _ ## BASE_NAME, BASE_NAME) +%enddef + +%define _GR_SWIG_BLOCK_MAGIC_HELPER(PKG, NAME, BASE_NAME) +class NAME; +typedef boost::shared_ptr NAME ## _sptr; +%template(NAME ## _sptr) boost::shared_ptr; +%rename(BASE_NAME) PKG ## _make_ ## BASE_NAME; +%inline { + gr_block_sptr NAME ## _block (NAME ## _sptr r) + { + return gr_block_sptr (r); + } +} + +%pythoncode %{ +NAME ## _sptr.block = lambda self: NAME ## _block (self) +NAME ## _sptr.__repr__ = lambda self: "" % (self.name(), self.unique_id ()) +%} + +%ignore NAME; +%enddef diff --git a/gnuradio-core/src/lib/runtime/gr_timer.h b/gnuradio-core/src/lib/runtime/gr_timer.h new file mode 100644 index 000000000..709b98470 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_timer.h @@ -0,0 +1,82 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef INCLUDED_GR_TIMER_H +#define INCLUDED_GR_TIMER_H + +#include + +class gr_timer; + +typedef boost::shared_ptr gr_timer_sptr; + +typedef void (*gr_timer_hook)(gr_timer *, void *); + +/*! + * \brief create a timeout. + * + * gr_timer_hook is called when timer fires. + */ +gr_timer_sptr gr_make_timer (gr_timer_hook, void *); + +/*! + * \brief implement timeouts + */ +class gr_timer { + double d_expiry; + double d_period; + gr_timer_hook d_hook; + void *d_hook_arg; + + friend gr_timer_sptr gr_make_timer (gr_timer_hook, void *); + + gr_timer (...); + +public: + ~gr_timer (); + + //! return absolute current time (seconds since the epoc). + static double now (); + + /*! + * \brief schedule timer to fire at abs_when + * \param abs_when absolute time in seconds since the epoc. + */ + void schedule_at (double abs_when); + + /*! + * \brief schedule timer to fire rel_when seconds from now. + * \param rel_when relative time in seconds from now. + */ + void schedule_after (double rel_when); // relative time in seconds + + /*! + * \brief schedule a periodic timeout. + * \param abs_when absolute time to fire first time + * \param period time between firings + */ + void schedule_periodic (double abs_when, double period); + + //! cancel timer + void unschedule (); +}; + +#endif /* INCLUDED_GR_TIMER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc b/gnuradio-core/src/lib/runtime/gr_tmp_path.cc new file mode 100644 index 000000000..7eb03b5d5 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tmp_path.cc @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include + +const char * +gr_tmp_path () +{ + static char *pp = 0; + + if (pp) + return pp; + + char *s = getenv ("TMP"); + if (s){ + pp = strdup (s); + return pp; + } + +#ifdef P_tmpdir + if (P_tmpdir){ + pp = strdup (P_tmpdir); + return pp; + } +#endif + + pp = strdup ("/tmp"); + return pp; +} + diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.h b/gnuradio-core/src/lib/runtime/gr_tmp_path.h new file mode 100644 index 000000000..742ce0563 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tmp_path.h @@ -0,0 +1,31 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _GR_TMP_PATH_H_ +#define _GR_TMP_PATH_H_ + +/*! + * \brief return directory portion of pathname used for temporary files. + */ +const char *gr_tmp_path (); + +#endif /* _GR_TMP_PATH_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h new file mode 100644 index 000000000..370ca5642 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_TYPES_H +#define INCLUDED_GR_TYPES_H + +#include +#include +#include // size_t + +#include + +typedef std::vector gr_vector_int; +typedef std::vector gr_vector_float; +typedef std::vector gr_vector_double; +typedef std::vector gr_vector_void_star; +typedef std::vector gr_vector_const_void_star; + +/* + * #include must be placed beforehand + * in the source file including gr_types.h for + * the following to work correctly + */ +#ifdef HAVE_STDINT_H +#include +typedef int16_t gr_int16; +typedef int32_t gr_int32; +typedef int64_t gr_int64; +typedef uint16_t gr_uint16; +typedef uint32_t gr_uint32; +typedef uint64_t gr_uint64; +#else +/* + * Note: these defaults may be wrong on 64-bit systems + */ +typedef short gr_int16; +typedef int gr_int32; +typedef long long gr_int64; +typedef unsigned short gr_uint16; +typedef unsigned int gr_uint32; +typedef unsigned long long gr_uint64; +#endif /* HAVE_STDINT_H */ + +#endif /* INCLUDED_GR_TYPES_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc new file mode 100644 index 000000000..3586c4c73 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc @@ -0,0 +1,291 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include +#include +#include + +// all the factories we know about +#include +#include +#include +#include + +static const char *FACTORY_PREF_KEY = "gr_vmcircbuf_default_factory"; + +gr_vmcircbuf::~gr_vmcircbuf () +{ +} + +gr_vmcircbuf_factory::~gr_vmcircbuf_factory () +{ +} + +// ---------------------------------------------------------------- + +static gr_vmcircbuf_factory *s_default_factory = 0; + +gr_vmcircbuf_factory * +gr_vmcircbuf_sysconfig::get_default_factory () +{ + if (s_default_factory) + return s_default_factory; + + bool verbose = false; + + std::vector all = all_factories (); + + const char *name = gr_preferences::get (FACTORY_PREF_KEY); + + if (name){ + for (unsigned int i = 0; i < all.size (); i++){ + if (strcmp (name, all[i]->name ()) == 0){ + s_default_factory = all[i]; + if (verbose) + fprintf (stderr, "gr_vmcircbuf_sysconfig: using %s\n", + s_default_factory->name ()); + return s_default_factory; + } + } + } + + // either we don't have a default, or the default named is not in our + // list of factories. Find the first factory that works. + + if (verbose) + fprintf (stderr, "gr_vmcircbuf_sysconfig: finding a working factory...\n"); + + for (unsigned int i = 0; i < all.size (); i++){ + if (test_factory (all[i], verbose)){ + set_default_factory (all[i]); + return s_default_factory; + } + } + + // We're screwed! + + fprintf (stderr, "gr_vmcircbuf_sysconfig: unable to find a working factory!\n"); + throw std::runtime_error ("gr_vmcircbuf_sysconfig"); +} + +std::vector +gr_vmcircbuf_sysconfig::all_factories () +{ + std::vector result; + + result.push_back (gr_vmcircbuf_createfilemapping_factory::singleton ()); + result.push_back (gr_vmcircbuf_sysv_shm_factory::singleton ()); + result.push_back (gr_vmcircbuf_mmap_shm_open_factory::singleton ()); + result.push_back (gr_vmcircbuf_mmap_tmpfile_factory::singleton ()); + + return result; +} + +void +gr_vmcircbuf_sysconfig::set_default_factory (gr_vmcircbuf_factory *f) +{ + gr_preferences::set (FACTORY_PREF_KEY, f->name ()); + s_default_factory = f; +} + + +// ------------------------------------------------------------------------ +// test code for vmcircbuf factories +// ------------------------------------------------------------------------ + +static void +init_buffer (gr_vmcircbuf *c, int counter, int size) +{ + unsigned int *p = (unsigned int *) c->pointer_to_first_copy (); + for (unsigned int i = 0; i < size / sizeof (int); i++) + p[i] = counter + i; +} + +static bool +check_mapping (gr_vmcircbuf *c, int counter, int size, char *msg, bool verbose) +{ + bool ok = true; + + if (verbose) + fprintf (stderr, "... %s", msg); + + unsigned int *p1 = (unsigned int *) c->pointer_to_first_copy (); + unsigned int *p2 = (unsigned int *) c->pointer_to_second_copy (); + + // fprintf (stderr, "p1 = %p, p2 = %p\n", p1, p2); + + for (unsigned int i = 0; i < size / sizeof (int); i++){ + if (p1[i] != counter + i){ + ok = false; + if (verbose) + fprintf (stderr, " p1[%d] == %u, expected %u\n", i, p1[i], counter + i); + break; + } + if (p2[i] != counter + i){ + if (verbose) + fprintf (stderr, " p2[%d] == %u, expected %u\n", i, p2[i], counter + i); + ok = false; + break; + } + } + + if (ok && verbose){ + fprintf (stderr, " OK\n"); + } + return ok; +} + +static char * +memsize (int size) +{ + static char buf[100]; + if (size >= (1 << 20)){ + snprintf (buf, sizeof (buf), "%dMB", size / (1 << 20)); + } + else if (size >= (1 << 10)){ + snprintf (buf, sizeof (buf), "%dKB", size / (1 << 10)); + } + else { + snprintf (buf, sizeof (buf), "%d", size); + } + return buf; +} + +static bool +test_a_bunch (gr_vmcircbuf_factory *factory, int n, int size, int *start_ptr, bool verbose) +{ + bool ok = true; + int counter[n]; + gr_vmcircbuf *c[n]; + int cum_size = 0; + + for (int i = 0; i < n; i++){ + counter[i] = *start_ptr; + *start_ptr += size; + if ((c[i] = factory->make (size)) == 0){ + if (verbose) + fprintf (stderr, + "Failed to allocate gr_vmcircbuf number %d of size %d (cum = %s)\n", + i + 1, size, memsize (cum_size)); + return false; + } + init_buffer (c[i], counter[i], size); + cum_size += size; + } + + for (int i = 0; i < n; i++){ + char msg[100]; + snprintf (msg, sizeof (msg), "test_a_bunch_%dx%s[%d]", n, memsize (size), i); + ok &= check_mapping (c[i], counter[i], size, msg, verbose); + } + + for (int i = 0; i < n; i++){ + delete c[i]; + c[i] = 0; + } + + return ok; +} + +static bool +standard_tests (gr_vmcircbuf_factory *f, int verbose) +{ + if (verbose >= 1) + fprintf (stderr, "Testing %s...\n", f->name ()); + + bool v = verbose >= 2; + int granularity = f->granularity (); + int start = 0; + bool ok = true; + + ok &= test_a_bunch (f, 1, 1 * granularity, &start, v); // 1 x 4KB = 4KB + + if (ok){ + ok &= test_a_bunch (f, 64, 4 * granularity, &start, v); // 256 x 16KB = 4MB + ok &= test_a_bunch (f, 32, 4 * (1L << 20), &start, v); // 32 x 4MB = 64MB + ok &= test_a_bunch (f, 256, 256 * (1L << 10), &start, v); // 256 x 256KB = 64MB + } + + if (verbose >= 1) + fprintf (stderr, "....... %s: %s", f->name (), ok ? "OK\n" : "Doesn't work\n"); + + return ok; +} + +bool +gr_vmcircbuf_sysconfig::test_factory (gr_vmcircbuf_factory *f, int verbose) +{ + // Install local signal handlers for SIGSEGV and SIGBUS. + // If something goes wrong, these signals may be invoked. + +#ifdef SIGSEGV + gr_local_sighandler sigsegv (SIGSEGV, gr_local_sighandler::throw_signal); +#endif +#ifdef SIGBUS + gr_local_sighandler sigbus (SIGBUS, gr_local_sighandler::throw_signal); +#endif +#ifdef SIGSYS + gr_local_sighandler sigsys (SIGSYS, gr_local_sighandler::throw_signal); +#endif + + try { + return standard_tests (f, verbose); + } + catch (gr_signal &sig){ + if (verbose){ + fprintf (stderr, "....... %s: %s", f->name (), "Doesn't work\n"); + fprintf (stderr, + "gr_vmcircbuf_factory::test_factory (%s): caught %s\n", + f->name (), sig.name().c_str()); + return false; + } + } + catch (...){ + if (verbose){ + fprintf (stderr, "....... %s: %s", f->name (), "Doesn't work\n"); + fprintf (stderr, + "gr_vmcircbuf_factory::test_factory (%s): some kind of uncaught exception\n", + f->name ()); + } + return false; + } + return false; // never gets here. shut compiler up. +} + +bool +gr_vmcircbuf_sysconfig::test_all_factories (int verbose) +{ + bool ok = false; + + std::vector all = all_factories (); + + for (unsigned int i = 0; i < all.size (); i++) + ok |= test_factory (all[i], verbose); + + return ok; +} diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h new file mode 100644 index 000000000..e2af93587 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h @@ -0,0 +1,120 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _GR_VMCIRCBUF_H_ +#define _GR_VMCIRCBUF_H_ + +#include + +/*! + * \brief abstract class to implement doubly mapped virtual memory circular buffers + */ +class gr_vmcircbuf { + protected: + int d_size; + char *d_base; + + // CREATORS + gr_vmcircbuf (int size) : d_size (size), d_base (0) {}; + + public: + virtual ~gr_vmcircbuf (); + + // ACCESSORS + void *pointer_to_first_copy () const { return d_base; } + void *pointer_to_second_copy () const { return d_base + d_size; } +}; + +/*! + * \brief abstract factory for creating circular buffers + */ +class gr_vmcircbuf_factory { + protected: + gr_vmcircbuf_factory () {}; + virtual ~gr_vmcircbuf_factory (); + + public: + + /*! + * \brief return name of this factory + */ + virtual const char *name () const = 0; + + /*! + * \brief return granularity of mapping, typically equal to page size + */ + virtual int granularity () = 0; + + /*! + * \brief return a gr_vmcircbuf, or 0 if unable. + * + * Call this to create a doubly mapped circular buffer. + */ + virtual gr_vmcircbuf *make (int size) = 0; +}; + +/* + * \brief pulls together all implementations of gr_vmcircbuf + */ +class gr_vmcircbuf_sysconfig { + public: + + /* + * \brief return the single instance of the default factory. + * + * returns the default factory to use if it's already defined, + * else find the first working factory and use it. + */ + static gr_vmcircbuf_factory *get_default_factory (); + + + static int granularity () { return get_default_factory()->granularity(); } + static gr_vmcircbuf *make (int size) { return get_default_factory()->make(size); } + + + // N.B. not all factories are guaranteed to work. + // It's too hard to check everything at config time, so we check at runtime + static std::vector all_factories (); + + // make this factory the default + static void set_default_factory (gr_vmcircbuf_factory *f); + + /*! + * \brief Does this factory really work? + * + * verbose = 0: silent + * verbose = 1: names of factories tested and results + * verbose = 2: all intermediate results + */ + static bool test_factory (gr_vmcircbuf_factory *f, int verbose); + + /*! + * \brief Test all factories, return true if at least one of them works + * verbose = 0: silent + * verbose = 1: names of factories tested and results + * verbose = 2: all intermediate results + */ + static bool test_all_factories (int verbose); +}; + + +#endif /* _GR_VMCIRCBUF_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc new file mode 100644 index 000000000..8f3540b4b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc @@ -0,0 +1,191 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_MMAN_H +#include +#endif +#include +#include +#include +#include +#include + + +gr_vmcircbuf_createfilemapping::gr_vmcircbuf_createfilemapping (int size) + : gr_vmcircbuf (size) +{ +#if !defined(HAVE_CREATEFILEMAPPING) + fprintf (stderr, "%s: createfilemapping is not available\n",__FUNCTION__); + throw std::runtime_error ("gr_vmcircbuf_createfilemapping"); +#else + static int s_seg_counter = 0; + + if (size <= 0 || (size % gr_pagesize ()) != 0){ + fprintf (stderr, "gr_vmcircbuf_createfilemapping: invalid size = %d\n", size); + throw std::runtime_error ("gr_vmcircbuf_createfilemapping"); + } + + char seg_name[1024]; + snprintf (seg_name, sizeof (seg_name), "/gnuradio-%d-%d", getpid (), s_seg_counter); + + d_handle = CreateFileMapping(INVALID_HANDLE_VALUE, // use paging file + NULL, // default security + PAGE_READWRITE, // read/write access + 0, // max. object size + size, // buffer size + seg_name); // name of mapping object + + s_seg_counter++; + if (d_handle == NULL || d_handle == INVALID_HANDLE_VALUE){ + char msg[1024]; + snprintf (msg, sizeof (msg), "gr_vmcircbuf_mmap_createfilemapping: CreateFileMapping [%s] :%d", seg_name,(int)GetLastError()); + perror (msg); + throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); + } + + int i = 0; + d_first_copy = d_second_copy = NULL; + + while (i++ < 8 && d_second_copy == NULL){ + // keep the first map allocation to force allocation in a new address + // space + LPVOID first_tmp = d_first_copy; + + d_first_copy = MapViewOfFile((HANDLE)d_handle, // handle to map object + FILE_MAP_WRITE, // read/write permission + 0, + 0, + size); + + if (d_first_copy == NULL){ + if (first_tmp) + UnmapViewOfFile(first_tmp); + + CloseHandle(d_handle); // cleanup + char msg[1024]; + snprintf (msg, sizeof (msg), + "gr_vmcircbuf_mmap_createfilemapping: MapViewOfFile (1) :%d", (int)GetLastError()); + perror (msg); + throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); + } + + // NOTE: d_second_copy will be NULL if MapViewFileEx() fails to allocate the + // requested address space + d_second_copy = MapViewOfFileEx((HANDLE)d_handle, // handle to map object + FILE_MAP_WRITE, // read/write permission + 0, + 0, + size, + (char *)d_first_copy + size);//(LPVOID) ((char *)d_first_copy + size)); + + if (first_tmp) + UnmapViewOfFile(first_tmp); + +#ifdef DEBUG + fprintf (stderr,"gr_vmcircbuf_mmap_createfilemapping: contiguous? mmap %p %p %p %p, %d\n", + (char *)d_first_copy, (char *)d_second_copy, size, (char *)d_first_copy + size,i); +#endif + } + + if (d_second_copy == NULL){ // cleanup + fprintf (stderr,"gr_vmcircbuf_mmap_createfilemapping: non contiguous mmap - %p %p %p %p\n", + d_first_copy, d_second_copy, size, (char *)d_first_copy + size); + UnmapViewOfFile(d_first_copy); + CloseHandle(d_handle); // cleanup + throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); + } + + // Now remember the important stuff + d_base = (char *) d_first_copy; + d_size = size; +#endif /*HAVE_CREATEFILEMAPPING*/ +} + +gr_vmcircbuf_createfilemapping::~gr_vmcircbuf_createfilemapping () +{ +#ifdef HAVE_CREATEFILEMAPPING + if (UnmapViewOfFile(d_first_copy) == 0) + { + perror ("gr_vmcircbuf_createfilemapping: UnmapViewOfFile(d_first_copy)"); + } + d_base=NULL; + if (UnmapViewOfFile(d_second_copy) == 0) + { + perror ("gr_vmcircbuf_createfilemapping: UnmapViewOfFile(d_second_copy)"); + } + //d_second=NULL; + CloseHandle(d_handle); +#endif +} + +// ---------------------------------------------------------------- +// The factory interface +// ---------------------------------------------------------------- + + +gr_vmcircbuf_factory *gr_vmcircbuf_createfilemapping_factory::s_the_factory = 0; + +gr_vmcircbuf_factory * +gr_vmcircbuf_createfilemapping_factory::singleton () +{ + if (s_the_factory) + return s_the_factory; + s_the_factory = new gr_vmcircbuf_createfilemapping_factory (); + return s_the_factory; +} + +int +gr_vmcircbuf_createfilemapping_factory::granularity () +{ +#ifdef HAVE_CREATEFILEMAPPING + // return 65536;//TODO, check, is this needed or can we just use gr_pagesize() + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + //fprintf(stderr,"win32 AllocationGranularity %p\n",(int)system_info.dwAllocationGranularity); + return (int)system_info.dwAllocationGranularity; +#else + return gr_pagesize (); +#endif +} + +gr_vmcircbuf * +gr_vmcircbuf_createfilemapping_factory::make (int size) +{ + try + { + return new gr_vmcircbuf_createfilemapping (size); + } + catch (...) + { + return 0; + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h new file mode 100644 index 000000000..f7113cf4f --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h @@ -0,0 +1,74 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _GR_VMCIRCBUF_CREATEFILEMAPPING_H_ +#define _GR_VMCIRCBUF_CREATEFILEMAPPING_H_ + +#include + +#ifdef HAVE_CREATEFILEMAPPING +#include +#endif +/*! + * \brief concrete class to implement circular buffers with mmap and shm_open + */ +class gr_vmcircbuf_createfilemapping : public gr_vmcircbuf +{ + public: + // CREATORS + gr_vmcircbuf_createfilemapping (int size); + virtual ~gr_vmcircbuf_createfilemapping (); +#ifdef HAVE_CREATEFILEMAPPING + private: + HANDLE d_handle; + LPVOID d_first_copy; + LPVOID d_second_copy; +#endif +}; + +/*! + * \brief concrete factory for circular buffers built using mmap and shm_open + */ +class gr_vmcircbuf_createfilemapping_factory : public gr_vmcircbuf_factory +{ + private: + static gr_vmcircbuf_factory *s_the_factory; + + public: + static gr_vmcircbuf_factory *singleton (); + + virtual const char *name () const { return "gr_vmcircbuf_createfilemapping_factory"; } + + /*! + * \brief return granularity of mapping, typically equal to page size + */ + virtual int granularity (); + + /*! + * \brief return a gr_vmcircbuf, or 0 if unable. + * + * Call this to create a doubly mapped circular buffer. + */ + virtual gr_vmcircbuf *make (int size); +}; + +#endif /* _GR_VMCIRCBUF_CREATEFILEMAPPING_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc new file mode 100644 index 000000000..65fa1183b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc @@ -0,0 +1,205 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_MMAN_H +#include +#endif +#include +#include +#include +#include + + +gr_vmcircbuf_mmap_shm_open::gr_vmcircbuf_mmap_shm_open (int size) + : gr_vmcircbuf (size) +{ +#if !defined(HAVE_MMAP) || !defined(HAVE_SHM_OPEN) + fprintf (stderr, "gr_vmcircbuf_mmap_shm_open: mmap or shm_open is not available\n"); + throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); +#else + static int s_seg_counter = 0; + + if (size <= 0 || (size % gr_pagesize ()) != 0){ + fprintf (stderr, "gr_vmcircbuf_mmap_shm_open: invalid size = %d\n", size); + throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); + } + + int shm_fd = -1; + char seg_name[1024]; + static bool portable_format = true; + + // open a new named shared memory segment + + while (1){ + if (portable_format){ + + // This is the POSIX recommended "portable format". + // Of course the "portable format" doesn't work on some systems... + + snprintf (seg_name, sizeof (seg_name), + "/gnuradio-%d-%d", getpid (), s_seg_counter); + } + else { + + // Where the "portable format" doesn't work, we try building + // a full filesystem pathname pointing into a suitable temporary directory. + + snprintf (seg_name, sizeof (seg_name), + "%s/gnuradio-%d-%d", gr_tmp_path (), getpid (), s_seg_counter); + } + + shm_fd = shm_open (seg_name, O_RDWR | O_CREAT | O_EXCL, 0600); + if (shm_fd == -1 && errno == EACCES && portable_format){ + portable_format = false; + continue; // try again using "non-portable format" + } + + s_seg_counter++; + + if (shm_fd == -1){ + if (errno == EEXIST) // Named segment already exists (shouldn't happen). Try again + continue; + + char msg[1024]; + snprintf (msg, sizeof (msg), "gr_vmcircbuf_mmap_shm_open: shm_open [%s]", seg_name); + perror (msg); + throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); + } + break; + } + + // We've got a new shared memory segment fd open. + // Now set it's length to 2x what we really want and mmap it in. + + if (ftruncate (shm_fd, (off_t) 2 * size) == -1){ + close (shm_fd); // cleanup + perror ("gr_vmcircbuf_mmap_shm_open: ftruncate (1)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); + } + + void *first_copy = mmap (0, 2 * size, + PROT_READ | PROT_WRITE, MAP_SHARED, + shm_fd, (off_t) 0); + + if (first_copy == MAP_FAILED){ + close (shm_fd); // cleanup + perror ("gr_vmcircbuf_mmap_shm_open: mmap (1)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); + } + + // unmap the 2nd half + if (munmap ((char *) first_copy + size, size) == -1){ + close (shm_fd); // cleanup + perror ("gr_vmcircbuf_mmap_shm_open: munmap (1)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); + } + + // map the first half into the now available hole where the + // second half used to be. + + void *second_copy = mmap ((char *) first_copy + size, size, + PROT_READ | PROT_WRITE, MAP_SHARED, + shm_fd, (off_t) 0); + + if (second_copy == MAP_FAILED){ + close (shm_fd); // cleanup + perror ("gr_vmcircbuf_mmap_shm_open: mmap (2)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); + } + +#if 0 // OS/X doesn't allow you to resize the segment + + // cut the shared memory segment down to size + if (ftruncate (shm_fd, (off_t) size) == -1){ + close (shm_fd); // cleanup + perror ("gr_vmcircbuf_mmap_shm_open: ftruncate (2)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); + } +#endif + + close (shm_fd); // fd no longer needed. The mapping is retained. + + if (shm_unlink (seg_name) == -1){ // unlink the seg_name. + perror ("gr_vmcircbuf_mmap_shm_open: shm_unlink"); + throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); + } + + // Now remember the important stuff + + d_base = (char *) first_copy; + d_size = size; +#endif +} + +gr_vmcircbuf_mmap_shm_open::~gr_vmcircbuf_mmap_shm_open () +{ +#if defined(HAVE_MMAP) + if (munmap (d_base, 2 * d_size) == -1){ + perror ("gr_vmcircbuf_mmap_shm_open: munmap (2)"); + } +#endif +} + +// ---------------------------------------------------------------- +// The factory interface +// ---------------------------------------------------------------- + + +gr_vmcircbuf_factory *gr_vmcircbuf_mmap_shm_open_factory::s_the_factory = 0; + +gr_vmcircbuf_factory * +gr_vmcircbuf_mmap_shm_open_factory::singleton () +{ + if (s_the_factory) + return s_the_factory; + + s_the_factory = new gr_vmcircbuf_mmap_shm_open_factory (); + return s_the_factory; +} + +int +gr_vmcircbuf_mmap_shm_open_factory::granularity () +{ + return gr_pagesize (); +} + +gr_vmcircbuf * +gr_vmcircbuf_mmap_shm_open_factory::make (int size) +{ + try { + return new gr_vmcircbuf_mmap_shm_open (size); + } + catch (...){ + return 0; + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h new file mode 100644 index 000000000..4b1feafff --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _GR_VMCIRCBUF_MMAP_SHM_OPEN_H_ +#define _GR_VMCIRCBUF_MMAP_SHM_OPEN_H_ + +#include + +/*! + * \brief concrete class to implement circular buffers with mmap and shm_open + */ +class gr_vmcircbuf_mmap_shm_open : public gr_vmcircbuf { + public: + + // CREATORS + + gr_vmcircbuf_mmap_shm_open (int size); + virtual ~gr_vmcircbuf_mmap_shm_open (); +}; + +/*! + * \brief concrete factory for circular buffers built using mmap and shm_open + */ +class gr_vmcircbuf_mmap_shm_open_factory : public gr_vmcircbuf_factory { + private: + static gr_vmcircbuf_factory *s_the_factory; + + public: + static gr_vmcircbuf_factory *singleton (); + + virtual const char *name () const { return "gr_vmcircbuf_mmap_shm_open_factory"; } + + /*! + * \brief return granularity of mapping, typically equal to page size + */ + virtual int granularity (); + + /*! + * \brief return a gr_vmcircbuf, or 0 if unable. + * + * Call this to create a doubly mapped circular buffer. + */ + virtual gr_vmcircbuf *make (int size); +}; + +#endif /* _GR_VMCIRCBUF_MMAP_SHM_OPEN_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc new file mode 100644 index 000000000..a07df779c --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc @@ -0,0 +1,198 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_MMAN_H +#include +#endif +#include +#include +#include +#include +#include +#include + + +gr_vmcircbuf_mmap_tmpfile::gr_vmcircbuf_mmap_tmpfile (int size) + : gr_vmcircbuf (size) +{ +#if !defined(HAVE_MMAP) + fprintf (stderr, "gr_vmcircbuf_mmap_tmpfile: mmap or mkstemp is not available\n"); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); +#else + + if (size <= 0 || (size % gr_pagesize ()) != 0){ + fprintf (stderr, "gr_vmcircbuf_mmap_tmpfile: invalid size = %d\n", size); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); + } + + int seg_fd = -1; + char seg_name[1024]; + + static int s_seg_counter = 0; + + + // open a temporary file that we'll map in a bit later + + while (1){ + snprintf (seg_name, sizeof (seg_name), + "%s/gnuradio-%d-%d-XXXXXX", gr_tmp_path (), getpid (), s_seg_counter); + s_seg_counter++; + + seg_fd = open (seg_name, O_RDWR | O_CREAT | O_EXCL, 0600); + if (seg_fd == -1){ + if (errno == EEXIST) // File already exists (shouldn't happen). Try again + continue; + + char msg[1024]; + snprintf (msg, sizeof (msg), + "gr_vmcircbuf_mmap_tmpfile: open [%s]", seg_name); + perror (msg); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); + } + break; + } + + if (unlink (seg_name) == -1){ + perror ("gr_vmcircbuf_mmap_tmpfile: unlink"); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); + } + + // We've got a valid file descriptor to a tmp file. + // Now set it's length to 2x what we really want and mmap it in. + + if (ftruncate (seg_fd, (off_t) 2 * size) == -1){ + close (seg_fd); // cleanup + perror ("gr_vmcircbuf_mmap_tmpfile: ftruncate (1)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); + } + + void *first_copy = mmap (0, 2 * size, + PROT_READ | PROT_WRITE, MAP_SHARED, + seg_fd, (off_t) 0); + + if (first_copy == MAP_FAILED){ + close (seg_fd); // cleanup + perror ("gr_vmcircbuf_mmap_tmpfile: mmap (1)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); + } + + // unmap the 2nd half + if (munmap ((char *) first_copy + size, size) == -1){ + close (seg_fd); // cleanup + perror ("gr_vmcircbuf_mmap_tmpfile: munmap (1)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); + } + + // map the first half into the now available hole where the + // second half used to be. + + void *second_copy = mmap ((char *) first_copy + size, size, + PROT_READ | PROT_WRITE, MAP_SHARED, + seg_fd, (off_t) 0); + + if (second_copy == MAP_FAILED){ + munmap(first_copy, size); // cleanup + close (seg_fd); + perror ("gr_vmcircbuf_mmap_tmpfile: mmap (2)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); + } + + // check for contiguity + if ((char *) second_copy != (char *) first_copy + size){ + munmap(first_copy, size); // cleanup + munmap(second_copy, size); + close (seg_fd); + perror ("gr_vmcircbuf_mmap_tmpfile: non-contiguous second copy"); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); + } + + // cut the tmp file down to size + if (ftruncate (seg_fd, (off_t) size) == -1){ + munmap(first_copy, size); // cleanup + munmap(second_copy, size); + close (seg_fd); + perror ("gr_vmcircbuf_mmap_tmpfile: ftruncate (2)"); + throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); + } + + close (seg_fd); // fd no longer needed. The mapping is retained. + + // Now remember the important stuff + + d_base = (char *) first_copy; + d_size = size; +#endif +} + +gr_vmcircbuf_mmap_tmpfile::~gr_vmcircbuf_mmap_tmpfile () +{ +#if defined(HAVE_MMAP) + if (munmap (d_base, 2 * d_size) == -1){ + perror ("gr_vmcircbuf_mmap_tmpfile: munmap (2)"); + } +#endif +} + +// ---------------------------------------------------------------- +// The factory interface +// ---------------------------------------------------------------- + + +gr_vmcircbuf_factory *gr_vmcircbuf_mmap_tmpfile_factory::s_the_factory = 0; + +gr_vmcircbuf_factory * +gr_vmcircbuf_mmap_tmpfile_factory::singleton () +{ + if (s_the_factory) + return s_the_factory; + + s_the_factory = new gr_vmcircbuf_mmap_tmpfile_factory (); + return s_the_factory; +} + +int +gr_vmcircbuf_mmap_tmpfile_factory::granularity () +{ + return gr_pagesize (); +} + +gr_vmcircbuf * +gr_vmcircbuf_mmap_tmpfile_factory::make (int size) +{ + try { + return new gr_vmcircbuf_mmap_tmpfile (size); + } + catch (...){ + return 0; + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h new file mode 100644 index 000000000..3b9f5dba8 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _GR_VMCIRCBUF_MMAP_TMPFILE_H_ +#define _GR_VMCIRCBUF_MMAP_TMPFILE_H_ + +#include + +/*! + * \brief concrete class to implement circular buffers with mmap and shm_open + */ +class gr_vmcircbuf_mmap_tmpfile : public gr_vmcircbuf { + public: + + // CREATORS + + gr_vmcircbuf_mmap_tmpfile (int size); + virtual ~gr_vmcircbuf_mmap_tmpfile (); +}; + +/*! + * \brief concrete factory for circular buffers built using mmap and shm_open + */ +class gr_vmcircbuf_mmap_tmpfile_factory : public gr_vmcircbuf_factory { + private: + static gr_vmcircbuf_factory *s_the_factory; + + public: + static gr_vmcircbuf_factory *singleton (); + + virtual const char *name () const { return "gr_vmcircbuf_mmap_tmpfile_factory"; } + + /*! + * \brief return granularity of mapping, typically equal to page size + */ + virtual int granularity (); + + /*! + * \brief return a gr_vmcircbuf, or 0 if unable. + * + * Call this to create a doubly mapped circular buffer. + */ + virtual gr_vmcircbuf *make (int size); +}; + +#endif /* _GR_VMCIRCBUF_MMAP_TMPFILE_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc new file mode 100644 index 000000000..4b6fcfe33 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc @@ -0,0 +1,192 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_IPC_H +#include +#endif +#ifdef HAVE_SYS_SHM_H +#include +#endif +#include +#include +#include + + +gr_vmcircbuf_sysv_shm::gr_vmcircbuf_sysv_shm (int size) + : gr_vmcircbuf (size) +{ +#if !defined(HAVE_SYS_SHM_H) + fprintf (stderr, "gr_vmcircbuf_sysv_shm: sysv shared memory is not available\n"); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); +#else + + int pagesize = gr_pagesize(); + + if (size <= 0 || (size % pagesize) != 0){ + fprintf (stderr, "gr_vmcircbuf_sysv_shm: invalid size = %d\n", size); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); + } + + int shmid_guard = -1; + int shmid1 = -1; + int shmid2 = -1; + + // We use this as a guard page. We'll map it read-only on both ends of the buffer. + // Ideally we'd map it no access, but I don't think that's possible with SysV + if ((shmid_guard = shmget (IPC_PRIVATE, pagesize, IPC_CREAT | 0400)) == -1){ + perror ("gr_vmcircbuf_sysv_shm: shmget (0)"); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); + } + + if ((shmid2 = shmget (IPC_PRIVATE, 2 * size + 2 * pagesize, IPC_CREAT | 0700)) == -1){ + perror ("gr_vmcircbuf_sysv_shm: shmget (1)"); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); + } + + if ((shmid1 = shmget (IPC_PRIVATE, size, IPC_CREAT | 0700)) == -1){ + perror ("gr_vmcircbuf_sysv_shm: shmget (2)"); + shmctl (shmid2, IPC_RMID, 0); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); + } + + void *first_copy = shmat (shmid2, 0, 0); + if (first_copy == (void *) -1){ + perror ("gr_vmcircbuf_sysv_shm: shmat (1)"); + shmctl (shmid_guard, IPC_RMID, 0); + shmctl (shmid2, IPC_RMID, 0); + shmctl (shmid1, IPC_RMID, 0); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); + } + + shmctl (shmid2, IPC_RMID, 0); + + // There may be a race between our detach and attach. + // + // If the system allocates all shared memory segments at the same + // virtual addresses in all processes and if the system allocates + // some other segment to first_copy or first_copoy + size between + // our detach and attach, the attaches below could fail [I've never + // seen it fail for this reason]. + + shmdt (first_copy); + + // first read-only guard page + if (shmat (shmid_guard, first_copy, SHM_RDONLY) == (void *) -1){ + perror ("gr_vmcircbuf_sysv_shm: shmat (2)"); + shmctl (shmid_guard, IPC_RMID, 0); + shmctl (shmid1, IPC_RMID, 0); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); + } + + // first copy + if (shmat (shmid1, (char *) first_copy + pagesize, 0) == (void *) -1){ + perror ("gr_vmcircbuf_sysv_shm: shmat (3)"); + shmctl (shmid_guard, IPC_RMID, 0); + shmctl (shmid1, IPC_RMID, 0); + shmdt (first_copy); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); + } + + // second copy + if (shmat (shmid1, (char *) first_copy + pagesize + size, 0) == (void *) -1){ + perror ("gr_vmcircbuf_sysv_shm: shmat (4)"); + shmctl (shmid_guard, IPC_RMID, 0); + shmctl (shmid1, IPC_RMID, 0); + shmdt ((char *)first_copy + pagesize); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); + } + + // second read-only guard page + if (shmat (shmid_guard, (char *) first_copy + pagesize + 2 * size, SHM_RDONLY) == (void *) -1){ + perror ("gr_vmcircbuf_sysv_shm: shmat (5)"); + shmctl (shmid_guard, IPC_RMID, 0); + shmctl (shmid1, IPC_RMID, 0); + shmdt (first_copy); + shmdt ((char *)first_copy + pagesize); + shmdt ((char *)first_copy + pagesize + size); + throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); + } + + shmctl (shmid1, IPC_RMID, 0); + shmctl (shmid_guard, IPC_RMID, 0); + + // Now remember the important stuff + + d_base = (char *) first_copy + pagesize; + d_size = size; +#endif +} + +gr_vmcircbuf_sysv_shm::~gr_vmcircbuf_sysv_shm () +{ +#if defined(HAVE_SYS_SHM_H) + if (shmdt (d_base - gr_pagesize()) == -1 + || shmdt (d_base) == -1 + || shmdt (d_base + d_size) == -1 + || shmdt (d_base + 2 * d_size) == -1){ + perror ("gr_vmcircbuf_sysv_shm: shmdt (2)"); + } +#endif +} + +// ---------------------------------------------------------------- +// The factory interface +// ---------------------------------------------------------------- + + +gr_vmcircbuf_factory *gr_vmcircbuf_sysv_shm_factory::s_the_factory = 0; + +gr_vmcircbuf_factory * +gr_vmcircbuf_sysv_shm_factory::singleton () +{ + if (s_the_factory) + return s_the_factory; + + s_the_factory = new gr_vmcircbuf_sysv_shm_factory (); + return s_the_factory; +} + +int +gr_vmcircbuf_sysv_shm_factory::granularity () +{ + return gr_pagesize (); +} + +gr_vmcircbuf * +gr_vmcircbuf_sysv_shm_factory::make (int size) +{ + try { + return new gr_vmcircbuf_sysv_shm (size); + } + catch (...){ + return 0; + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h new file mode 100644 index 000000000..9a8c128a5 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _GR_VMCIRCBUF_SYSV_SHM_H_ +#define _GR_VMCIRCBUF_SYSV_SHM_H_ + +#include + +/*! + * \brief concrete class to implement circular buffers with mmap and shm_open + */ +class gr_vmcircbuf_sysv_shm : public gr_vmcircbuf { + public: + + // CREATORS + + gr_vmcircbuf_sysv_shm (int size); + virtual ~gr_vmcircbuf_sysv_shm (); +}; + +/*! + * \brief concrete factory for circular buffers built using mmap and shm_open + */ +class gr_vmcircbuf_sysv_shm_factory : public gr_vmcircbuf_factory { + private: + static gr_vmcircbuf_factory *s_the_factory; + + public: + static gr_vmcircbuf_factory *singleton (); + + virtual const char *name () const { return "gr_vmcircbuf_sysv_shm_factory"; } + + /*! + * \brief return granularity of mapping, typically equal to page size + */ + virtual int granularity (); + + /*! + * \brief return a gr_vmcircbuf, or 0 if unable. + * + * Call this to create a doubly mapped circular buffer. + */ + virtual gr_vmcircbuf *make (int size); +}; + +#endif /* _GR_VMCIRCBUF_SYSV_SHM_H_ */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_block.cc new file mode 100644 index 000000000..e3a21be35 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.cc @@ -0,0 +1,89 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include +#include +#include + + +// ---------------------------------------------------------------- + + +void +qa_gr_block::t0 () +{ + // test creation of sources + gr_block_sptr src1 (gr_make_null_source (sizeof (int))); + CPPUNIT_ASSERT_EQUAL (std::string ("null_source"), src1->name ()); + CPPUNIT_ASSERT_EQUAL (0, src1->input_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL (1, src1->output_signature()->min_streams ()); + CPPUNIT_ASSERT_EQUAL (1, src1->output_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL (sizeof (int), + src1->output_signature()->sizeof_stream_item (0)); + + gr_block_sptr src2 (gr_make_null_source (sizeof (short))); + CPPUNIT_ASSERT_EQUAL (std::string ("null_source"), src2->name ()); + CPPUNIT_ASSERT_EQUAL (0, src2->input_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL (1, src2->output_signature()->min_streams ()); + CPPUNIT_ASSERT_EQUAL (1, src2->output_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL (sizeof (short), + src2->output_signature()->sizeof_stream_item (0)); +} + + +void +qa_gr_block::t1 () +{ + // test creation of sinks + gr_block_sptr dst1 (gr_make_null_sink (sizeof (int))); + CPPUNIT_ASSERT_EQUAL (std::string ("null_sink"), dst1->name ()); + CPPUNIT_ASSERT_EQUAL (1, dst1->input_signature()->min_streams ()); + CPPUNIT_ASSERT_EQUAL (1, dst1->input_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL (sizeof (int), + dst1->input_signature()->sizeof_stream_item (0)); + + CPPUNIT_ASSERT_EQUAL (0, dst1->output_signature()->max_streams ()); + + gr_block_sptr dst2 (gr_make_null_sink (sizeof (short))); + CPPUNIT_ASSERT_EQUAL (std::string ("null_sink"), dst2->name ()); + CPPUNIT_ASSERT_EQUAL (1, dst2->input_signature()->min_streams ()); + CPPUNIT_ASSERT_EQUAL (1, dst2->input_signature()->max_streams ()); + CPPUNIT_ASSERT_EQUAL (sizeof (short), + dst2->input_signature()->sizeof_stream_item (0)); + CPPUNIT_ASSERT_EQUAL (0, dst2->output_signature()->max_streams ()); +} + +void +qa_gr_block::t2 () +{ +} + +void +qa_gr_block::t3 () +{ +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.h b/gnuradio-core/src/lib/runtime/qa_gr_block.h new file mode 100644 index 000000000..6e3082514 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_QA_GR_BLOCK_H +#define INCLUDED_QA_GR_BLOCK_H + +#include +#include +#include + +class qa_gr_block : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_gr_block); + CPPUNIT_TEST (t0); + CPPUNIT_TEST (t1); + CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST_SUITE_END (); + + private: + void t0 (); + void t1 (); + void t2 (); + void t3 (); + +}; + + +#endif /* INCLUDED_QA_GR_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc new file mode 100644 index 000000000..5c549d0b9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc @@ -0,0 +1,307 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include +#include + +static void +leak_check (void f ()) +{ + long buffer_count = gr_buffer_ncurrently_allocated (); + long buffer_reader_count = gr_buffer_reader_ncurrently_allocated (); + + f (); + + CPPUNIT_ASSERT_EQUAL (buffer_reader_count, gr_buffer_reader_ncurrently_allocated ()); + CPPUNIT_ASSERT_EQUAL (buffer_count, gr_buffer_ncurrently_allocated ()); +} + + +// ---------------------------------------------------------------------------- +// test single writer, no readers... +// + +static void +t0_body () +{ + int nitems = 4000 / sizeof (int); + int counter = 0; + + gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); + + int last_sa; + int sa; + + sa = buf->space_available (); + CPPUNIT_ASSERT (sa > 0); + last_sa = sa; + + for (int i = 0; i < 5; i++){ + sa = buf->space_available (); + CPPUNIT_ASSERT_EQUAL (last_sa, sa); + last_sa = sa; + + int *p = (int *) buf->write_pointer (); + CPPUNIT_ASSERT (p != 0); + + for (int j = 0; j < sa; j++) + *p++ = counter++; + + buf->update_write_pointer (sa); + } +} + +// ---------------------------------------------------------------------------- +// test single writer, single reader +// + +static void +t1_body () + { + int nitems = 4000 / sizeof (int); + int write_counter = 0; + int read_counter = 0; + + gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); + gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 1)); + + + int sa; + + // write 1/3 of buffer + + sa = buf->space_available (); + CPPUNIT_ASSERT (sa > 0); + + int *p = (int *) buf->write_pointer (); + CPPUNIT_ASSERT (p != 0); + + for (int j = 0; j < sa/3; j++){ + *p++ = write_counter++; + } + buf->update_write_pointer (sa/3); + + + // write the next 1/3 (1/2 of what's left) + + sa = buf->space_available (); + CPPUNIT_ASSERT (sa > 0); + + p = (int *) buf->write_pointer (); + CPPUNIT_ASSERT (p != 0); + + for (int j = 0; j < sa/2; j++){ + *p++ = write_counter++; + } + buf->update_write_pointer (sa/2); + + + // check that we can read it OK + + int ia = r1->items_available (); + CPPUNIT_ASSERT_EQUAL (write_counter, ia); + + int *rp = (int *) r1->read_pointer (); + CPPUNIT_ASSERT (rp != 0); + + for (int i = 0; i < ia/2; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter, *rp); + read_counter++; + rp++; + } + r1->update_read_pointer (ia/2); + + // read the rest + + ia = r1->items_available (); + rp = (int *) r1->read_pointer (); + CPPUNIT_ASSERT (rp != 0); + + for (int i = 0; i < ia; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter, *rp); + read_counter++; + rp++; + } + r1->update_read_pointer (ia); +} + +// ---------------------------------------------------------------------------- +// single writer, single reader: check wrap-around +// + +static void +t2_body () +{ + // 64K is the largest granularity we've seen so far (MS windows file mapping). + // This allows a bit of "white box testing" + + int nitems = (64 * (1L << 10)) / sizeof (int); // 64K worth of ints + + gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); + gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 1)); + + int read_counter = 0; + int write_counter = 0; + int n; + int *wp = 0; + int *rp = 0; + + // Write 3/4 of buffer + + n = (int) (buf->space_available () * 0.75); + wp = (int *) buf->write_pointer (); + + for (int i = 0; i < n; i++) + *wp++ = write_counter++; + buf->update_write_pointer (n); + + // Now read it all + + int m = r1->items_available (); + CPPUNIT_ASSERT_EQUAL (n, m); + rp = (int *) r1->read_pointer (); + + for (int i = 0; i < m; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter, *rp); + read_counter++; + rp++; + } + r1->update_read_pointer (m); + + // Now write as much as we can. + // This will wrap around the buffer + + n = buf->space_available (); + CPPUNIT_ASSERT_EQUAL (nitems - 1, n); // white box test + wp = (int *) buf->write_pointer (); + + for (int i = 0; i < n; i++) + *wp++ = write_counter++; + buf->update_write_pointer (n); + + // now read it all + + m = r1->items_available (); + CPPUNIT_ASSERT_EQUAL (n, m); + rp = (int *) r1->read_pointer (); + + for (int i = 0; i < m; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter, *rp); + read_counter++; + rp++; + } + r1->update_read_pointer (m); + +} + +// ---------------------------------------------------------------------------- +// single writer, N readers, randomized order and lengths +// ---------------------------------------------------------------------------- + +static void +t3_body () +{ + int nitems = (64 * (1L << 10)) / sizeof (int); + + static const int N = 5; + gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); + gr_buffer_reader_sptr reader[N]; + int read_counter[N]; + int write_counter = 0; + gr_random random; + + for (int i = 0; i < N; i++){ + read_counter[i] = 0; + reader[i] = gr_buffer_add_reader (buf, 1); + } + + for (int lc = 0; lc < 1000; lc++){ + + // write some + + int n = (int) (buf->space_available () * random.ran1 ()); + int *wp = (int *) buf->write_pointer (); + + for (int i = 0; i < n; i++) + *wp++ = write_counter++; + + buf->update_write_pointer (n); + + // pick a random reader and read some + + int r = (int) (N * random.ran1 ()); + CPPUNIT_ASSERT (0 <= r && r < N); + + int m = reader[r]->items_available (); + int *rp = (int *) reader[r]->read_pointer (); + + for (int i = 0; i < m; i++){ + CPPUNIT_ASSERT_EQUAL (read_counter[r], *rp); + read_counter[r]++; + rp++; + } + reader[r]->update_read_pointer (m); + } +} + + +// ---------------------------------------------------------------------------- + +void +qa_gr_buffer::t0 () +{ + leak_check (t0_body); +} + +void +qa_gr_buffer::t1 () +{ + leak_check (t1_body); +} + +void +qa_gr_buffer::t2 () +{ + leak_check (t2_body); +} + +void +qa_gr_buffer::t3 () +{ + leak_check (t3_body); +} + +void +qa_gr_buffer::t4 () +{ +} + +void +qa_gr_buffer::t5 () +{ +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.h b/gnuradio-core/src/lib/runtime/qa_gr_buffer.h new file mode 100644 index 000000000..700629cc4 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.h @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_QA_GR_BUFFER_H +#define INCLUDED_QA_GR_BUFFER_H + +#include +#include + +class qa_gr_buffer : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_gr_buffer); + CPPUNIT_TEST (t0); + CPPUNIT_TEST (t1); + CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST (t4); + CPPUNIT_TEST (t5); + CPPUNIT_TEST_SUITE_END (); + + + private: + + void t0 (); + void t1 (); + void t2 (); + void t3 (); + void t4 (); + void t5 (); +}; + + + +#endif /* INCLUDED_QA_GR_BUFFER_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc new file mode 100644 index 000000000..c180e7b74 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include + +void +qa_gr_io_signature::t0 () +{ + gr_make_io_signature (1, 1, sizeof (int)); +} + +void +qa_gr_io_signature::t1 () +{ + gr_make_io_signature (3, 1, sizeof (int)); // throws std::invalid_argument +} + +void +qa_gr_io_signature::t2 () +{ + gr_io_signature_sptr p = + gr_make_io_signature (3, gr_io_signature::IO_INFINITE, sizeof (int)); + + CPPUNIT_ASSERT_EQUAL (p->min_streams (), 3); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item (0), sizeof (int)); +} + +void +qa_gr_io_signature::t3 () +{ +} + diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h new file mode 100644 index 000000000..225ce8068 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h @@ -0,0 +1,47 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_QA_GR_IO_SIGNATURE_H +#define INCLUDED_QA_GR_IO_SIGNATURE_H + +#include +#include +#include + +class qa_gr_io_signature : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_gr_io_signature); + CPPUNIT_TEST (t0); + CPPUNIT_TEST_EXCEPTION (t1, std::invalid_argument); + CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST_SUITE_END (); + + private: + void t0 (); + void t1 (); + void t2 (); + void t3 (); + +}; + +#endif /* INCLUDED_QA_GR_IO_SIGNATURE_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc new file mode 100644 index 000000000..f3c815a0d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc @@ -0,0 +1,40 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +void +qa_gr_vmcircbuf::test_all () +{ + int verbose = 1; // summary + + bool ok = gr_vmcircbuf_sysconfig::test_all_factories (verbose); + + CPPUNIT_ASSERT_EQUAL (true, ok); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h new file mode 100644 index 000000000..41f69c353 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h @@ -0,0 +1,39 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef _QA_GR_VMCIRCBUF_H_ +#define _QA_GR_VMCIRCBUF_H_ + +#include +#include + +class qa_gr_vmcircbuf : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_gr_vmcircbuf); + CPPUNIT_TEST (test_all); + CPPUNIT_TEST_SUITE_END (); + + private: + void test_all (); +}; + + +#endif /* _QA_GR_VMCIRCBUF_H_ */ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc new file mode 100644 index 000000000..668628f2a --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -0,0 +1,49 @@ +/* + * Copyright 2002 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * This class gathers together all the test cases for the gr + * directory into a single test suite. As you create new test cases, + * add them here. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +CppUnit::TestSuite * +qa_runtime::suite () +{ + CppUnit::TestSuite *s = new CppUnit::TestSuite ("runtime"); + + s->addTest (qa_gr_vmcircbuf::suite ()); + s->addTest (qa_gr_io_signature::suite ()); + s->addTest (qa_gr_block::suite ()); + s->addTest (qa_gr_buffer::suite ()); + + return s; +} diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.h b/gnuradio-core/src/lib/runtime/qa_runtime.h new file mode 100644 index 000000000..5862b1ea2 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_runtime.h @@ -0,0 +1,37 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _QA_RUNTIME_H_ +#define _QA_RUNTIME_H_ + +#include + +//! collect all the tests for the runtime directory + +class qa_runtime { + public: + //! return suite of tests for all of runtime directory + static CppUnit::TestSuite *suite (); +}; + + +#endif /* _QA_RUNTIME_H_ */ diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i new file mode 100644 index 000000000..d8dd34f1e --- /dev/null +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +%{ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +%} + +%include +%include +%include +%include +%include +%include +%include +%include +%include +%include +%include +%include diff --git a/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc b/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc new file mode 100644 index 000000000..26bfa6d2d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +gr_block_sptr +foo (gr_vector_source_i_sptr s) +{ + return gr_block_sptr (s); +} + +typedef gr_shared_block_sptr gr_vector_source_i_ptrX; +//typedef boost::shared_ptr gr_vector_source_i_ptrX; + +gr_vector_source_i_ptrX +bar (gr_vector_source_i *s) +{ + return gr_vector_source_i_ptrX (s); +} + +gr_block_sptr +baz_1 (gr_vector_source_i_ptrX s) +{ + return gr_block_sptr (s); +} + +#if 0 +gr_block_sptr +baz_2 (gr_vector_source_i_ptrX s) +{ + return s.block_sptr (); +} +#endif -- cgit From 62959cd5d2356fa3120680a96ae6814a0c0effbe Mon Sep 17 00:00:00 2001 From: eb Date: Thu, 24 Aug 2006 18:50:19 +0000 Subject: Trial fix for ticket:45 Changed interpretation of second argument to gr_buffer_add_reader from "history" to "nzero_preload". If the argument is 0, no zeros are preloaded into the buffer. This is a less surprising interpretation than the old behavior, which when passed a zero, inserted buffersize-1 zeros ;) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3403 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 7 +++++-- gnuradio-core/src/lib/runtime/gr_buffer.h | 11 +++++++---- gnuradio-core/src/lib/runtime/gr_buffer.i | 2 +- gnuradio-core/src/lib/runtime/qa_gr_buffer.cc | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index d3d123096..e06786880 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -179,11 +179,14 @@ gr_buffer::update_write_pointer (int nitems) } gr_buffer_reader_sptr -gr_buffer_add_reader (gr_buffer_sptr buf, int history) +gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload) { + if (nzero_preload < 0) + throw std::invalid_argument("gr_buffer_add_reader: nzero_preload must be >= 0"); + gr_buffer_reader_sptr r (new gr_buffer_reader (buf, buf->index_sub(buf->d_write_index, - history-1))); + nzero_preload))); buf->d_readers.push_back (r.get ()); return r; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 6f85f275e..e468f4358 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -73,7 +73,7 @@ class gr_buffer { friend class gr_buffer_reader; friend gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item); - friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int history); + friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload); protected: char *d_base; // base address of buffer @@ -129,8 +129,11 @@ class gr_buffer { }; -//! create a new gr_buffer_reader and attach it to buffer \p buf -gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int history); +/*! + * \brief create a new gr_buffer_reader and attach it to buffer \p buf + * \param nzero_preload -- number of zero items to "preload" into buffer. + */ +gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload); //! returns # of gr_buffers currently allocated long gr_buffer_ncurrently_allocated (); @@ -179,7 +182,7 @@ class gr_buffer_reader { private: friend class gr_buffer; - friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int history); + friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload); gr_buffer_sptr d_buffer; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.i b/gnuradio-core/src/lib/runtime/gr_buffer.i index 80f92ece1..2cb6deb95 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.i +++ b/gnuradio-core/src/lib/runtime/gr_buffer.i @@ -43,7 +43,7 @@ typedef boost::shared_ptr gr_buffer_reader_sptr; %ignore gr_buffer_reader; %rename(buffer_add_reader) gr_buffer_add_reader; -gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int history); +gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload); class gr_buffer_reader { public: diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc index 5c549d0b9..5a3d4d3d7 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc @@ -88,7 +88,7 @@ t1_body () int read_counter = 0; gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); - gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 1)); + gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 0)); int sa; @@ -163,7 +163,7 @@ t2_body () int nitems = (64 * (1L << 10)) / sizeof (int); // 64K worth of ints gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); - gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 1)); + gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 0)); int read_counter = 0; int write_counter = 0; @@ -237,7 +237,7 @@ t3_body () for (int i = 0; i < N; i++){ read_counter[i] = 0; - reader[i] = gr_buffer_add_reader (buf, 1); + reader[i] = gr_buffer_add_reader (buf, 0); } for (int lc = 0; lc < 1000; lc++){ -- cgit From a5c2fda5e888832a11057792d6679f7d4399f934 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 12 Sep 2006 20:28:33 +0000 Subject: trial fix for ticket:63 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3526 221aa14e-8319-0410-a670-987f0aec2ac5 --- .../lib/runtime/gr_vmcircbuf_createfilemapping.cc | 111 ++++++++++++--------- 1 file changed, 63 insertions(+), 48 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc index 8f3540b4b..ffad5ac7d 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc @@ -39,6 +39,25 @@ #include #include +#ifdef HAVE_CREATEFILEMAPPING +// Print Windows error (could/should be global?) +static void +werror( char *where, DWORD last_error ) +{ + char buf[1024]; + + FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + last_error, + 0, // default language + buf, + sizeof(buf)/sizeof(TCHAR), // buffer size + NULL ); + fprintf( stderr, "%s: Error %d: %s", where, last_error, buf ); + return; +} +#endif + gr_vmcircbuf_createfilemapping::gr_vmcircbuf_createfilemapping (int size) : gr_vmcircbuf (size) @@ -67,63 +86,59 @@ gr_vmcircbuf_createfilemapping::gr_vmcircbuf_createfilemapping (int size) s_seg_counter++; if (d_handle == NULL || d_handle == INVALID_HANDLE_VALUE){ char msg[1024]; - snprintf (msg, sizeof (msg), "gr_vmcircbuf_mmap_createfilemapping: CreateFileMapping [%s] :%d", seg_name,(int)GetLastError()); - perror (msg); + snprintf( msg, sizeof(msg), + "gr_vmcircbuf_mmap_createfilemapping: CreateFileMapping [%s]", + seg_name ); + werror( msg, GetLastError() ); throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); } - int i = 0; - d_first_copy = d_second_copy = NULL; - - while (i++ < 8 && d_second_copy == NULL){ - // keep the first map allocation to force allocation in a new address - // space - LPVOID first_tmp = d_first_copy; - - d_first_copy = MapViewOfFile((HANDLE)d_handle, // handle to map object - FILE_MAP_WRITE, // read/write permission - 0, - 0, - size); - - if (d_first_copy == NULL){ - if (first_tmp) - UnmapViewOfFile(first_tmp); - - CloseHandle(d_handle); // cleanup - char msg[1024]; - snprintf (msg, sizeof (msg), - "gr_vmcircbuf_mmap_createfilemapping: MapViewOfFile (1) :%d", (int)GetLastError()); - perror (msg); - throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); - } - - // NOTE: d_second_copy will be NULL if MapViewFileEx() fails to allocate the - // requested address space - d_second_copy = MapViewOfFileEx((HANDLE)d_handle, // handle to map object - FILE_MAP_WRITE, // read/write permission - 0, - 0, - size, - (char *)d_first_copy + size);//(LPVOID) ((char *)d_first_copy + size)); - - if (first_tmp) - UnmapViewOfFile(first_tmp); + // Allocate virtual memory of the needed size, then free it so we can use it + LPVOID first_tmp; + first_tmp = VirtualAlloc( NULL, 2*size, MEM_RESERVE, PAGE_NOACCESS ); + if (first_tmp == NULL){ + werror( "gr_vmcircbuf_mmap_createfilemapping: VirtualAlloc", GetLastError()); + CloseHandle(d_handle); // cleanup + throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); + } -#ifdef DEBUG - fprintf (stderr,"gr_vmcircbuf_mmap_createfilemapping: contiguous? mmap %p %p %p %p, %d\n", - (char *)d_first_copy, (char *)d_second_copy, size, (char *)d_first_copy + size,i); -#endif + if (VirtualFree(first_tmp, 0, MEM_RELEASE) == 0){ + werror( "gr_vmcircbuf_mmap_createfilemapping: VirtualFree", GetLastError()); + CloseHandle(d_handle); // cleanup + throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); + } + + d_first_copy = MapViewOfFileEx((HANDLE)d_handle, // handle to map object + FILE_MAP_WRITE, // read/write permission + 0, + 0, + size, + first_tmp); + if (d_first_copy != first_tmp){ + werror( "gr_vmcircbuf_mmap_createfilemapping: MapViewOfFileEx(1)", GetLastError()); + CloseHandle(d_handle); // cleanup + throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); } - if (d_second_copy == NULL){ // cleanup - fprintf (stderr,"gr_vmcircbuf_mmap_createfilemapping: non contiguous mmap - %p %p %p %p\n", - d_first_copy, d_second_copy, size, (char *)d_first_copy + size); + d_second_copy = MapViewOfFileEx((HANDLE)d_handle, // handle to map object + FILE_MAP_WRITE, // read/write permission + 0, + 0, + size, + (char *)first_tmp + size);//(LPVOID) ((char *)d_first_copy + size)); + + if (d_second_copy != (char *)first_tmp + size){ + werror( "gr_vmcircbuf_mmap_createfilemapping: MapViewOfFileEx(2)", GetLastError()); UnmapViewOfFile(d_first_copy); CloseHandle(d_handle); // cleanup throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); } +#ifdef DEBUG + fprintf (stderr,"gr_vmcircbuf_mmap_createfilemapping: contiguous? mmap %p %p %p %p\n", + (char *)d_first_copy, (char *)d_second_copy, size, (char *)d_first_copy + size); +#endif + // Now remember the important stuff d_base = (char *) d_first_copy; d_size = size; @@ -135,12 +150,12 @@ gr_vmcircbuf_createfilemapping::~gr_vmcircbuf_createfilemapping () #ifdef HAVE_CREATEFILEMAPPING if (UnmapViewOfFile(d_first_copy) == 0) { - perror ("gr_vmcircbuf_createfilemapping: UnmapViewOfFile(d_first_copy)"); + werror("gr_vmcircbuf_createfilemapping: UnmapViewOfFile(d_first_copy)", GetLastError()); } d_base=NULL; if (UnmapViewOfFile(d_second_copy) == 0) { - perror ("gr_vmcircbuf_createfilemapping: UnmapViewOfFile(d_second_copy)"); + werror("gr_vmcircbuf_createfilemapping: UnmapViewOfFile(d_second_copy)", GetLastError()); } //d_second=NULL; CloseHandle(d_handle); -- cgit From 86f5c92427b3f4bb30536d76cf63c3fca388fb2f Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 13 Sep 2006 21:30:04 +0000 Subject: Updated FSF address in all files. Fixes ticket:51 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3534 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 4 ++-- gnuradio-core/src/lib/runtime/gr_block.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_block.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_block.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_block_detail.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_block_detail.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_buffer.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_buffer.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_buffer.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_complex.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_dispatcher.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_dispatcher.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_dispatcher.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_error_handler.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_error_handler.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_error_handler.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_io_signature.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_io_signature.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_io_signature.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_local_sighandler.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_local_sighandler.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_message.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_message.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_message.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_msg_handler.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_msg_handler.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_msg_handler.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_msg_queue.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_msg_queue.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_pagesize.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_pagesize.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_preferences.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_preferences.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_realtime.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_realtime.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_runtime.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_select_handler.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_select_handler.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_swig_block_magic.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_timer.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_tmp_path.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_tmp_path.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_types.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h | 4 ++-- gnuradio-core/src/lib/runtime/qa_gr_block.cc | 4 ++-- gnuradio-core/src/lib/runtime/qa_gr_block.h | 4 ++-- gnuradio-core/src/lib/runtime/qa_gr_buffer.cc | 4 ++-- gnuradio-core/src/lib/runtime/qa_gr_buffer.h | 4 ++-- gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc | 4 ++-- gnuradio-core/src/lib/runtime/qa_gr_io_signature.h | 4 ++-- gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc | 4 ++-- gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h | 4 ++-- gnuradio-core/src/lib/runtime/qa_runtime.cc | 4 ++-- gnuradio-core/src/lib/runtime/qa_runtime.h | 4 ++-- gnuradio-core/src/lib/runtime/runtime.i | 4 ++-- gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc | 4 ++-- 70 files changed, 140 insertions(+), 140 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 7ee94ba1b..cce4e6f84 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -15,8 +15,8 @@ # # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. # include $(top_srcdir)/Makefile.common diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 8378c8f7d..65e16045a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index df72e1a3f..8b234c751 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_BLOCK_H diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index f1f0332e8..3bfd24367 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ class gr_block; diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 0ad5da49c..ed414d472 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 90c912c25..c3e360cd1 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_BLOCK_DETAIL_H diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.i b/gnuradio-core/src/lib/runtime/gr_block_detail.i index 9d3843ebe..9ac5ae96d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.i +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ class gr_block_detail; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index e06786880..300d66f67 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index e468f4358..506a16616 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_BUFFER_H diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.i b/gnuradio-core/src/lib/runtime/gr_buffer.i index 2cb6deb95..0434bdfc1 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.i +++ b/gnuradio-core/src/lib/runtime/gr_buffer.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ class gr_buffer; diff --git a/gnuradio-core/src/lib/runtime/gr_complex.h b/gnuradio-core/src/lib/runtime/gr_complex.h index 242b2f54d..732aa997d 100644 --- a/gnuradio-core/src/lib/runtime/gr_complex.h +++ b/gnuradio-core/src/lib/runtime/gr_complex.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_COMPLEX_H #define INCLUDED_GR_COMPLEX_H diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.cc b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc index c2a1eb50a..3c84edd4c 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.cc +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.h b/gnuradio-core/src/lib/runtime/gr_dispatcher.h index a3d857972..69e7f851c 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.h +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_DISPATCHER_H diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.i b/gnuradio-core/src/lib/runtime/gr_dispatcher.i index 5feca7571..1e8ce1043 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.i +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ class gr_dispatcher; diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.cc b/gnuradio-core/src/lib/runtime/gr_error_handler.cc index a3148cfde..4d4ca6eea 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ /* * This code is based on error.cc from the "Click Modular Router". diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.h b/gnuradio-core/src/lib/runtime/gr_error_handler.h index 275db64c3..a001bcb90 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ /* * This code is based on error.hh from the "Click Modular Router". diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.i b/gnuradio-core/src/lib/runtime/gr_error_handler.i index d0e61496f..aea4598d7 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.i +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ %rename(error_handler) gr_error_handler; diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.cc b/gnuradio-core/src/lib/runtime/gr_io_signature.cc index 7277108ca..51ab9286c 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index e0d979070..c146193bc 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_IO_SIGNATURE_H diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.i b/gnuradio-core/src/lib/runtime/gr_io_signature.i index 601142e28..ca5ee215e 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.i +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ class gr_io_signature; diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc index c6da0978c..009d62bdb 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h index 69eb65d80..08e8edf00 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_LOCAL_SIGHANDLER_H diff --git a/gnuradio-core/src/lib/runtime/gr_message.cc b/gnuradio-core/src/lib/runtime/gr_message.cc index e9427e64d..7586376dc 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.cc +++ b/gnuradio-core/src/lib/runtime/gr_message.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_message.h b/gnuradio-core/src/lib/runtime/gr_message.h index 272a82ee4..cae599da1 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.h +++ b/gnuradio-core/src/lib/runtime/gr_message.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_MESSAGE_H #define INCLUDED_GR_MESSAGE_H diff --git a/gnuradio-core/src/lib/runtime/gr_message.i b/gnuradio-core/src/lib/runtime/gr_message.i index 19d5d1cd1..7be0e73ca 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.i +++ b/gnuradio-core/src/lib/runtime/gr_message.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ class gr_message; diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.cc b/gnuradio-core/src/lib/runtime/gr_msg_handler.cc index 98007e239..5b5604949 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.h b/gnuradio-core/src/lib/runtime/gr_msg_handler.h index 15aab338a..3ddc25678 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_MSG_HANDLER_H #define INCLUDED_GR_MSG_HANDLER_H diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.i b/gnuradio-core/src/lib/runtime/gr_msg_handler.i index 5571665ac..bda1e3ed3 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ /*! diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc index 6b53fc7ea..6d105b71b 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.h b/gnuradio-core/src/lib/runtime/gr_msg_queue.h index 6a9147ee3..a2bd70dd2 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_MSG_QUEUE_H #define INCLUDED_GR_MSG_QUEUE_H diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 28292d66f..0fe0d2906 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ class gr_msg_queue; diff --git a/gnuradio-core/src/lib/runtime/gr_pagesize.cc b/gnuradio-core/src/lib/runtime/gr_pagesize.cc index dec40678b..a3896b0b9 100644 --- a/gnuradio-core/src/lib/runtime/gr_pagesize.cc +++ b/gnuradio-core/src/lib/runtime/gr_pagesize.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_pagesize.h b/gnuradio-core/src/lib/runtime/gr_pagesize.h index a5cadb707..ae7d74442 100644 --- a/gnuradio-core/src/lib/runtime/gr_pagesize.h +++ b/gnuradio-core/src/lib/runtime/gr_pagesize.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _GR_PAGESIZE_H_ #define _GR_PAGESIZE_H_ diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index 854314447..f8cd339d5 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.h b/gnuradio-core/src/lib/runtime/gr_preferences.h index 5a7cad454..55c42e127 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.h +++ b/gnuradio-core/src/lib/runtime/gr_preferences.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _GR_PREFERENCES_H_ diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.cc b/gnuradio-core/src/lib/runtime/gr_realtime.cc index 4f23ea0c6..a5b8b0477 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_realtime.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.h b/gnuradio-core/src/lib/runtime/gr_realtime.h index 3aeafa533..e4d676e15 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.h +++ b/gnuradio-core/src/lib/runtime/gr_realtime.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_REALTIME_H diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.h b/gnuradio-core/src/lib/runtime/gr_runtime.h index f138e6ac4..55cbabe18 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_RUNTIME_H diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.cc b/gnuradio-core/src/lib/runtime/gr_select_handler.cc index d85883a65..faaa96e56 100644 --- a/gnuradio-core/src/lib/runtime/gr_select_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.h b/gnuradio-core/src/lib/runtime/gr_select_handler.h index d07ff007f..482a0ea65 100644 --- a/gnuradio-core/src/lib/runtime/gr_select_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_SELECT_HANDLER_H diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc index 3d401557b..794291f2c 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h index 1272831e5..304199bf2 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_SINGLE_THREADED_SCHEDULER_H diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i index 40058228b..12c3065ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #include diff --git a/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i b/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i index ca4f6e600..cbcd1b005 100644 --- a/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i +++ b/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ %define GR_SWIG_BLOCK_MAGIC(PKG, BASE_NAME) diff --git a/gnuradio-core/src/lib/runtime/gr_timer.h b/gnuradio-core/src/lib/runtime/gr_timer.h index 709b98470..c0c3c92aa 100644 --- a/gnuradio-core/src/lib/runtime/gr_timer.h +++ b/gnuradio-core/src/lib/runtime/gr_timer.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_TIMER_H #define INCLUDED_GR_TIMER_H diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc b/gnuradio-core/src/lib/runtime/gr_tmp_path.cc index 7eb03b5d5..4c156fb97 100644 --- a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc +++ b/gnuradio-core/src/lib/runtime/gr_tmp_path.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #include diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.h b/gnuradio-core/src/lib/runtime/gr_tmp_path.h index 742ce0563..987df64e4 100644 --- a/gnuradio-core/src/lib/runtime/gr_tmp_path.h +++ b/gnuradio-core/src/lib/runtime/gr_tmp_path.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _GR_TMP_PATH_H_ diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h index 370ca5642..d37d3bee0 100644 --- a/gnuradio-core/src/lib/runtime/gr_types.h +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_GR_TYPES_H diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc index 3586c4c73..980ec3c20 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h index e2af93587..49039fd36 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _GR_VMCIRCBUF_H_ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc index ffad5ac7d..75f28e888 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h index f7113cf4f..20aff94b2 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _GR_VMCIRCBUF_CREATEFILEMAPPING_H_ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc index 65fa1183b..1d8694cd0 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h index 4b1feafff..a852b813f 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _GR_VMCIRCBUF_MMAP_SHM_OPEN_H_ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc index a07df779c..b898498e5 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h index 3b9f5dba8..b43de2ef5 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _GR_VMCIRCBUF_MMAP_TMPFILE_H_ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc index 4b6fcfe33..fe0322f73 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h index 9a8c128a5..cfa683255 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _GR_VMCIRCBUF_SYSV_SHM_H_ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_block.cc index e3a21be35..becaf4f29 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.h b/gnuradio-core/src/lib/runtime/qa_gr_block.h index 6e3082514..58aeb6dae 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_QA_GR_BLOCK_H diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc index 5a3d4d3d7..d5a63c68a 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.h b/gnuradio-core/src/lib/runtime/qa_gr_buffer.h index 700629cc4..46e3ddc11 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_QA_GR_BUFFER_H diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc index c180e7b74..ed32f9554 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h index 225ce8068..ef14ab1cd 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef INCLUDED_QA_GR_IO_SIGNATURE_H diff --git a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc index f3c815a0d..594e36882 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H diff --git a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h index 41f69c353..8ae1d8a03 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _QA_GR_VMCIRCBUF_H_ #define _QA_GR_VMCIRCBUF_H_ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 668628f2a..165a34703 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -15,8 +15,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ /* diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.h b/gnuradio-core/src/lib/runtime/qa_runtime.h index 5862b1ea2..b9a920ba7 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.h +++ b/gnuradio-core/src/lib/runtime/qa_runtime.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _QA_RUNTIME_H_ diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index d8dd34f1e..3b08edd00 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ %{ diff --git a/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc b/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc index 26bfa6d2d..11704e415 100644 --- a/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc +++ b/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #include -- cgit From 348e6d5266d353feef7fb8043963682b1d58fc4d Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 6 Oct 2006 03:52:50 +0000 Subject: Reduced tmp usage during gnuradio-core 'make check' git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3721 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc index 980ec3c20..a302c010a 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc @@ -226,9 +226,9 @@ standard_tests (gr_vmcircbuf_factory *f, int verbose) ok &= test_a_bunch (f, 1, 1 * granularity, &start, v); // 1 x 4KB = 4KB if (ok){ - ok &= test_a_bunch (f, 64, 4 * granularity, &start, v); // 256 x 16KB = 4MB - ok &= test_a_bunch (f, 32, 4 * (1L << 20), &start, v); // 32 x 4MB = 64MB - ok &= test_a_bunch (f, 256, 256 * (1L << 10), &start, v); // 256 x 256KB = 64MB + ok &= test_a_bunch (f, 64, 4 * granularity, &start, v); // 64 x 16KB = 1MB + ok &= test_a_bunch (f, 4, 4 * (1L << 20), &start, v); // 4 x 4MB = 16MB +// ok &= test_a_bunch (f, 256, 256 * (1L << 10), &start, v); // 256 x 256KB = 64MB } if (verbose >= 1) -- cgit From 5de36fac220305307d6fb64eabe6f417a26c0982 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 12 Dec 2006 18:11:13 +0000 Subject: Move gr_runtime.h out of the way in preparation for merge of hier developer branch. No changes in functionality. Passes make distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4068 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 2 +- gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 2 +- gnuradio-core/src/lib/runtime/gr_buffer.h | 2 +- gnuradio-core/src/lib/runtime/gr_io_signature.h | 2 +- gnuradio-core/src/lib/runtime/gr_runtime.h | 44 ---------------------- gnuradio-core/src/lib/runtime/gr_runtime_types.h | 44 ++++++++++++++++++++++ .../src/lib/runtime/gr_single_threaded_scheduler.h | 2 +- gnuradio-core/src/lib/runtime/qa_gr_block.cc | 2 +- gnuradio-core/src/lib/runtime/runtime.i | 2 +- 10 files changed, 52 insertions(+), 52 deletions(-) delete mode 100644 gnuradio-core/src/lib/runtime/gr_runtime.h create mode 100644 gnuradio-core/src/lib/runtime/gr_runtime_types.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index cce4e6f84..2c1ea7eff 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -74,7 +74,7 @@ grinclude_HEADERS = \ gr_pagesize.h \ gr_preferences.h \ gr_realtime.h \ - gr_runtime.h \ + gr_runtime_types.h \ gr_select_handler.h \ gr_single_threaded_scheduler.h \ gr_timer.h \ diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 8b234c751..9723be108 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -23,7 +23,7 @@ #ifndef INCLUDED_GR_BLOCK_H #define INCLUDED_GR_BLOCK_H -#include +#include #include /*! diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index c3e360cd1..8c4615919 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -23,7 +23,7 @@ #ifndef INCLUDED_GR_BLOCK_DETAIL_H #define INCLUDED_GR_BLOCK_DETAIL_H -#include +#include #include /*! diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 506a16616..46017f6ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -23,7 +23,7 @@ #ifndef INCLUDED_GR_BUFFER_H #define INCLUDED_GR_BUFFER_H -#include +#include class gr_vmcircbuf; diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index c146193bc..e5e009781 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -23,7 +23,7 @@ #ifndef INCLUDED_IO_SIGNATURE_H #define INCLUDED_IO_SIGNATURE_H -#include +#include /*! * \brief i/o signature for input and output ports. diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.h b/gnuradio-core/src/lib/runtime/gr_runtime.h deleted file mode 100644 index 55cbabe18..000000000 --- a/gnuradio-core/src/lib/runtime/gr_runtime.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_RUNTIME_H -#define INCLUDED_GR_RUNTIME_H - -#include - -/* - * typedefs for smart pointers we use throughout the runtime system - */ - -class gr_block; -class gr_block_detail; -class gr_io_signature; -class gr_buffer; -class gr_buffer_reader; - -typedef boost::shared_ptr gr_block_sptr; -typedef boost::shared_ptr gr_block_detail_sptr; -typedef boost::shared_ptr gr_io_signature_sptr; -typedef boost::shared_ptr gr_buffer_sptr; -typedef boost::shared_ptr gr_buffer_reader_sptr; - -#endif /* INCLUDED_GR_RUNTIME_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_types.h b/gnuradio-core/src/lib/runtime/gr_runtime_types.h new file mode 100644 index 000000000..55cbabe18 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_runtime_types.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_RUNTIME_H +#define INCLUDED_GR_RUNTIME_H + +#include + +/* + * typedefs for smart pointers we use throughout the runtime system + */ + +class gr_block; +class gr_block_detail; +class gr_io_signature; +class gr_buffer; +class gr_buffer_reader; + +typedef boost::shared_ptr gr_block_sptr; +typedef boost::shared_ptr gr_block_detail_sptr; +typedef boost::shared_ptr gr_io_signature_sptr; +typedef boost::shared_ptr gr_buffer_sptr; +typedef boost::shared_ptr gr_buffer_reader_sptr; + +#endif /* INCLUDED_GR_RUNTIME_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h index 304199bf2..5e21d8d08 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h @@ -23,7 +23,7 @@ #ifndef INCLUDED_GR_SINGLE_THREADED_SCHEDULER_H #define INCLUDED_GR_SINGLE_THREADED_SCHEDULER_H -#include +#include #include class gr_single_threaded_scheduler; diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_block.cc index becaf4f29..4773a6eaa 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.cc @@ -25,7 +25,7 @@ #endif #include #include -#include +#include #include #include #include diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 3b08edd00..f2fd36437 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -21,7 +21,7 @@ */ %{ -#include +#include #include #include #include -- cgit From 76ed4c2fea5f59bfe02bbbb17754ef7eda44feca Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 12 Dec 2006 20:00:39 +0000 Subject: Merge jcorgan/hier developer branch into trunk. Enables creation of true hierarchical blocks, from either C++ or Python, as well as creating pure C++ gnuradio applications. EXPERIMENTAL. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4070 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 20 + gnuradio-core/src/lib/runtime/gr_basic_block.cc | 59 +++ gnuradio-core/src/lib/runtime/gr_basic_block.h | 99 +++++ gnuradio-core/src/lib/runtime/gr_basic_block.i | 52 +++ gnuradio-core/src/lib/runtime/gr_block.cc | 23 +- gnuradio-core/src/lib/runtime/gr_block.h | 66 +-- gnuradio-core/src/lib/runtime/gr_block.i | 16 +- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 3 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 28 +- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 63 +++ gnuradio-core/src/lib/runtime/gr_hier_block2.h | 67 +++ gnuradio-core/src/lib/runtime/gr_hier_block2.i | 52 +++ .../src/lib/runtime/gr_hier_block2_detail.cc | 227 ++++++++++ .../src/lib/runtime/gr_hier_block2_detail.h | 66 +++ gnuradio-core/src/lib/runtime/gr_runtime.cc | 70 +++ gnuradio-core/src/lib/runtime/gr_runtime.h | 49 +++ gnuradio-core/src/lib/runtime/gr_runtime.i | 42 ++ gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 130 ++++++ gnuradio-core/src/lib/runtime/gr_runtime_impl.h | 74 ++++ gnuradio-core/src/lib/runtime/gr_runtime_types.h | 24 +- .../src/lib/runtime/gr_simple_flowgraph.cc | 67 +++ .../src/lib/runtime/gr_simple_flowgraph.h | 52 +++ .../src/lib/runtime/gr_simple_flowgraph.i | 45 ++ .../src/lib/runtime/gr_simple_flowgraph_detail.cc | 471 +++++++++++++++++++++ .../src/lib/runtime/gr_simple_flowgraph_detail.h | 128 ++++++ gnuradio-core/src/lib/runtime/qa_gr_block.cc | 1 - gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc | 46 ++ gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h | 43 ++ gnuradio-core/src/lib/runtime/qa_runtime.cc | 2 + gnuradio-core/src/lib/runtime/runtime.i | 7 + 30 files changed, 1992 insertions(+), 100 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/gr_basic_block.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_basic_block.h create mode 100644 gnuradio-core/src/lib/runtime/gr_basic_block.i create mode 100644 gnuradio-core/src/lib/runtime/gr_hier_block2.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_hier_block2.h create mode 100644 gnuradio-core/src/lib/runtime/gr_hier_block2.i create mode 100644 gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h create mode 100644 gnuradio-core/src/lib/runtime/gr_runtime.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_runtime.h create mode 100644 gnuradio-core/src/lib/runtime/gr_runtime.i create mode 100644 gnuradio-core/src/lib/runtime/gr_runtime_impl.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_runtime_impl.h create mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h create mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i create mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 2c1ea7eff..47ae07a6b 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -30,8 +30,13 @@ libruntime_la_LIBADD = \ libruntime_la_SOURCES = \ + gr_basic_block.cc \ + gr_simple_flowgraph.cc \ + gr_simple_flowgraph_detail.cc \ gr_block.cc \ gr_block_detail.cc \ + gr_hier_block2.cc \ + gr_hier_block2_detail.cc \ gr_buffer.cc \ gr_dispatcher.cc \ gr_error_handler.cc \ @@ -43,6 +48,8 @@ libruntime_la_SOURCES = \ gr_pagesize.cc \ gr_preferences.cc \ gr_realtime.cc \ + gr_runtime.cc \ + gr_runtime_impl.cc \ gr_single_threaded_scheduler.cc \ gr_tmp_path.cc \ gr_vmcircbuf.cc \ @@ -54,14 +61,20 @@ libruntime_la_SOURCES = \ libruntime_qa_la_SOURCES = \ qa_gr_block.cc \ + qa_gr_hier_block2.cc \ qa_gr_buffer.cc \ qa_gr_io_signature.cc \ qa_gr_vmcircbuf.cc \ qa_runtime.cc grinclude_HEADERS = \ + gr_basic_block.h \ + gr_simple_flowgraph.h \ + gr_simple_flowgraph_detail.h \ gr_block.h \ gr_block_detail.h \ + gr_hier_block2.h \ + gr_hier_block2_detail.h \ gr_buffer.h \ gr_complex.h \ gr_dispatcher.h \ @@ -74,6 +87,8 @@ grinclude_HEADERS = \ gr_pagesize.h \ gr_preferences.h \ gr_realtime.h \ + gr_runtime.h \ + gr_runtime_impl.h \ gr_runtime_types.h \ gr_select_handler.h \ gr_single_threaded_scheduler.h \ @@ -88,14 +103,17 @@ noinst_HEADERS = \ gr_vmcircbuf_sysv_shm.h \ gr_vmcircbuf_createfilemapping.h \ qa_gr_block.h \ + qa_gr_hier_block2.h \ qa_gr_buffer.h \ qa_gr_io_signature.h \ qa_gr_vmcircbuf.h \ qa_runtime.h swiginclude_HEADERS = \ + gr_basic_block.i \ gr_block.i \ gr_block_detail.i \ + gr_hier_block2.i \ gr_buffer.i \ gr_dispatcher.i \ gr_error_handler.i \ @@ -104,6 +122,8 @@ swiginclude_HEADERS = \ gr_msg_handler.i \ gr_msg_queue.i \ gr_realtime.i \ + gr_runtime.i \ + gr_simple_flowgraph.i \ gr_single_threaded_scheduler.i \ gr_swig_block_magic.i \ runtime.i diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc new file mode 100644 index 000000000..a5f1a4f83 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +static long s_next_id = 0; +static long s_ncurrently_allocated = 0; + +long +gr_basic_block_ncurrently_allocated() +{ + return s_ncurrently_allocated; +} + +gr_basic_block::gr_basic_block(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature) + : d_name(name), + d_input_signature(input_signature), + d_output_signature(output_signature), + d_unique_id(s_next_id++) +{ + s_ncurrently_allocated++; +} + +gr_basic_block::~gr_basic_block() +{ + s_ncurrently_allocated--; +} + +gr_basic_block_sptr +gr_basic_block::basic_block() +{ + return shared_from_this(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h new file mode 100644 index 000000000..583c3241d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -0,0 +1,99 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_BASIC_BLOCK_H +#define INCLUDED_GR_BASIC_BLOCK_H + +#include +#include +#include + +/*! + * \brief The abstract base class for all signal processing blocks. + * \ingroup block + * + * Basic blocks are the bare abstraction of an entity that has a name + * and a set of inputs and outputs. These are never instantiated + * directly; rather, this is the abstract parent class of both gr_hier_block, + * which is a recursive container, and gr_block, which implements actual + * signal processing functions. + */ + +class gr_basic_block : public boost::enable_shared_from_this +{ +protected: + std::string d_name; + gr_io_signature_sptr d_input_signature; + gr_io_signature_sptr d_output_signature; + long d_unique_id; + + //! Protected constructor prevents instantiation by non-derived classes + gr_basic_block(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + + //! may only be called during constructor + void set_input_signature(gr_io_signature_sptr iosig) { + d_input_signature = iosig; + } + + //! may only be called during constructor + void set_output_signature(gr_io_signature_sptr iosig) { + d_output_signature = iosig; + } + +public: + virtual ~gr_basic_block(); + long unique_id() const { return d_unique_id; } + std::string name() const { return d_name; } + gr_io_signature_sptr input_signature() const { return d_input_signature; } + gr_io_signature_sptr output_signature() const { return d_output_signature; } + gr_basic_block_sptr basic_block(); // Needed for Python type coercion + + /*! + * \brief Confirm that ninputs and noutputs is an acceptable combination. + * + * \param ninputs number of input streams connected + * \param noutputs number of output streams connected + * + * \returns true if this is a valid configuration for this block. + * + * This function is called by the runtime system whenever the + * topology changes. Most classes do not need to override this. + * This check is in addition to the constraints specified by the input + * and output gr_io_signatures. + */ + virtual bool check_topology(int ninputs, int noutputs) { return true; } +}; + +typedef std::vector gr_basic_block_vector_t; +typedef std::vector::iterator gr_basic_block_viter_t; + +long gr_basic_block_ncurrently_allocated(); + +inline std::ostream &operator << (std::ostream &os, gr_basic_block_sptr basic_block) +{ + os << basic_block->name() << "(" << basic_block->unique_id() << ")"; + return os; +} + +#endif /* INCLUDED_GR_BASIC_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i new file mode 100644 index 000000000..33b895d43 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +class gr_basic_block; +typedef boost::shared_ptr gr_basic_block_sptr; +%template(gr_basic_block_sptr) boost::shared_ptr; + +// support vectors of these... +namespace std { + %template(x_vector_gr_basic_block_sptr) vector; +}; + +class gr_basic_block +{ +protected: + gr_basic_block(); + +public: + virtual ~gr_basic_block(); + std::string name() const; + gr_io_signature_sptr input_signature() const; + gr_io_signature_sptr output_signature() const; + long unique_id() const; + gr_basic_block_sptr basic_block(); + bool check_topology (int ninputs, int noutputs); +}; + +%rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; +long gr_basic_block_ncurrently_allocated(); + +%pythoncode %{ +gr_basic_block_sptr.__repr__ = lambda self: "" % (self.name(), self.unique_id ()) +%} diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 65e16045a..1b1d35756 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -27,34 +27,21 @@ #include #include #include - -static long s_next_id = 0; -static long s_ncurrently_allocated = 0; - -long -gr_block_ncurrently_allocated () -{ - return s_ncurrently_allocated; -} +#include gr_block::gr_block (const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature) - : d_name (name), - d_input_signature (input_signature), - d_output_signature (output_signature), + : gr_basic_block(name, input_signature, output_signature), d_output_multiple (1), d_relative_rate (1.0), - d_unique_id (s_next_id++), d_history(1), d_fixed_rate(false) { - s_ncurrently_allocated++; } gr_block::~gr_block () { - s_ncurrently_allocated--; } // stub implementation: 1:1 @@ -69,12 +56,6 @@ gr_block::forecast (int noutput_items, gr_vector_int &ninput_items_required) // default implementation -bool -gr_block::check_topology (int ninputs, int noutputs) -{ - return true; -} - bool gr_block::start() { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 9723be108..247238bb0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -23,13 +23,17 @@ #ifndef INCLUDED_GR_BLOCK_H #define INCLUDED_GR_BLOCK_H -#include -#include +#include /*! - * \brief The abstract base class for all signal processing blocks. + * \brief The abstract base class for all 'terminal' processing blocks. * \ingroup block * + * A signal processing flow is constructed by creating a tree of + * hierarchical blocks, which at any level may also contain terminal nodes + * that actually implement signal processing functions. This is the base + * class for all such leaf nodes. + * Blocks have a set of input streams and output streams. The * input_signature and output_signature define the number of input * streams and output streams respectively, and the type of the data @@ -49,16 +53,11 @@ * It reads the input items and writes the output items. */ -class gr_block { +class gr_block : public gr_basic_block { public: virtual ~gr_block (); - - std::string name () const { return d_name; } - gr_io_signature_sptr input_signature () const { return d_input_signature; } - gr_io_signature_sptr output_signature () const { return d_output_signature; } - long unique_id () const { return d_unique_id; } /*! * Assume block computes y_i = f(x_i, x_i-1, x_i-2, x_i-3...) @@ -113,21 +112,6 @@ class gr_block { gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) = 0; - /*! - * \brief Confirm that ninputs and noutputs is an acceptable combination. - * - * \param ninputs number of input streams connected - * \param noutputs number of output streams connected - * - * \returns true if this is a valid configuration for this block. - * - * This function is called by the runtime system whenever the - * topology changes. Most classes do not need to override this. - * This check is in addition to the constraints specified by the input - * and output gr_io_signatures. - */ - virtual bool check_topology (int ninputs, int noutputs); - /*! * \brief Called to enable drivers, etc for i/o devices. * @@ -205,32 +189,17 @@ class gr_block { private: - std::string d_name; - gr_io_signature_sptr d_input_signature; - gr_io_signature_sptr d_output_signature; - int d_output_multiple; - double d_relative_rate; // approx output_rate / input_rate - gr_block_detail_sptr d_detail; // implementation details - long d_unique_id; // convenient for debugging - unsigned d_history; - bool d_fixed_rate; - - + int d_output_multiple; + double d_relative_rate; // approx output_rate / input_rate + gr_block_detail_sptr d_detail; // implementation details + unsigned d_history; + bool d_fixed_rate; + protected: gr_block (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - - //! may only be called during constructor - void set_input_signature (gr_io_signature_sptr iosig){ - d_input_signature = iosig; - } - - //! may only be called during constructor - void set_output_signature (gr_io_signature_sptr iosig){ - d_output_signature = iosig; - } + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); void set_fixed_rate(bool fixed_rate){ d_fixed_rate = fixed_rate; } @@ -242,6 +211,7 @@ class gr_block { void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } }; -long gr_block_ncurrently_allocated (); +typedef std::vector gr_block_vector_t; +typedef std::vector::iterator gr_block_viter_t; #endif /* INCLUDED_GR_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index 3bfd24367..5d0f5fb1b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -20,6 +20,8 @@ * Boston, MA 02110-1301, USA. */ +%include + class gr_block; typedef boost::shared_ptr gr_block_sptr; %template(gr_block_sptr) boost::shared_ptr; @@ -29,26 +31,21 @@ namespace std { %template(x_vector_gr_block_sptr) vector; }; -class gr_block { +class gr_block : public gr_basic_block { protected: gr_block (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); public: virtual ~gr_block (); - std::string name () const; - gr_io_signature_sptr input_signature () const; - gr_io_signature_sptr output_signature () const; - long unique_id () const; unsigned history () const; int output_multiple () const; double relative_rate () const; - bool check_topology (int ninputs, int noutputs); bool start(); bool stop(); @@ -57,9 +54,6 @@ class gr_block { void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } }; -%rename(block_ncurrently_allocated) gr_block_ncurrently_allocated; -long gr_block_ncurrently_allocated (); - %pythoncode %{ gr_block_sptr.__repr__ = lambda self: "" % (self.name(), self.unique_id ()) gr_block_sptr.block = lambda self: self diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index ed414d472..5feb180f7 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -38,7 +38,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_input (ninputs), d_output (noutputs), - d_done (false) + d_done (false), + d_color (gr_block_detail::WHITE) { s_ncurrently_allocated++; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 8c4615919..d89b7fea1 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 2, 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 detail. - * + * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -75,18 +75,26 @@ class gr_block_detail { void produce_each (int how_many_items); + /*! + * \brief Allow the flowgraph to set for sorting and partitioning + */ + enum vcolor { WHITE, GREY, BLACK }; + void set_color(vcolor color) { d_color = color; } + vcolor color() const { return d_color; } + // ---------------------------------------------------------------------------- private: - unsigned int d_ninputs; - unsigned int d_noutputs; + unsigned int d_ninputs; + unsigned int d_noutputs; std::vector d_input; - std::vector d_output; - bool d_done; - + std::vector d_output; + bool d_done; + vcolor d_color; + gr_block_detail (unsigned int ninputs, unsigned int noutputs); - friend gr_block_detail_sptr + friend gr_block_detail_sptr gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); }; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc new file mode 100644 index 000000000..65dea95fb --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature) +{ + return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); +} + +gr_hier_block2::gr_hier_block2(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature) + : gr_basic_block(name, input_signature, output_signature), + d_detail(new gr_hier_block2_detail(this)) +{ +} + +gr_hier_block2::~gr_hier_block2() +{ + delete d_detail; +} + +void +gr_hier_block2::define_component(const std::string &name, gr_basic_block_sptr block) +{ + d_detail->define_component(name, block); +} + +void +gr_hier_block2::connect(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port) +{ + d_detail->connect(src_name, src_port, dst_name, dst_port); +} diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h new file mode 100644 index 000000000..9d2dd3569 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_GR_HIER_BLOCK2_H +#define INCLUDED_GR_HIER_BLOCK2_H + +#include + +/*! + * \brief public constructor for gr_hier_block2 + */ +gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + +class gr_hier_block2_detail; + +/*! + * \brief gr_hier_block2 - Hierarchical container class for gr_block's + * + */ +class gr_hier_block2 : public gr_basic_block +{ +private: + friend class gr_hier_block2_detail; + friend class gr_runtime_impl; + friend gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + + /*! + * \brief Private implementation details of gr_hier_block2 + */ + gr_hier_block2_detail *d_detail; + +protected: + gr_hier_block2(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + +public: + virtual ~gr_hier_block2(); + + void define_component(const std::string &name, gr_basic_block_sptr basic_block); + void connect(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port); +}; + +#endif /* INCLUDED_GR_HIER_BLOCK2_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i new file mode 100644 index 000000000..c5a676534 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +%include + +class gr_hier_block2; +typedef boost::shared_ptr gr_hier_block2_sptr; +%template(gr_hier_block2_sptr) boost::shared_ptr; + +// Hack to have a Python shim implementation of gr.hier_block2 +// that instantiates one of these and passes through calls +%rename(hier_block2_swig) gr_make_hier_block2; +gr_hier_block2_sptr gr_make_hier_block2(const std::string name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + +class gr_hier_block2 : public gr_basic_block +{ +private: + gr_hier_block2(const std::string name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + +public: + ~gr_hier_block2 (); + + // Add a named block to the container + void define_component(const std::string &name, gr_basic_block_sptr basic_block) + throw (std::invalid_argument); + void connect(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port) + throw (std::invalid_argument); +}; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc new file mode 100644 index 000000000..545a64bfd --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -0,0 +1,227 @@ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : +d_owner(owner) +{ +} + +gr_hier_block2_detail::~gr_hier_block2_detail() +{ + d_owner = 0; // Don't use delete, we didn't allocate +} + +gr_basic_block_sptr +gr_hier_block2_detail::lookup_block(const std::string &name) +{ + gr_hier_component_miter_t p = d_components.find(name); + if (p != d_components.end()) + return p->second; + else + return gr_basic_block_sptr(); +} + +void +gr_hier_block2_detail::define_component(const std::string &name, gr_basic_block_sptr block) +{ + if (!block) + throw std::invalid_argument("null block passed"); + + if (name == "self") + throw std::invalid_argument("name is reserved"); + + // TODO: reject names with '.' inside + + if (!lookup_block(name)) + d_components[name] = block; + else + throw std::invalid_argument("name already in use"); +} + +void +gr_hier_block2_detail::connect(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port) +{ + gr_io_signature_sptr src_io_signature; + gr_io_signature_sptr dst_io_signature; + + // Check against our *input_signature* if we're wiring from one of our external inputs + if (src_name == "self") + src_io_signature = d_owner->input_signature(); + else { + gr_basic_block_sptr src_block = lookup_block(src_name); + if (!src_block) + throw std::invalid_argument("undefined src name"); + src_io_signature = src_block->output_signature(); + } + + // Check against our *output_signature* if we're wiring to one of our external outputs + if (dst_name == "self") + dst_io_signature = d_owner->output_signature(); + else { + gr_basic_block_sptr dst_block = lookup_block(dst_name); + if (!dst_block) + throw std::invalid_argument("undefined dst name"); + dst_io_signature = dst_block->input_signature(); + } + + // Check port numbers are valid + check_valid_port(src_io_signature, src_port); + check_valid_port(dst_io_signature, dst_port); + + // Check destination port not already in use + check_dst_not_used(dst_name, dst_port); + + // Check endpoint types match + check_type_match(src_io_signature, src_port, dst_io_signature, dst_port); + + d_edges.push_back(gr_make_edge(src_name, src_port, dst_name, dst_port)); +} + +void +gr_hier_block2_detail::check_valid_port(gr_io_signature_sptr sig, int port) +{ + if (port < 0) + throw std::invalid_argument("port number must not be negative"); + + if (sig->max_streams() >= 0 && port >= sig->max_streams()) + throw std::invalid_argument("port number exceeds max streams"); +} + +void +gr_hier_block2_detail::check_dst_not_used(const std::string name, int port) +{ + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if ((*p)->dst_name() == name && (*p)->dst_port() == port) + throw std::invalid_argument("destination port in use"); +} + +void +gr_hier_block2_detail::check_type_match(gr_io_signature_sptr src_sig, int src_port, + gr_io_signature_sptr dst_sig, int dst_port) +{ + if (src_sig->sizeof_stream_item(src_port) != dst_sig->sizeof_stream_item(dst_port)) + throw std::invalid_argument("type mismatch"); +} + +std::string +gr_hier_block2_detail::prepend_prefix(const std::string &prefix, const std::string &str) +{ + return prefix + ((prefix == "") ? "" : ".") + str; +} + +gr_endpoint +gr_hier_block2_detail::match_endpoint(const std::string &name, int port, bool is_input) +{ + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + if (is_input) { + if ((*p)->src_name() == name && (*p)->src_port() == port) + return resolve_endpoint((*p)->dst_name(), (*p)->dst_port(), "", !is_input); + } + else { + if ((*p)->dst_name() == name && (*p)->dst_port() == port) + return resolve_endpoint((*p)->src_name(), (*p)->src_port(), "", !is_input); + } + } + + // Should never get here + throw std::runtime_error("unable to match endpoint"); +} + +gr_endpoint +gr_hier_block2_detail::resolve_endpoint(const std::string &name, int port, + const std::string &prefix, bool is_input) +{ + gr_basic_block_sptr basic_block = lookup_block(name); + + // Check if 'name' points to gr_block (leaf node) + gr_block_sptr block(boost::dynamic_pointer_cast(basic_block)); + if (block) + return gr_endpoint(prepend_prefix(prefix, name), port); + + // Check if 'name' points to hierarchical block + gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(basic_block)); + if (hier_block2) { + std::string child_prefix = prepend_prefix(prefix, name); + gr_endpoint match(hier_block2->d_detail->match_endpoint("self", port, !is_input)); + return gr_endpoint(prepend_prefix(child_prefix, match.name()), match.port()); + } + + // Shouldn't ever get here + throw std::runtime_error("unable to resolve endpoint"); +} + +void +gr_hier_block2_detail::flatten(gr_simple_flowgraph_sptr sfg, const std::string &prefix) +{ + flatten_components(sfg, prefix); + flatten_edges(sfg, prefix); +} + +void +gr_hier_block2_detail::flatten_components(gr_simple_flowgraph_sptr sfg, const std::string &prefix) +{ + // Add my non-hierarchical components to the simple flowgraph, then recurse + for (gr_hier_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { + std::string name = prepend_prefix(prefix, p->first); + + gr_basic_block_sptr basic_block = p->second; + gr_block_sptr block(boost::dynamic_pointer_cast(basic_block)); + if (block) + sfg->define_component(name, block); + + gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(basic_block)); + if (hier_block2) + hier_block2->d_detail->flatten_components(sfg, name); + } +} + +void +gr_hier_block2_detail::flatten_edges(gr_simple_flowgraph_sptr sfg, const std::string &prefix) +{ + // Add my edges to the flow graph, resolving references to actual endpoints + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + // Connections to self get resolved/added by parent if actually connected + if ((*p)->src_name() == "self" || (*p)->dst_name() == "self") + continue; + + gr_endpoint src_endp = resolve_endpoint((*p)->src_name(), (*p)->src_port(), prefix, true); + gr_endpoint dst_endp = resolve_endpoint((*p)->dst_name(), (*p)->dst_port(), prefix, false); + sfg->connect(src_endp.name(), src_endp.port(), dst_endp.name(), dst_endp.port()); + } + + // Recurse hierarchical children + for (gr_hier_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { + gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(p->second)); + if (hier_block2) + hier_block2->d_detail->flatten_edges(sfg, prepend_prefix(prefix, p->first)); + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h new file mode 100644 index 000000000..095bd40f5 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -0,0 +1,66 @@ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_GR_HIER_BLOCK2_DETAIL_H +#define INCLUDED_GR_HIER_BLOCK2_DETAIL_H + +#include +#include +#include + +typedef std::map gr_hier_component_map_t; +typedef std::map::iterator gr_hier_component_miter_t; + +class gr_hier_block2_detail : boost::noncopyable +{ +private: + friend class gr_hier_block2; + friend class gr_runtime_impl; + + // Constructor--it's private, only friends can instantiate + gr_hier_block2_detail(gr_hier_block2 *owner); + + // Private implementation data + gr_hier_block2 *d_owner; + gr_hier_component_map_t d_components; + gr_edge_vector_t d_edges; + + // Private implementation methods + void define_component(const std::string &name, gr_basic_block_sptr block); + gr_basic_block_sptr lookup_block(const std::string &name); + void connect(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port); + void check_valid_port(gr_io_signature_sptr sig, int port); + void check_dst_not_used(const std::string name, int port); + void check_type_match(gr_io_signature_sptr src_sig, int src_port, + gr_io_signature_sptr dst_sig, int dst_port); + std::string prepend_prefix(const std::string &prefix, const std::string &str); + void flatten(gr_simple_flowgraph_sptr sfg, const std::string &prefix = ""); + void flatten_components(gr_simple_flowgraph_sptr sfg, const std::string &prefix); + void flatten_edges(gr_simple_flowgraph_sptr sfg, const std::string &prefix); + gr_endpoint match_endpoint(const std::string &name, int port, bool is_input); + gr_endpoint resolve_endpoint(const std::string &name, int port, + const std::string &prefix, bool is_input); + +public: + ~gr_hier_block2_detail(); +}; + +#endif /* INCLUDED_GR_HIER_BLOCK2_DETAIL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.cc b/gnuradio-core/src/lib/runtime/gr_runtime.cc new file mode 100644 index 000000000..926e87857 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_runtime.cc @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +gr_runtime_sptr +gr_make_runtime(gr_hier_block2_sptr top_block) +{ + return gr_runtime_sptr(new gr_runtime(top_block)); +} + +gr_runtime::gr_runtime(gr_hier_block2_sptr top_block) +{ + d_impl = new gr_runtime_impl(top_block); +} + +gr_runtime::~gr_runtime() +{ + delete d_impl; +} + +void +gr_runtime::start() +{ + d_impl->start(); +} + +void +gr_runtime::stop() +{ + d_impl->stop(); +} + +void +gr_runtime::wait() +{ + d_impl->wait(); +} + +void +gr_runtime::run() +{ + start(); + wait(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.h b/gnuradio-core/src/lib/runtime/gr_runtime.h new file mode 100644 index 000000000..fc58da456 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_runtime.h @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_RUNTIME_H +#define INCLUDED_GR_RUNTIME_H + +#include + +class gr_runtime_impl; + +gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); + +class gr_runtime +{ +private: + gr_runtime(gr_hier_block2_sptr top_block); + friend gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); + + gr_runtime_impl *d_impl; + +public: + ~gr_runtime(); + + void start(); + void stop(); + void wait(); + void run(); +}; + +#endif /* INCLUDED_GR_RUNTIME_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.i b/gnuradio-core/src/lib/runtime/gr_runtime.i new file mode 100644 index 000000000..496adff37 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_runtime.i @@ -0,0 +1,42 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +class gr_runtime; +typedef boost::shared_ptr gr_runtime_sptr; +%template(gr_runtime_sptr) boost::shared_ptr; + +%rename(runtime) gr_make_runtime; +gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); + +class gr_runtime +{ +protected: + gr_runtime(gr_hier_block2_sptr top_block); + +public: + void start() + throw (std::runtime_error); + void stop(); + void wait(); + void run() + throw (std::runtime_error); +}; diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc new file mode 100644 index 000000000..2b104cd99 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -0,0 +1,130 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#define GR_RUNTIME_IMPL_DEBUG 0 + +#include +#include +#include +#include +#include +#include + +gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) : +d_running(false), +d_top_block(top_block), +d_sfg(gr_make_simple_flowgraph()), +d_graphs() +{ +} + +gr_runtime_impl::~gr_runtime_impl() +{ +} + +void +gr_runtime_impl::start() +{ + if (d_running) + throw std::runtime_error("already running"); + else + d_running = true; + + d_sfg->d_detail->reset(); + d_top_block->d_detail->flatten(d_sfg); + d_sfg->d_detail->validate(); + d_sfg->d_detail->setup_connections(); + + d_graphs = d_sfg->d_detail->partition(); + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "Flow graph has " << d_graphs.size() + << " sub-graphs." << std::endl; + + d_threads.clear(); + for (std::vector::iterator p = d_graphs.begin(); + p != d_graphs.end(); p++) { + gr_scheduler_thread_sptr thread = gr_make_scheduler_thread(*p); + thread->start(); + d_threads.push_back(thread); + } +} + +void +gr_runtime_impl::stop() +{ + if (!d_running) + return; + + for (gr_scheduler_thread_viter_t p = d_threads.begin(); + p != d_threads.end(); p++) + (*p)->stop(); + + d_running = false; +} + +void +gr_runtime_impl::wait() +{ + for (gr_scheduler_thread_viter_t p = d_threads.begin(); + p != d_threads.end(); p++) { + while(1) { + (*p)->join(NULL); + if (!(*p)->state() == omni_thread::STATE_TERMINATED) + break; + } + } +} + +gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph) +{ + return gr_scheduler_thread_sptr(new gr_scheduler_thread(graph)); +} + +gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) : + omni_thread(NULL, PRIORITY_NORMAL), + d_sts(gr_make_single_threaded_scheduler(graph)) +{ +} + +gr_scheduler_thread::~gr_scheduler_thread() +{ +} + +void gr_scheduler_thread::start() +{ + start_undetached(); +} + +void *gr_scheduler_thread::run_undetached(void *arg) +{ + d_sts->run(); + return 0; +} + +void gr_scheduler_thread::stop() +{ + d_sts->stop(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h new file mode 100644 index 000000000..54977ef97 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h @@ -0,0 +1,74 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_RUNTIME_IMPL_H +#define INCLUDED_GR_RUNTIME_IMPL_H + +#include +#include +#include +#include + +class gr_scheduler_thread; +typedef boost::shared_ptr gr_scheduler_thread_sptr; +typedef std::vector gr_scheduler_thread_vector_t; +typedef std::vector::iterator gr_scheduler_thread_viter_t; + +gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph); + +class gr_scheduler_thread : public omni_thread +{ +private: + gr_scheduler_thread(gr_block_vector_t graph); + friend gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph); + + gr_single_threaded_scheduler_sptr d_sts; + +public: + ~gr_scheduler_thread(); + virtual void *run_undetached(void *arg); + void start(); + void stop(); +}; + +class gr_runtime_impl +{ +private: + gr_runtime_impl(gr_hier_block2_sptr top_block); + friend class gr_runtime; + + bool d_running; + gr_hier_block2_sptr d_top_block; + gr_simple_flowgraph_sptr d_sfg; + std::vector d_graphs; + gr_scheduler_thread_vector_t d_threads; + + void start(); + void stop(); + void wait(); + +public: + ~gr_runtime_impl(); + +}; + +#endif /* INCLUDED_GR_RUNTIME_IMPL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_types.h b/gnuradio-core/src/lib/runtime/gr_runtime_types.h index 55cbabe18..dfa0ce94f 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_types.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_types.h @@ -20,8 +20,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef INCLUDED_GR_RUNTIME_H -#define INCLUDED_GR_RUNTIME_H +#ifndef INCLUDED_GR_RUNTIME_TYPES_H +#define INCLUDED_GR_RUNTIME_TYPES_H #include @@ -29,16 +29,24 @@ * typedefs for smart pointers we use throughout the runtime system */ +class gr_basic_block; class gr_block; class gr_block_detail; +class gr_hier_block2; class gr_io_signature; class gr_buffer; class gr_buffer_reader; +class gr_simple_flowgraph; +class gr_runtime; -typedef boost::shared_ptr gr_block_sptr; -typedef boost::shared_ptr gr_block_detail_sptr; -typedef boost::shared_ptr gr_io_signature_sptr; -typedef boost::shared_ptr gr_buffer_sptr; -typedef boost::shared_ptr gr_buffer_reader_sptr; +typedef boost::shared_ptr gr_basic_block_sptr; +typedef boost::shared_ptr gr_block_sptr; +typedef boost::shared_ptr gr_block_detail_sptr; +typedef boost::shared_ptr gr_hier_block2_sptr; +typedef boost::shared_ptr gr_io_signature_sptr; +typedef boost::shared_ptr gr_buffer_sptr; +typedef boost::shared_ptr gr_buffer_reader_sptr; +typedef boost::shared_ptr gr_runtime_sptr; +typedef boost::shared_ptr gr_simple_flowgraph_sptr; -#endif /* INCLUDED_GR_RUNTIME_H */ +#endif /* INCLUDED_GR_RUNTIME_TYPES_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc new file mode 100644 index 000000000..21aeb587c --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#define GR_SIMPLE_FLOWGRAPH_DEBUG 0 + +gr_simple_flowgraph_sptr gr_make_simple_flowgraph() +{ + return gr_simple_flowgraph_sptr(new gr_simple_flowgraph()); +} + +gr_simple_flowgraph::gr_simple_flowgraph() : +d_detail(new gr_simple_flowgraph_detail()) +{ +} + +gr_simple_flowgraph::~gr_simple_flowgraph() +{ + delete d_detail; +} + +void +gr_simple_flowgraph::define_component(const std::string &name, gr_block_sptr block) +{ + if (GR_SIMPLE_FLOWGRAPH_DEBUG) + std::cout << "Defining block " << block << " as " << name << std::endl; + d_detail->define_component(name, block); +} + +void +gr_simple_flowgraph::connect(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port) +{ + d_detail->connect(src_name, src_port, dst_name, dst_port); +} + +void +gr_simple_flowgraph::validate() +{ + d_detail->validate(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h new file mode 100644 index 000000000..ca2c505e5 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_SIMPLE_FLOWGRAPH_H +#define INCLUDED_GR_SIMPLE_FLOWGRAPH_H + +#include +#include +#include + +gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); + +class gr_simple_flowgraph_detail; + +class gr_simple_flowgraph +{ +private: + friend class gr_runtime_impl; + friend gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); + gr_simple_flowgraph(); + + gr_simple_flowgraph_detail *d_detail; + +public: + ~gr_simple_flowgraph(); + + void define_component(const std::string &name, gr_block_sptr block); + void connect(const std::string &src, int src_port, + const std::string &dst, int dst_port); + void validate(); +}; + +#endif /* INCLUDED_GR_SIMPLE_FLOWGRAPH_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i new file mode 100644 index 000000000..c3654fe50 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i @@ -0,0 +1,45 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +class gr_simple_flowgraph; +typedef boost::shared_ptr gr_simple_flowgraph_sptr; +%template(gr_simple_flowgraph_sptr) boost::shared_ptr; +%rename(simple_flowgraph) gr_make_simple_flowgraph; +%ignore gr_simple_flowgraph; + +gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); + +class gr_simple_flowgraph +{ +private: + gr_simple_flowgraph(); + +public: + ~gr_simple_flowgraph(); + void define_component(const std::string name, gr_block_sptr block) + throw (std::invalid_argument); + void connect(const std::string &src, int src_port, + const std::string &dst, int dst_port) + throw (std::invalid_argument); + void validate() + throw (std::runtime_error); +}; diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc new file mode 100644 index 000000000..2698bc6d8 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc @@ -0,0 +1,471 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG 0 + +gr_edge_sptr +gr_make_edge(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port) +{ + return gr_edge_sptr(new gr_edge(src_name, src_port, dst_name, dst_port)); +} + +gr_edge::gr_edge(const std::string &src_name, int src_port, const std::string &dst_name, int dst_port) + : d_src(src_name, src_port), + d_dst(dst_name, dst_port) +{ +} + +gr_edge::~gr_edge() +{ +} + +gr_simple_flowgraph_detail::gr_simple_flowgraph_detail() : +d_components(), +d_edges() +{ +} + +gr_simple_flowgraph_detail::~gr_simple_flowgraph_detail() +{ +} + +void +gr_simple_flowgraph_detail::reset() +{ + // Boost shared pointers will deallocate as needed + d_edges.clear(); + d_components.clear(); +} + +gr_block_sptr +gr_simple_flowgraph_detail::lookup_block(const std::string &name) +{ + gr_component_miter_t p = d_components.find(name); + if (p != d_components.end()) + return p->second; + else + return gr_block_sptr(); +} + +void +gr_simple_flowgraph_detail::define_component(const std::string &name, gr_block_sptr block) +{ + if (!block) + throw std::invalid_argument("null block passed"); + + if (!lookup_block(name)) + d_components[name] = block; + else + throw std::invalid_argument("name already in use"); +} + +void +gr_simple_flowgraph_detail::connect(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port) +{ + gr_block_sptr src_block = lookup_block(src_name); + gr_block_sptr dst_block = lookup_block(dst_name); + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Connecting " << src_name << ":" << src_port << "->" + << dst_name << ":" << dst_port << std::endl; + + if (!src_block) + throw std::invalid_argument("unknown src name"); + if (!dst_block) + throw std::invalid_argument("unknown dst name"); + + check_valid_port(src_block->output_signature(), src_port); + check_valid_port(dst_block->input_signature(), dst_port); + check_dst_not_used(dst_name, dst_port); + check_type_match(src_block, src_port, dst_block, dst_port); + + d_edges.push_back(gr_make_edge(src_name, src_port, dst_name, dst_port)); +} + +void +gr_simple_flowgraph_detail::check_valid_port(gr_io_signature_sptr sig, int port) +{ + if (port < 0) + throw std::invalid_argument("negative port number"); + if (sig->max_streams() >= 0 && port >= sig->max_streams()) + throw std::invalid_argument("port number exceeds max"); +} + +void +gr_simple_flowgraph_detail::check_dst_not_used(const std::string &name, int port) +{ + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if ((*p)->dst_name() == name && (*p)->dst_port() == port) + throw std::invalid_argument("dst already in use"); +} + +void +gr_simple_flowgraph_detail::check_type_match(gr_block_sptr src_block, int src_port, + gr_block_sptr dst_block, int dst_port) +{ + int src_size = src_block->output_signature()->sizeof_stream_item(src_port); + int dst_size = dst_block->input_signature()->sizeof_stream_item(dst_port); + + if (src_size != dst_size) + throw std::invalid_argument("type size mismatch"); +} + +void +gr_simple_flowgraph_detail::validate() +{ + for (gr_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { + std::vector used_ports; + int ninputs, noutputs; + + used_ports = calc_used_ports(p->first, true); // inputs + ninputs = used_ports.size(); + check_contiguity(p->second, used_ports, true); // inputs + + used_ports = calc_used_ports(p->first, false); // outputs + noutputs = used_ports.size(); + check_contiguity(p->second, used_ports, false); // outputs + + if (!(p->second->check_topology(ninputs, noutputs))) + throw std::runtime_error("check topology failed"); + } +} + +std::vector +gr_simple_flowgraph_detail::calc_used_ports(const std::string &name, bool check_inputs) +{ + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Calculating used " << (check_inputs ? "input " : "output ") + << "ports..."; + + std::vector tmp, result; + std::insert_iterator > inserter(result, result.begin()); + + gr_edge_vector_t edges = calc_connections(name, check_inputs); + + for (gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) { + if (check_inputs == true) + tmp.push_back((*p)->dst_port()); + else + tmp.push_back((*p)->src_port()); + } + + // remove duplicates + std::sort(tmp.begin(), tmp.end()); + std::unique_copy(tmp.begin(), tmp.end(), inserter); + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << result.size() << std::endl; + + return result; +} + +gr_edge_vector_t +gr_simple_flowgraph_detail::calc_connections(const std::string &name, bool check_inputs) +{ + gr_edge_vector_t result; + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + if (check_inputs) { + if ((*p)->dst_name() == name) + result.push_back(*p); + } + else { + if ((*p)->src_name() == name) + result.push_back(*p); + } + } + + return result; // assumes no duplicates +} + +void +gr_simple_flowgraph_detail::check_contiguity(gr_block_sptr block, + const std::vector &used_ports, + bool check_inputs) +{ + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Checking " << (check_inputs ? "input " : "output ") + << "contiguity..."; + + gr_io_signature_sptr sig = + check_inputs ? block->input_signature() : block->output_signature(); + + int nports = used_ports.size(); + int min_ports = sig->min_streams(); + + if (nports == 0) { + if (min_ports == 0) { + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "ok." << std::endl; + return; + } + else { + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "needs " << min_ports << ", only has " + << nports << std::endl; + + throw std::runtime_error("insufficient ports"); + } + } + + if (used_ports[nports-1]+1 != nports) { + for (int i = 0; i < nports; i++) { + if (used_ports[i] != i) { + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "missing " << (check_inputs ? "input ":"output ") + << i << std::endl; + + throw std::runtime_error("missing input assignment"); + } + } + } + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "ok." << std::endl; +} + +void +gr_simple_flowgraph_detail::setup_connections() +{ + // Assign block details to component blocks + for (gr_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Allocating output buffers for " << p->first << "..." << std::endl; + + int ninputs = calc_used_ports(p->first, true).size(); + int noutputs = calc_used_ports(p->first, false).size(); + gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); + for (int i = 0; i < noutputs; i++) + detail->set_output(i, allocate_buffer(p->first, i)); + p->second->set_detail(detail); + } + + // Connect inputs to outputs for each block + for(gr_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { + // Get its detail and edges that feed into it + gr_block_detail_sptr detail = p->second->detail(); + gr_edge_vector_t in_edges = calc_upstream_edges(p->first); + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + if (in_edges.size() > 0) + std::cout << "Connecting inputs to " << p->first << "..." << std::endl; + + // For each edge that feeds into it + for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) { + // Set the input buffer on the destination port to the output + // buffer on the source port + int dst_port = (*e)->dst_port(); + int src_port = (*e)->src_port(); + gr_block_sptr src_block = lookup_block((*e)->src_name()); + gr_buffer_sptr src_buffer = src_block->detail()->output(src_port); + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Setting input on " << (*e)->dst_name() + << ":" << dst_port << std::endl; + + detail->set_input(dst_port, gr_buffer_add_reader(src_buffer, p->second->history()-1)); + } + } +} + +gr_buffer_sptr +gr_simple_flowgraph_detail::allocate_buffer(const std::string &name, int port) +{ + gr_block_sptr block = lookup_block(name); + int item_size = block->output_signature()->sizeof_stream_item(port); + int nitems = s_fixed_buffer_size/item_size; + + // Make sure there are at least twice the output_multiple no. of items + if (nitems < 2*block->output_multiple()) // Note: this means output_multiple() + nitems = 2*block->output_multiple(); // can't be changed by block dynamically + + // If any downstream blocks are decimators and/or have a large output_multiple, + // ensure we have a buffer at least twice their decimation factor*output_multiple + gr_block_vector_t blocks = calc_downstream_blocks(name, port); + for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + int decimation = (int)(1.0/(*p)->relative_rate()); + int multiple = (*p)->output_multiple(); + int history = (*p)->history(); + nitems = std::max(nitems, 2*(decimation*multiple+history)); + } + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Allocating buffer for port " << port << " with " + << nitems << " items of size " << item_size << std::endl; + + return gr_make_buffer(nitems, item_size); +} + +gr_block_vector_t +gr_simple_flowgraph_detail::calc_downstream_blocks(const std::string &name, int port) +{ + gr_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if ((*p)->src_name() == name && (*p)->src_port() == port) + tmp.push_back(lookup_block((*p)->dst_name())); + + // Remove duplicates + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; +} + +gr_edge_vector_t +gr_simple_flowgraph_detail::calc_upstream_edges(const std::string &name) +{ + gr_edge_vector_t result; + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if ((*p)->dst_name() == name) + result.push_back(*p); + + return result; // Assume no duplicates +} + +gr_block_vector_t +gr_simple_flowgraph_detail::calc_used_blocks() +{ + std::vector tmp, tmp_unique; + std::insert_iterator > inserter(tmp_unique, tmp_unique.begin()); + gr_block_vector_t result; + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + tmp.push_back((*p)->src_name()); + tmp.push_back((*p)->dst_name()); + } + + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + + for (std::vector::iterator p = tmp_unique.begin(); + p != tmp_unique.end(); p++) + result.push_back(lookup_block(*p)); + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Flowgraph uses " << result.size() + << " distinct blocks." << std::endl; + + return result; +} + +std::vector +gr_simple_flowgraph_detail::partition() +{ + std::vector result; + gr_block_vector_t blocks = calc_used_blocks(); + gr_block_vector_t graph; + + while (blocks.size() > 0) { + graph = calc_reachable_blocks(blocks[0], blocks); + assert(graph.size()); + result.push_back(topological_sort(graph)); + + for (gr_block_viter_t p = graph.begin(); p != graph.end(); p++) + blocks.erase(find(blocks.begin(), blocks.end(), *p)); + } + + return result; +} + +gr_block_vector_t +gr_simple_flowgraph_detail::calc_reachable_blocks(gr_block_sptr block, gr_block_vector_t &blocks) +{ + gr_block_vector_t result; + + // Mark all blocks as unvisited + for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) + (*p)->detail()->set_color(gr_block_detail::WHITE); + + // Recursively mark all reachable blocks + reachable_dfs_visit(block, blocks); + + // Collect all the blocks that have been visited + for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) + if ((*p)->detail()->color() == gr_block_detail::BLACK) + result.push_back(*p); + + return result; +} + +// Recursively mark all reachable blocks from given block and block list +void +gr_simple_flowgraph_detail::reachable_dfs_visit(gr_block_sptr block, gr_block_vector_t &blocks) +{ + // Mark the current one as visited + block->detail()->set_color(gr_block_detail::BLACK); + + // Recurse into adjacent vertices + gr_block_vector_t adjacent = calc_adjacent_blocks(block, blocks); + + for (gr_block_viter_t p = adjacent.begin(); p != adjacent.end(); p++) + if ((*p)->detail()->color() == gr_block_detail::WHITE) + reachable_dfs_visit(*p, blocks); +} + +// Return a list of block adjacent to a given block along any edge +gr_block_vector_t +gr_simple_flowgraph_detail::calc_adjacent_blocks(gr_block_sptr block, gr_block_vector_t &blocks) +{ + gr_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); + + // Find any blocks that are inputs or outputs + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + if (lookup_block((*p)->src_name()) == block) + tmp.push_back(lookup_block((*p)->dst_name())); + if (lookup_block((*p)->dst_name()) == block) + tmp.push_back(lookup_block((*p)->src_name())); + } + + // Remove duplicates + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; +} + +gr_block_vector_t +gr_simple_flowgraph_detail::topological_sort(gr_block_vector_t &blocks) +{ + gr_block_vector_t result; + + // NOP for now + result = blocks; + + return result; +} + diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h new file mode 100644 index 000000000..368a0619f --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h @@ -0,0 +1,128 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_SIMPLE_FLOWGRAPH_DETAIL_H +#define INCLUDED_GR_SIMPLE_FLOWGRAPH_DETAIL_H + +#include +#include + +#define GR_FIXED_BUFFER_SIZE (32*(1L<<10)) + +typedef std::map gr_component_map_t; +typedef std::map::iterator gr_component_miter_t; + +class gr_endpoint +{ +private: + std::string d_name; + int d_port; + +public: + gr_endpoint(const std::string &name, int port) { d_name = name; d_port = port; } + const std::string &name() const { return d_name; } + int port() const { return d_port; } +}; + +class gr_edge; +typedef boost::shared_ptr gr_edge_sptr; +gr_edge_sptr gr_make_edge(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port); + +class gr_edge +{ +private: + friend gr_edge_sptr gr_make_edge(const std::string &src_name, int src_port, + const std::string &dst_name, int dst_port); + gr_edge(const std::string &name, int src_port, + const std::string &name, int dst_port); + + gr_endpoint d_src; + gr_endpoint d_dst; + +public: + ~gr_edge(); + const std::string src_name() const { return d_src.name(); } + const std::string dst_name() const { return d_dst.name(); } + int src_port() const { return d_src.port(); } + int dst_port() const { return d_dst.port(); } +}; + +typedef std::vector gr_edge_vector_t; +typedef std::vector::iterator gr_edge_viter_t; + +class gr_simple_flowgraph_detail +{ +private: + friend class gr_simple_flowgraph; + friend class gr_runtime_impl; + + gr_simple_flowgraph_detail(); + + gr_component_map_t d_components; + gr_edge_vector_t d_edges; + static const unsigned int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE; + + void reset(); + void define_component(const std::string &name, gr_block_sptr block); + void connect(const std::string &src, int src_port, + const std::string &dst, int dst_port); + gr_block_sptr lookup_block(const std::string &name); + void check_valid_port(gr_io_signature_sptr sig, int port); + void check_dst_not_used(const std::string &name, int port); + void check_type_match(gr_block_sptr src_block, int src_port, + gr_block_sptr dst_block, int dst_port); + void validate(); + gr_edge_vector_t calc_connections(const std::string &name, bool check_inputs); // false=use outputs + std::vector calc_used_ports(const std::string &name, bool check_inputs); + void check_contiguity(gr_block_sptr block, const std::vector &used_ports, + bool check_inputs); + void setup_connections(); + gr_buffer_sptr allocate_buffer(const std::string &name, int port); + gr_block_vector_t calc_downstream_blocks(const std::string &name, int port); + gr_edge_vector_t calc_upstream_edges(const std::string &name); + gr_block_vector_t calc_used_blocks(); + std::vector partition(); + gr_block_vector_t calc_reachable_blocks(gr_block_sptr block, gr_block_vector_t &blocks); + gr_block_vector_t topological_sort(gr_block_vector_t &blocks); + void reachable_dfs_visit(gr_block_sptr block, gr_block_vector_t &blocks); + gr_block_vector_t calc_adjacent_blocks(gr_block_sptr block, gr_block_vector_t &blocks); + +public: + ~gr_simple_flowgraph_detail(); +}; + +inline std::ostream& +operator <<(std::ostream& os, const gr_block_sptr p) +{ + os << "name() << " (" << p->unique_id() << ")>"; + return os; +} + +inline std::ostream& +operator <<(std::ostream &os, const gr_endpoint endp) +{ + os << endp.name() << ":" << endp.port(); + return os; +} + +#endif /* INCLUDED_GR_SIMPLE_FLOWGRAPH_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_block.cc index 4773a6eaa..630d72749 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.cc @@ -25,7 +25,6 @@ #endif #include #include -#include #include #include #include diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc new file mode 100644 index 000000000..766ea2f6b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc @@ -0,0 +1,46 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +void qa_gr_hier_block2::test_make() +{ + gr_hier_block2_sptr src1(gr_make_hier_block2("test", + gr_make_io_signature(1, 1, sizeof(int)), + gr_make_io_signature(1, 1, sizeof(int)))); + + CPPUNIT_ASSERT(src1); + CPPUNIT_ASSERT_EQUAL(std::string("test"), src1->name()); + CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->max_streams()); + CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->min_streams()); + CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->max_streams()); + CPPUNIT_ASSERT_EQUAL(sizeof(int), + src1->output_signature()->sizeof_stream_item(0)); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h new file mode 100644 index 000000000..a6bd8d97b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h @@ -0,0 +1,43 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_QA_GR_HIER_BLOCK2_H +#define INCLUDED_QA_GR_HIER_BLOCK2_H + +#include +#include +#include + +class qa_gr_hier_block2 : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_gr_hier_block2); + + CPPUNIT_TEST(test_make); + + CPPUNIT_TEST_SUITE_END(); + +private: + void test_make(); + void test_derived(); +}; + +#endif /* INCLUDED_QA_GR_HIER_BLOCK2_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 165a34703..ca0c71d3c 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -33,6 +33,7 @@ #include #include #include +#include #include CppUnit::TestSuite * @@ -43,6 +44,7 @@ qa_runtime::suite () s->addTest (qa_gr_vmcircbuf::suite ()); s->addTest (qa_gr_io_signature::suite ()); s->addTest (qa_gr_block::suite ()); + s->addTest (qa_gr_hier_block2::suite ()); s->addTest (qa_gr_buffer::suite ()); return s; diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index f2fd36437..8e6c01f9a 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -26,6 +26,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -37,9 +40,12 @@ %include %include +%include %include %include +%include %include +%include %include %include %include @@ -47,3 +53,4 @@ %include %include %include +%include -- cgit From 65ee33a8122bf23dad5721ff115e80ae7bb8e523 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 14 Dec 2006 16:28:36 +0000 Subject: Merged jcorgan/sfg changeset r4082 into trunk (fixes gr.runtime parameter typing issue) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4083 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_runtime.i | 13 +++++-------- gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.i b/gnuradio-core/src/lib/runtime/gr_runtime.i index 496adff37..2933c7187 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.i +++ b/gnuradio-core/src/lib/runtime/gr_runtime.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2006 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,7 +24,6 @@ class gr_runtime; typedef boost::shared_ptr gr_runtime_sptr; %template(gr_runtime_sptr) boost::shared_ptr; -%rename(runtime) gr_make_runtime; gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); class gr_runtime @@ -33,10 +32,8 @@ protected: gr_runtime(gr_hier_block2_sptr top_block); public: - void start() - throw (std::runtime_error); - void stop(); - void wait(); - void run() - throw (std::runtime_error); + void run() throw (std::runtime_error); + void start() throw (std::runtime_error); + void stop() throw (std::runtime_error); + void wait() throw (std::runtime_error); }; diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc index 2b104cd99..ffc897b8b 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -76,7 +76,7 @@ void gr_runtime_impl::stop() { if (!d_running) - return; + throw std::runtime_error("not running"); for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) -- cgit From 3ffcee6b999a5ec8a1e59c0a26cd8f3bc7725dfc Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 14 Dec 2006 23:37:20 +0000 Subject: Merge jcorgan/sfg changeset 4089 into trunk. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4090 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_runtime.i | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.i b/gnuradio-core/src/lib/runtime/gr_runtime.i index 2933c7187..3a8b7e0b6 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.i +++ b/gnuradio-core/src/lib/runtime/gr_runtime.i @@ -37,3 +37,39 @@ public: void stop() throw (std::runtime_error); void wait() throw (std::runtime_error); }; + +%{ +class ensure_py_gil_state2 { + PyGILState_STATE d_gstate; +public: + ensure_py_gil_state2() { d_gstate = PyGILState_Ensure(); } + ~ensure_py_gil_state2() { PyGILState_Release(d_gstate); } +}; +%} + +%inline %{ +void runtime_run_unlocked(gr_runtime_sptr r) throw (std::runtime_error) +{ + ensure_py_gil_state2 _lock; + r->run(); +} + +void runtime_start_unlocked(gr_runtime_sptr r) throw (std::runtime_error) +{ + ensure_py_gil_state2 _lock; + r->start(); +} + +void runtime_stop_unlocked(gr_runtime_sptr r) throw (std::runtime_error) +{ + ensure_py_gil_state2 _lock; + r->stop(); +} + +void runtime_wait_unlocked(gr_runtime_sptr r) throw (std::runtime_error) +{ + ensure_py_gil_state2 _lock; + r->wait(); +} + +%} -- cgit From a7e596eb3785b37cf0034b457187cc52d44c6bfd Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 16 Dec 2006 07:26:48 +0000 Subject: Merged jcorgan/sfg changeset r4048 into trunk. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4098 221aa14e-8319-0410-a670-987f0aec2ac5 --- .../src/lib/runtime/gr_simple_flowgraph_detail.cc | 120 ++++++++++++++++++++- .../src/lib/runtime/gr_simple_flowgraph_detail.h | 8 ++ 2 files changed, 125 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc index 2698bc6d8..36dc0bc40 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc @@ -79,6 +79,17 @@ gr_simple_flowgraph_detail::lookup_block(const std::string &name) return gr_block_sptr(); } +std::string +gr_simple_flowgraph_detail::lookup_name(gr_block_sptr block) +{ + for (gr_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { + if (p->second == block) + return p->first; + } + + return std::string(""); // Not found +} + void gr_simple_flowgraph_detail::define_component(const std::string &name, gr_block_sptr block) { @@ -345,6 +356,22 @@ gr_simple_flowgraph_detail::calc_downstream_blocks(const std::string &name, int return result; } +gr_block_vector_t +gr_simple_flowgraph_detail::calc_downstream_blocks(const std::string &name) +{ + gr_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if ((*p)->src_name() == name) + tmp.push_back(lookup_block((*p)->dst_name())); + + // Remove duplicates + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; +} + gr_edge_vector_t gr_simple_flowgraph_detail::calc_upstream_edges(const std::string &name) { @@ -458,14 +485,101 @@ gr_simple_flowgraph_detail::calc_adjacent_blocks(gr_block_sptr block, gr_block_v return result; } +void +gr_simple_flowgraph_detail::dump_block_vector(gr_block_vector_t blocks) +{ + for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + std::cout << (*p) << std::endl; + } +} + gr_block_vector_t gr_simple_flowgraph_detail::topological_sort(gr_block_vector_t &blocks) { - gr_block_vector_t result; + gr_block_vector_t result, tmp; + std::cout << "Before source sort: " << std::endl; + dump_block_vector(blocks); + std::cout << std::endl; + + tmp = sort_sources_first(blocks); + + std::cout << "After source sort: " << std::endl; + dump_block_vector(tmp); + std::cout << std::endl; + + // Start 'em all white + for (gr_block_viter_t p = tmp.begin(); p != tmp.end(); p++) + (*p)->detail()->set_color(gr_block_detail::WHITE); + + for (gr_block_viter_t p = tmp.begin(); p != tmp.end(); p++) { + if ((*p)->detail()->color() == gr_block_detail::WHITE) + topological_dfs_visit(*p, result); + } + + reverse(result.begin(), result.end()); + + std::cout << "After dfs: " << std::endl; + dump_block_vector(result); + std::cout << std::endl; + + return result; +} + +bool +gr_simple_flowgraph_detail::source_p(gr_block_sptr block) +{ + return (calc_upstream_edges(lookup_name(block)).size() == 0); +} + +gr_block_vector_t +gr_simple_flowgraph_detail::sort_sources_first(gr_block_vector_t &blocks) +{ + gr_block_vector_t sources, nonsources, result; + + for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + if (source_p(*p)) + sources.push_back(*p); + else + nonsources.push_back(*p); + } + + for (gr_block_viter_t p = sources.begin(); p != sources.end(); p++) + result.push_back(*p); - // NOP for now - result = blocks; + for (gr_block_viter_t p = nonsources.begin(); p != nonsources.end(); p++) + result.push_back(*p); return result; } +void +gr_simple_flowgraph_detail::topological_dfs_visit(gr_block_sptr block, gr_block_vector_t &output) +{ + block->detail()->set_color(gr_block_detail::GREY); + + gr_block_vector_t ds_blocks = calc_downstream_blocks(lookup_name(block)); + std::cout << "Downstream blocks of " << block << ":" << std::endl; + dump_block_vector(ds_blocks); + + gr_block_vector_t blocks(ds_blocks); + for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + switch ((*p)->detail()->color()) { + case gr_block_detail::WHITE: // (u, v) is a tree edge + topological_dfs_visit(*p, output); + break; + + case gr_block_detail::GREY: // (u, v) is a back edge - not a DAG + throw std::runtime_error("flow graph has loops!"); + + case gr_block_detail::BLACK: + continue; + + default: + throw std::runtime_error("invalid color on block!"); + } + + } + + block->detail()->set_color(gr_block_detail::BLACK); + output.push_back(block); +} diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h index 368a0619f..d4812b615 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h @@ -75,6 +75,7 @@ class gr_simple_flowgraph_detail private: friend class gr_simple_flowgraph; friend class gr_runtime_impl; + friend class topo_block_cmp; gr_simple_flowgraph_detail(); @@ -87,6 +88,8 @@ private: void connect(const std::string &src, int src_port, const std::string &dst, int dst_port); gr_block_sptr lookup_block(const std::string &name); + std::string lookup_name(const gr_block_sptr block); + void check_valid_port(gr_io_signature_sptr sig, int port); void check_dst_not_used(const std::string &name, int port); void check_type_match(gr_block_sptr src_block, int src_port, @@ -99,6 +102,7 @@ private: void setup_connections(); gr_buffer_sptr allocate_buffer(const std::string &name, int port); gr_block_vector_t calc_downstream_blocks(const std::string &name, int port); + gr_block_vector_t calc_downstream_blocks(const std::string &name); gr_edge_vector_t calc_upstream_edges(const std::string &name); gr_block_vector_t calc_used_blocks(); std::vector partition(); @@ -106,6 +110,10 @@ private: gr_block_vector_t topological_sort(gr_block_vector_t &blocks); void reachable_dfs_visit(gr_block_sptr block, gr_block_vector_t &blocks); gr_block_vector_t calc_adjacent_blocks(gr_block_sptr block, gr_block_vector_t &blocks); + bool source_p(gr_block_sptr block); + gr_block_vector_t sort_sources_first(gr_block_vector_t &blocks); + void topological_dfs_visit(gr_block_sptr block, gr_block_vector_t &output); + void dump_block_vector(gr_block_vector_t blocks); public: ~gr_simple_flowgraph_detail(); -- cgit From 95144e53f0285d9e5ea897348030a33c18773b60 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 18 Dec 2006 04:35:19 +0000 Subject: Merged jcorgan/sfg r4097:4124 into trunk, fixing hier_block2 threading issues. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4126 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_runtime.cc | 24 ++++++++++- gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 47 ++++++++++++---------- gnuradio-core/src/lib/runtime/gr_runtime_impl.h | 13 +++--- .../src/lib/runtime/gr_simple_flowgraph_detail.cc | 38 ++++------------- .../src/lib/runtime/gr_simple_flowgraph_detail.h | 1 - 5 files changed, 59 insertions(+), 64 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.cc b/gnuradio-core/src/lib/runtime/gr_runtime.cc index 926e87857..93f78fea8 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime.cc @@ -26,8 +26,11 @@ #include #include +#include #include +static gr_runtime *s_runtime = 0; + gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block) { @@ -37,16 +40,29 @@ gr_make_runtime(gr_hier_block2_sptr top_block) gr_runtime::gr_runtime(gr_hier_block2_sptr top_block) { d_impl = new gr_runtime_impl(top_block); + s_runtime = this; } gr_runtime::~gr_runtime() { + s_runtime = 0; // we don't own this delete d_impl; } +// HACK: This prevents using more than one gr_runtime instance +static void +runtime_sigint_handler(int signum) +{ + + if (s_runtime) + s_runtime->stop(); +} + void gr_runtime::start() { + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); + d_impl->start(); } @@ -59,12 +75,16 @@ gr_runtime::stop() void gr_runtime::wait() { + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); + d_impl->wait(); } void gr_runtime::run() { - start(); - wait(); + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); + + d_impl->start(); + d_impl->wait(); } diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc index ffc897b8b..dcd904a01 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -30,14 +30,14 @@ #include #include #include +#include #include #include -gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) : -d_running(false), -d_top_block(top_block), -d_sfg(gr_make_simple_flowgraph()), -d_graphs() +gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) + : d_running(false), + d_top_block(top_block), + d_sfg(gr_make_simple_flowgraph()) { } @@ -66,7 +66,7 @@ gr_runtime_impl::start() d_threads.clear(); for (std::vector::iterator p = d_graphs.begin(); p != d_graphs.end(); p++) { - gr_scheduler_thread_sptr thread = gr_make_scheduler_thread(*p); + gr_scheduler_thread *thread = new gr_scheduler_thread(*p); thread->start(); d_threads.push_back(thread); } @@ -78,9 +78,8 @@ gr_runtime_impl::stop() if (!d_running) throw std::runtime_error("not running"); - for (gr_scheduler_thread_viter_t p = d_threads.begin(); - p != d_threads.end(); p++) - (*p)->stop(); + for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) + (*p)->stop(); d_running = false; } @@ -88,19 +87,12 @@ gr_runtime_impl::stop() void gr_runtime_impl::wait() { - for (gr_scheduler_thread_viter_t p = d_threads.begin(); - p != d_threads.end(); p++) { - while(1) { - (*p)->join(NULL); - if (!(*p)->state() == omni_thread::STATE_TERMINATED) - break; - } - } -} + void *dummy_status; // don't ever dereference this -gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph) -{ - return gr_scheduler_thread_sptr(new gr_scheduler_thread(graph)); + for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { + (*p)->join(&dummy_status); // pthreads will self-delete, so pointer is now dead + (*p) = 0; // FIXME: switch to stl::list and actually remove from container + } } gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) : @@ -118,8 +110,19 @@ void gr_scheduler_thread::start() start_undetached(); } -void *gr_scheduler_thread::run_undetached(void *arg) +void * +gr_scheduler_thread::run_undetached(void *arg) { + // First code to run in new thread context + + // Mask off SIGINT in this thread to gaurantee mainline thread gets signal + sigset_t old_set; + sigset_t new_set; + sigfillset(&new_set); + sigdelset(&new_set, SIGINT); + sigprocmask(SIG_BLOCK, &new_set, &old_set); + + // Run the single-threaded scheduler d_sts->run(); return 0; } diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h index 54977ef97..e69446719 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h @@ -28,23 +28,20 @@ #include #include +// omnithread calls delete on itself after thread exits, so can't use shared ptr class gr_scheduler_thread; -typedef boost::shared_ptr gr_scheduler_thread_sptr; -typedef std::vector gr_scheduler_thread_vector_t; -typedef std::vector::iterator gr_scheduler_thread_viter_t; - -gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph); +typedef std::vector gr_scheduler_thread_vector_t; +typedef gr_scheduler_thread_vector_t::iterator gr_scheduler_thread_viter_t; class gr_scheduler_thread : public omni_thread { private: - gr_scheduler_thread(gr_block_vector_t graph); - friend gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph); - gr_single_threaded_scheduler_sptr d_sts; public: + gr_scheduler_thread(gr_block_vector_t graph); ~gr_scheduler_thread(); + virtual void *run_undetached(void *arg); void start(); void stop(); diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc index 36dc0bc40..0c9c9b707 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc @@ -110,8 +110,8 @@ gr_simple_flowgraph_detail::connect(const std::string &src_name, int src_port, gr_block_sptr dst_block = lookup_block(dst_name); if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Connecting " << src_name << ":" << src_port << "->" - << dst_name << ":" << dst_port << std::endl; + std::cout << "Connecting " << src_name << ":" << src_port << "->" + << dst_name << ":" << dst_port << std::endl; if (!src_block) throw std::invalid_argument("unknown src name"); @@ -291,8 +291,8 @@ gr_simple_flowgraph_detail::setup_connections() gr_edge_vector_t in_edges = calc_upstream_edges(p->first); if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - if (in_edges.size() > 0) - std::cout << "Connecting inputs to " << p->first << "..." << std::endl; + if (in_edges.size() > 0) + std::cout << "Connecting inputs to " << p->first << "..." << std::endl; // For each edge that feeds into it for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) { @@ -485,28 +485,12 @@ gr_simple_flowgraph_detail::calc_adjacent_blocks(gr_block_sptr block, gr_block_v return result; } -void -gr_simple_flowgraph_detail::dump_block_vector(gr_block_vector_t blocks) -{ - for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - std::cout << (*p) << std::endl; - } -} - gr_block_vector_t gr_simple_flowgraph_detail::topological_sort(gr_block_vector_t &blocks) { gr_block_vector_t result, tmp; - std::cout << "Before source sort: " << std::endl; - dump_block_vector(blocks); - std::cout << std::endl; - tmp = sort_sources_first(blocks); - std::cout << "After source sort: " << std::endl; - dump_block_vector(tmp); - std::cout << std::endl; - // Start 'em all white for (gr_block_viter_t p = tmp.begin(); p != tmp.end(); p++) (*p)->detail()->set_color(gr_block_detail::WHITE); @@ -518,10 +502,6 @@ gr_simple_flowgraph_detail::topological_sort(gr_block_vector_t &blocks) reverse(result.begin(), result.end()); - std::cout << "After dfs: " << std::endl; - dump_block_vector(result); - std::cout << std::endl; - return result; } @@ -557,18 +537,15 @@ gr_simple_flowgraph_detail::topological_dfs_visit(gr_block_sptr block, gr_block_ { block->detail()->set_color(gr_block_detail::GREY); - gr_block_vector_t ds_blocks = calc_downstream_blocks(lookup_name(block)); - std::cout << "Downstream blocks of " << block << ":" << std::endl; - dump_block_vector(ds_blocks); + gr_block_vector_t blocks(calc_downstream_blocks(lookup_name(block))); - gr_block_vector_t blocks(ds_blocks); for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { switch ((*p)->detail()->color()) { - case gr_block_detail::WHITE: // (u, v) is a tree edge + case gr_block_detail::WHITE: topological_dfs_visit(*p, output); break; - case gr_block_detail::GREY: // (u, v) is a back edge - not a DAG + case gr_block_detail::GREY: throw std::runtime_error("flow graph has loops!"); case gr_block_detail::BLACK: @@ -577,7 +554,6 @@ gr_simple_flowgraph_detail::topological_dfs_visit(gr_block_sptr block, gr_block_ default: throw std::runtime_error("invalid color on block!"); } - } block->detail()->set_color(gr_block_detail::BLACK); diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h index d4812b615..2df1575ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h @@ -113,7 +113,6 @@ private: bool source_p(gr_block_sptr block); gr_block_vector_t sort_sources_first(gr_block_vector_t &blocks); void topological_dfs_visit(gr_block_sptr block, gr_block_vector_t &output); - void dump_block_vector(gr_block_vector_t blocks); public: ~gr_simple_flowgraph_detail(); -- cgit From 424a1b454020727163cbbb0b19e8ea2f0833ef85 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 18 Dec 2006 05:39:40 +0000 Subject: Cleanup on hierarchical flowgraph code. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4133 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_local_sighandler.h | 3 +++ gnuradio-core/src/lib/runtime/gr_runtime.cc | 2 +- gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 15 ++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h index 08e8edf00..011b0853a 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h @@ -23,7 +23,10 @@ #ifndef INCLUDED_GR_LOCAL_SIGHANDLER_H #define INCLUDED_GR_LOCAL_SIGHANDLER_H +#ifdef HAVE_SIGNAL_H #include +#endif + #include /*! diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.cc b/gnuradio-core/src/lib/runtime/gr_runtime.cc index 93f78fea8..aab8ea5ab 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime.cc @@ -49,7 +49,7 @@ gr_runtime::~gr_runtime() delete d_impl; } -// HACK: This prevents using more than one gr_runtime instance +// FIXME: This prevents using more than one gr_runtime instance static void runtime_sigint_handler(int signum) { diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc index dcd904a01..f8d65261e 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -24,16 +24,20 @@ #include "config.h" #endif -#define GR_RUNTIME_IMPL_DEBUG 0 - #include #include #include #include + +#ifdef HAVE_SIGNAL_H #include +#endif + #include #include +#define GR_RUNTIME_IMPL_DEBUG 0 + gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) : d_running(false), d_top_block(top_block), @@ -116,12 +120,13 @@ gr_scheduler_thread::run_undetached(void *arg) // First code to run in new thread context // Mask off SIGINT in this thread to gaurantee mainline thread gets signal +#ifdef HAVE_SIGPROCMASK sigset_t old_set; sigset_t new_set; - sigfillset(&new_set); - sigdelset(&new_set, SIGINT); + sigemptyset(&new_set); + sigaddset(&new_set, SIGINT); sigprocmask(SIG_BLOCK, &new_set, &old_set); - +#endif // Run the single-threaded scheduler d_sts->run(); return 0; -- cgit From cbe1628f2eb1a1a3c8b0b96a3b1334a039074def Mon Sep 17 00:00:00 2001 From: eb Date: Sat, 13 Jan 2007 04:14:56 +0000 Subject: SWIG compilation speedup! Fixes ticket:9. Merged -r4203:4254 from eb/swig-split into trunk. This refactors gnuradio_swig_python.{cc,py} into 5 separate .so's These correspond to the runtime, general, filter and io directories, and also includes a new directory, gengen. gengen contains that part of general that was machine generated. This split is arbitrary, but was useful for getting size of the swig generated glue code for general down to about 2MB. In addition, the swig glue is now compiled with -g1 -O1 instead of -g -O2. With this change all the swig code now compiles in about 60% of the time that it used to take. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4255 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 9 +++ gnuradio-core/src/lib/runtime/gr_sync_block.cc | 68 +++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_sync_block.h | 65 ++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_sync_block.i | 29 +++++++++ gnuradio-core/src/lib/runtime/gr_sync_decimator.cc | 69 +++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 68 +++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_sync_decimator.i | 31 ++++++++++ .../src/lib/runtime/gr_sync_interpolator.cc | 70 ++++++++++++++++++++++ .../src/lib/runtime/gr_sync_interpolator.h | 68 +++++++++++++++++++++ .../src/lib/runtime/gr_sync_interpolator.i | 31 ++++++++++ gnuradio-core/src/lib/runtime/runtime.i | 6 ++ 11 files changed, 514 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/gr_sync_block.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_sync_block.h create mode 100644 gnuradio-core/src/lib/runtime/gr_sync_block.i create mode 100644 gnuradio-core/src/lib/runtime/gr_sync_decimator.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_sync_decimator.h create mode 100644 gnuradio-core/src/lib/runtime/gr_sync_decimator.i create mode 100644 gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_sync_interpolator.h create mode 100644 gnuradio-core/src/lib/runtime/gr_sync_interpolator.i (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 47ae07a6b..91d3c144b 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -51,6 +51,9 @@ libruntime_la_SOURCES = \ gr_runtime.cc \ gr_runtime_impl.cc \ gr_single_threaded_scheduler.cc \ + gr_sync_block.cc \ + gr_sync_decimator.cc \ + gr_sync_interpolator.cc \ gr_tmp_path.cc \ gr_vmcircbuf.cc \ gr_vmcircbuf_mmap_shm_open.cc \ @@ -92,6 +95,9 @@ grinclude_HEADERS = \ gr_runtime_types.h \ gr_select_handler.h \ gr_single_threaded_scheduler.h \ + gr_sync_block.h \ + gr_sync_decimator.h \ + gr_sync_interpolator.h \ gr_timer.h \ gr_tmp_path.h \ gr_types.h \ @@ -125,5 +131,8 @@ swiginclude_HEADERS = \ gr_runtime.i \ gr_simple_flowgraph.i \ gr_single_threaded_scheduler.i \ + gr_sync_block.i \ + gr_sync_decimator.i \ + gr_sync_interpolator.i \ gr_swig_block_magic.i \ runtime.i diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.cc b/gnuradio-core/src/lib/runtime/gr_sync_block.cc new file mode 100644 index 000000000..ac2e90b63 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.cc @@ -0,0 +1,68 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +gr_sync_block::gr_sync_block (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature) + : gr_block(name, input_signature, output_signature) +{ + set_fixed_rate(true); +} + + +void +gr_sync_block::forecast (int noutput_items, gr_vector_int &ninput_items_required) +{ + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = fixed_rate_noutput_to_ninput (noutput_items); +} + +int +gr_sync_block::fixed_rate_noutput_to_ninput(int noutput_items) +{ + return noutput_items + history() - 1; +} + +int +gr_sync_block::fixed_rate_ninput_to_noutput(int ninput_items) +{ + return std::max(0, ninput_items - (int)history() + 1); +} + +int +gr_sync_block::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + int r = work (noutput_items, input_items, output_items); + if (r > 0) + consume_each (r); + return r; +} diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h new file mode 100644 index 000000000..7607cd190 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_SYNC_BLOCK_H +#define INCLUDED_GR_SYNC_BLOCK_H + +#include + +/*! + * \brief synchronous 1:1 input to output with history + * \ingroup block + * + * Override work to provide the signal processing implementation. + */ +class gr_sync_block : public gr_block +{ + protected: + + gr_sync_block (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + + public: + + /*! + * \brief just like gr_block::general_work, only this arranges to call consume_each for you + * + * The user must override work to define the signal processing code + */ + virtual int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) = 0; + + + // gr_sync_block overrides these to assist work + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + int fixed_rate_ninput_to_noutput(int ninput); + int fixed_rate_noutput_to_ninput(int noutput); +}; + +#endif /* INCLUDED_GR_SYNC_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.i b/gnuradio-core/src/lib/runtime/gr_sync_block.i new file mode 100644 index 000000000..2bfcd2b7d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.i @@ -0,0 +1,29 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +class gr_sync_block : public gr_block +{ + protected: + + gr_sync_block (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); +}; diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc new file mode 100644 index 000000000..1526cf8fc --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +gr_sync_decimator::gr_sync_decimator (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + unsigned decimation) + : gr_sync_block (name, input_signature, output_signature) +{ + set_decimation (decimation); +} + +void +gr_sync_decimator::forecast (int noutput_items, gr_vector_int &ninput_items_required) +{ + unsigned ninputs = ninput_items_required.size (); + for (unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = fixed_rate_noutput_to_ninput(noutput_items); +} + +int +gr_sync_decimator::fixed_rate_noutput_to_ninput(int noutput_items) +{ + return noutput_items * decimation() + history() - 1; +} + +int +gr_sync_decimator::fixed_rate_ninput_to_noutput(int ninput_items) +{ + return std::max(0, ninput_items - (int)history() + 1) / decimation(); +} + +int +gr_sync_decimator::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + int r = work (noutput_items, input_items, output_items); + if (r > 0) + consume_each (r * decimation ()); + return r; +} + diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h new file mode 100644 index 000000000..d6ee14deb --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -0,0 +1,68 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_SYNC_DECIMATOR_H +#define INCLUDED_GR_SYNC_DECIMATOR_H + +#include + +/*! + * \brief synchronous N:1 input to output with history + * \ingroup block + * + * Override work to provide the signal processing implementation. + */ +class gr_sync_decimator : public gr_sync_block +{ + private: + unsigned d_decimation; + + protected: + + gr_sync_decimator (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + unsigned decimation); + public: + + unsigned decimation () const { return d_decimation; } + void set_decimation (unsigned decimation) + { + d_decimation = decimation; + set_relative_rate (1.0 / decimation); + } + + // gr_sync_decimator overrides these to assist work + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + // derived classes should override work + + int fixed_rate_ninput_to_noutput(int ninput); + int fixed_rate_noutput_to_ninput(int noutput); +}; + + +#endif /* INCLUDED_GR_SYNC_DECIMATOR_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.i b/gnuradio-core/src/lib/runtime/gr_sync_decimator.i new file mode 100644 index 000000000..167e843a6 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.i @@ -0,0 +1,31 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +class gr_sync_decimator : public gr_sync_block +{ + protected: + + gr_sync_decimator (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + unsigned decimation); +}; diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc new file mode 100644 index 000000000..0a88cc7cd --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +gr_sync_interpolator::gr_sync_interpolator (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + unsigned interpolation) + : gr_sync_block (name, input_signature, output_signature) +{ + set_interpolation (interpolation); +} + +void +gr_sync_interpolator::forecast (int noutput_items, gr_vector_int &ninput_items_required) +{ + unsigned ninputs = ninput_items_required.size (); + for (unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = fixed_rate_noutput_to_ninput(noutput_items); +} + +int +gr_sync_interpolator::fixed_rate_noutput_to_ninput(int noutput_items) +{ + return noutput_items / interpolation() + history() - 1; +} + +int +gr_sync_interpolator::fixed_rate_ninput_to_noutout(int ninput_items) +{ + return std::max(0, ninput_items - (int)history() + 1) * interpolation(); +} + +int +gr_sync_interpolator::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + int r = work (noutput_items, input_items, output_items); + if (r > 0) + consume_each (r / interpolation ()); + return r; +} + + diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h new file mode 100644 index 000000000..5151b7f92 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -0,0 +1,68 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_SYNC_INTERPOLATOR_H +#define INCLUDED_GR_SYNC_INTERPOLATOR_H + +#include + +/*! + * \brief synchronous 1:N input to output with history + * \ingroup block + * + * Override work to provide the signal processing implementation. + */ +class gr_sync_interpolator : public gr_sync_block +{ + private: + unsigned d_interpolation; + + protected: + gr_sync_interpolator (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + unsigned interpolation); + public: + + unsigned interpolation () const { return d_interpolation; } + void set_interpolation (unsigned interpolation) + { + d_interpolation = interpolation; + set_relative_rate (1.0 * interpolation); + set_output_multiple (interpolation); + } + + // gr_sync_interpolator overrides these to assist work + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + // derived classes should override work + + int fixed_rate_ninput_to_noutout(int ninput); + int fixed_rate_noutput_to_ninput(int noutput); +}; + + +#endif /* INCLUDED_GR_SYNC_INTERPOLATOR_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i new file mode 100644 index 000000000..5c42dfdd2 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i @@ -0,0 +1,31 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +class gr_sync_interpolator : public gr_sync_block +{ + protected: + + gr_sync_interpolator (const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + unsigned interpolation); +}; diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 8e6c01f9a..cab338630 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -36,6 +36,9 @@ #include #include #include +#include +#include +#include %} %include @@ -54,3 +57,6 @@ %include %include %include +%include +%include +%include -- cgit From 106af0e251ec0cb1237f5bcc4814d79c76048819 Mon Sep 17 00:00:00 2001 From: gdt Date: Wed, 31 Jan 2007 18:10:53 +0000 Subject: free schmid_guard on error paths where it has been allocated and not freed. Fixes shm leak on NetBSD which hits the error case for unknown reasons. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4346 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc index fe0322f73..ccb169b95 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc @@ -68,11 +68,13 @@ gr_vmcircbuf_sysv_shm::gr_vmcircbuf_sysv_shm (int size) if ((shmid2 = shmget (IPC_PRIVATE, 2 * size + 2 * pagesize, IPC_CREAT | 0700)) == -1){ perror ("gr_vmcircbuf_sysv_shm: shmget (1)"); + shmctl (shmid_guard, IPC_RMID, 0); throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); } if ((shmid1 = shmget (IPC_PRIVATE, size, IPC_CREAT | 0700)) == -1){ perror ("gr_vmcircbuf_sysv_shm: shmget (2)"); + shmctl (shmid_guard, IPC_RMID, 0); shmctl (shmid2, IPC_RMID, 0); throw std::runtime_error ("gr_vmcircbuf_sysv_shm"); } -- cgit From 8097ab89e6e26c08e6ed9bd57502f7fbb1385299 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 20 Feb 2007 20:49:54 +0000 Subject: Merged eb/iosig r4533:4539 into trunk. This adds support for io_signatures with heterogeneous stream element sizes. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4541 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_io_signature.cc | 80 +++++++++++++++--- gnuradio-core/src/lib/runtime/gr_io_signature.h | 95 ++++++++++++++++------ gnuradio-core/src/lib/runtime/gr_io_signature.i | 42 ++++++++-- gnuradio-core/src/lib/runtime/qa_gr_block.cc | 8 +- gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc | 2 +- .../src/lib/runtime/qa_gr_io_signature.cc | 13 ++- gnuradio-core/src/lib/runtime/qa_gr_io_signature.h | 1 - 7 files changed, 190 insertions(+), 51 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.cc b/gnuradio-core/src/lib/runtime/gr_io_signature.cc index 51ab9286c..ace27314e 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,28 +27,86 @@ #include #include -gr_io_signature::gr_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item) +gr_io_signature_sptr +gr_make_io_signaturev(int min_streams, int max_streams, + const std::vector &sizeof_stream_items) +{ + return gr_io_signature_sptr (new gr_io_signature (min_streams, max_streams, + sizeof_stream_items)); +} + +gr_io_signature_sptr +gr_make_io_signature(int min_streams, int max_streams, + int sizeof_stream_item) +{ + std::vector sizeof_items(1); + sizeof_items[0] = sizeof_stream_item; + return gr_make_io_signaturev(min_streams, max_streams, sizeof_items); +} + +gr_io_signature_sptr +gr_make_io_signature2(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2) +{ + std::vector sizeof_items(2); + sizeof_items[0] = sizeof_stream_item1; + sizeof_items[1] = sizeof_stream_item2; + return gr_make_io_signaturev(min_streams, max_streams, sizeof_items); +} + +gr_io_signature_sptr +gr_make_io_signature3(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2, + int sizeof_stream_item3) +{ + std::vector sizeof_items(3); + sizeof_items[0] = sizeof_stream_item1; + sizeof_items[1] = sizeof_stream_item2; + sizeof_items[2] = sizeof_stream_item3; + return gr_make_io_signaturev(min_streams, max_streams, sizeof_items); +} + +// ------------------------------------------------------------------------ + + +gr_io_signature::gr_io_signature (int min_streams, int max_streams, + const std::vector &sizeof_stream_items) { if (min_streams < 0 || (max_streams != IO_INFINITE && max_streams < min_streams)) - throw std::invalid_argument ("gr_io_signature"); + throw std::invalid_argument ("gr_io_signature(1)"); + if (sizeof_stream_items.size() < 1) + throw std::invalid_argument("gr_io_signature(2)"); + + for (size_t i = 0; i < sizeof_stream_items.size(); i++){ + if (max_streams != 0 && sizeof_stream_items[i] < 1) + throw std::invalid_argument("gr_io_signature(3)"); + } + d_min_streams = min_streams; d_max_streams = max_streams; - d_sizeof_stream_item = sizeof_stream_item; + d_sizeof_stream_item = sizeof_stream_items; } gr_io_signature::~gr_io_signature () { - // NOP for now - // std::cout << "destroying gr_io_signature: " << this << '\n'; } -gr_io_signature_sptr -gr_make_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item) +int +gr_io_signature::sizeof_stream_item (int _index) const { - return gr_io_signature_sptr (new gr_io_signature (min_streams, max_streams, - sizeof_stream_item)); + if (_index < 0) + throw std::invalid_argument ("gr_io_signature::sizeof_stream_item"); + + size_t index = _index; + return d_sizeof_stream_item[std::min(index, d_sizeof_stream_item.size() - 1)]; } - +std::vector +gr_io_signature::sizeof_stream_items() const +{ + return d_sizeof_stream_item; +} diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index e5e009781..d33a1cf34 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,13 +26,78 @@ #include /*! - * \brief i/o signature for input and output ports. + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item specify the size of the items in each stream + */ +gr_io_signature_sptr +gr_make_io_signature(int min_streams, int max_streams, + int sizeof_stream_item); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item1 specify the size of the items in the first stream + * \param sizeof_stream_item2 specify the size of the items in the second and subsequent streams + */ +gr_io_signature_sptr +gr_make_io_signature2(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2 + ); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item1 specify the size of the items in the first stream + * \param sizeof_stream_item2 specify the size of the items in the second stream + * \param sizeof_stream_item3 specify the size of the items in the third and subsequent streams + */ +gr_io_signature_sptr +gr_make_io_signature3(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2, + int sizeof_stream_item3 + ); + +/*! + * \brief Create an i/o signature * - * For now, we restrict all streams to be the same type. - * We can fix this later. + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_items specify the size of the items in the streams + * + * If there are more streams than there are entries in sizeof_stream_items, the + * value of the last entry in sizeof_stream_items is used for the missing values. + * sizeof_stream_items must contain at least 1 entry. + */ +gr_io_signature_sptr +gr_make_io_signaturev(int min_streams, int max_streams, + const std::vector &sizeof_stream_items); + + +/*! + * \brief i/o signature for input and output ports. */ - class gr_io_signature { + int d_min_streams; + int d_max_streams; + std::vector d_sizeof_stream_item; + + gr_io_signature(int min_streams, int max_streams, + const std::vector &sizeof_stream_items); + + friend gr_io_signature_sptr + gr_make_io_signaturev(int min_streams, + int max_streams, + const std::vector &sizeof_stream_item); + public: static const int IO_INFINITE = -1; @@ -41,25 +106,9 @@ class gr_io_signature { int min_streams () const { return d_min_streams; } int max_streams () const { return d_max_streams; } - size_t sizeof_stream_item (int index) const { return d_sizeof_stream_item; } - - // ---------------------------------------------------------------------------- - - private: - - int d_min_streams; - int d_max_streams; - size_t d_sizeof_stream_item; - - gr_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item); - - friend gr_io_signature_sptr gr_make_io_signature (int min_streams, - int max_streams, - size_t sizeof_stream_item); + int sizeof_stream_item (int index) const; + std::vector sizeof_stream_items() const; }; -gr_io_signature_sptr -gr_make_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item); - #endif /* INCLUDED_IO_SIGNATURE_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.i b/gnuradio-core/src/lib/runtime/gr_io_signature.i index ca5ee215e..ef79cd2fb 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.i +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2005 Free Software Foundation, Inc. + * Copyright 2004,2005,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,14 +24,40 @@ class gr_io_signature; typedef boost::shared_ptr gr_io_signature_sptr; %template(gr_io_signature_sptr) boost::shared_ptr; -%rename(io_signature) gr_make_io_signature; +%rename(io_signature) gr_make_io_signature; +%rename(io_signature2) gr_make_io_signature2; +%rename(io_signature3) gr_make_io_signature3; +%rename(io_signaturev) gr_make_io_signaturev; + +gr_io_signature_sptr +gr_make_io_signature(int min_streams, int max_streams, + int sizeof_stream_item); + +gr_io_signature_sptr +gr_make_io_signature2(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2 + ); +gr_io_signature_sptr +gr_make_io_signature3(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2, + int sizeof_stream_item3 + ); gr_io_signature_sptr -gr_make_io_signature (int min_streams, - int max_streams, - size_t sizeof_stream_item); +gr_make_io_signaturev(int min_streams, int max_streams, + const std::vector &sizeof_stream_items); + class gr_io_signature { + gr_io_signature (int min_streams, int max_streams, int sizeof_stream_item); + + friend gr_io_signature_sptr + gr_make_io_signaturev(int min_streams, + int max_streams, + const std::vector &sizeof_stream_item); + public: // disabled. Suspected bug in SWIG 1.3.24 @@ -41,9 +67,7 @@ class gr_io_signature { int min_streams () const { return d_min_streams; } int max_streams () const { return d_max_streams; } - size_t sizeof_stream_item (int index) const { return d_sizeof_stream_item; } - - private: - gr_io_signature (int min_streams, int max_streams, size_t sizeof_stream_item); + int sizeof_stream_item (int index) const; + std::vector sizeof_stream_items() const; }; diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_block.cc index 630d72749..5a0875335 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.cc @@ -42,7 +42,7 @@ qa_gr_block::t0 () CPPUNIT_ASSERT_EQUAL (0, src1->input_signature()->max_streams ()); CPPUNIT_ASSERT_EQUAL (1, src1->output_signature()->min_streams ()); CPPUNIT_ASSERT_EQUAL (1, src1->output_signature()->max_streams ()); - CPPUNIT_ASSERT_EQUAL (sizeof (int), + CPPUNIT_ASSERT_EQUAL ((int) sizeof(int), src1->output_signature()->sizeof_stream_item (0)); gr_block_sptr src2 (gr_make_null_source (sizeof (short))); @@ -50,7 +50,7 @@ qa_gr_block::t0 () CPPUNIT_ASSERT_EQUAL (0, src2->input_signature()->max_streams ()); CPPUNIT_ASSERT_EQUAL (1, src2->output_signature()->min_streams ()); CPPUNIT_ASSERT_EQUAL (1, src2->output_signature()->max_streams ()); - CPPUNIT_ASSERT_EQUAL (sizeof (short), + CPPUNIT_ASSERT_EQUAL ((int) sizeof (short), src2->output_signature()->sizeof_stream_item (0)); } @@ -63,7 +63,7 @@ qa_gr_block::t1 () CPPUNIT_ASSERT_EQUAL (std::string ("null_sink"), dst1->name ()); CPPUNIT_ASSERT_EQUAL (1, dst1->input_signature()->min_streams ()); CPPUNIT_ASSERT_EQUAL (1, dst1->input_signature()->max_streams ()); - CPPUNIT_ASSERT_EQUAL (sizeof (int), + CPPUNIT_ASSERT_EQUAL ((int) sizeof (int), dst1->input_signature()->sizeof_stream_item (0)); CPPUNIT_ASSERT_EQUAL (0, dst1->output_signature()->max_streams ()); @@ -72,7 +72,7 @@ qa_gr_block::t1 () CPPUNIT_ASSERT_EQUAL (std::string ("null_sink"), dst2->name ()); CPPUNIT_ASSERT_EQUAL (1, dst2->input_signature()->min_streams ()); CPPUNIT_ASSERT_EQUAL (1, dst2->input_signature()->max_streams ()); - CPPUNIT_ASSERT_EQUAL (sizeof (short), + CPPUNIT_ASSERT_EQUAL ((int) sizeof (short), dst2->input_signature()->sizeof_stream_item (0)); CPPUNIT_ASSERT_EQUAL (0, dst2->output_signature()->max_streams ()); } diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc index 766ea2f6b..b800b57b5 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc @@ -41,6 +41,6 @@ void qa_gr_hier_block2::test_make() CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->max_streams()); CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->min_streams()); CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->max_streams()); - CPPUNIT_ASSERT_EQUAL(sizeof(int), + CPPUNIT_ASSERT_EQUAL((int) sizeof(int), src1->output_signature()->sizeof_stream_item(0)); } diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc index ed32f9554..3b8976c6e 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc @@ -45,11 +45,20 @@ qa_gr_io_signature::t2 () gr_make_io_signature (3, gr_io_signature::IO_INFINITE, sizeof (int)); CPPUNIT_ASSERT_EQUAL (p->min_streams (), 3); - CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item (0), sizeof (int)); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item (0), (int) sizeof (int)); } void qa_gr_io_signature::t3 () { -} + gr_io_signature_sptr p = + gr_make_io_signature3 (0, 5, 1, 2, 3); + CPPUNIT_ASSERT_EQUAL (p->min_streams (), 0); + CPPUNIT_ASSERT_EQUAL (p->max_streams (), 5); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(0), 1); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(1), 2); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(2), 3); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(3), 3); + CPPUNIT_ASSERT_EQUAL (p->sizeof_stream_item(4), 3); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h index ef14ab1cd..3b22105f6 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h @@ -41,7 +41,6 @@ class qa_gr_io_signature : public CppUnit::TestCase { void t1 (); void t2 (); void t3 (); - }; #endif /* INCLUDED_QA_GR_IO_SIGNATURE_H */ -- cgit From b26ea69676c09f5366a9e2f33b11ae5a7521ffe5 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 28 Apr 2007 02:20:28 +0000 Subject: Merged -r 5137:5174 from developer branch jcorgan/hb. Trunk passes distcheck. Converts gr.hier_block2 API to not use 'define_component' methodology anymore. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5177 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 1 - gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 13 +- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 9 +- gnuradio-core/src/lib/runtime/gr_hier_block2.i | 9 +- .../src/lib/runtime/gr_hier_block2_detail.cc | 282 ++++----- .../src/lib/runtime/gr_hier_block2_detail.h | 36 +- gnuradio-core/src/lib/runtime/gr_runtime.cc | 41 +- gnuradio-core/src/lib/runtime/gr_runtime.h | 54 +- gnuradio-core/src/lib/runtime/gr_runtime.i | 9 +- gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 123 ++-- gnuradio-core/src/lib/runtime/gr_runtime_impl.h | 56 +- .../src/lib/runtime/gr_simple_flowgraph.cc | 27 +- .../src/lib/runtime/gr_simple_flowgraph.h | 50 +- .../src/lib/runtime/gr_simple_flowgraph.i | 45 -- .../src/lib/runtime/gr_simple_flowgraph_detail.cc | 666 +++++++++------------ .../src/lib/runtime/gr_simple_flowgraph_detail.h | 137 ++--- gnuradio-core/src/lib/runtime/runtime.i | 2 - 17 files changed, 750 insertions(+), 810 deletions(-) delete mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 91d3c144b..ee71fcdbc 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -129,7 +129,6 @@ swiginclude_HEADERS = \ gr_msg_queue.i \ gr_realtime.i \ gr_runtime.i \ - gr_simple_flowgraph.i \ gr_single_threaded_scheduler.i \ gr_sync_block.i \ gr_sync_decimator.i \ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index 65dea95fb..d5ed4ccc9 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -50,14 +50,15 @@ gr_hier_block2::~gr_hier_block2() } void -gr_hier_block2::define_component(const std::string &name, gr_basic_block_sptr block) +gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) { - d_detail->define_component(name, block); + d_detail->connect(src, src_port, dst, dst_port); } void -gr_hier_block2::connect(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port) +gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) { - d_detail->connect(src_name, src_port, dst_name, dst_port); + d_detail->disconnect(src, src_port, dst, dst_port); } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 9d2dd3569..53a23bb47 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -59,9 +59,10 @@ protected: public: virtual ~gr_hier_block2(); - void define_component(const std::string &name, gr_basic_block_sptr basic_block); - void connect(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port); + void connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port); + void disconnect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port); }; #endif /* INCLUDED_GR_HIER_BLOCK2_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index c5a676534..f9a126fe2 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005,2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -44,9 +44,10 @@ public: ~gr_hier_block2 (); // Add a named block to the container - void define_component(const std::string &name, gr_basic_block_sptr basic_block) + void connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) throw (std::invalid_argument); - void connect(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port) + void disconnect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) throw (std::invalid_argument); }; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 545a64bfd..b41d0c65c 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -1,5 +1,5 @@ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -29,199 +29,157 @@ #include #include +#define GR_HIER_BLOCK2_DETAIL_DEBUG 1 + gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : -d_owner(owner) + d_owner(owner), + d_fg(gr_make_simple_flowgraph()), + d_inputs(owner->input_signature()->max_streams()), + d_outputs(owner->output_signature()->max_streams()) { } gr_hier_block2_detail::~gr_hier_block2_detail() { - d_owner = 0; // Don't use delete, we didn't allocate -} - -gr_basic_block_sptr -gr_hier_block2_detail::lookup_block(const std::string &name) -{ - gr_hier_component_miter_t p = d_components.find(name); - if (p != d_components.end()) - return p->second; - else - return gr_basic_block_sptr(); + d_owner = 0; // Don't use delete, we didn't allocate } void -gr_hier_block2_detail::define_component(const std::string &name, gr_basic_block_sptr block) +gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) { - if (!block) - throw std::invalid_argument("null block passed"); - - if (name == "self") - throw std::invalid_argument("name is reserved"); - - // TODO: reject names with '.' inside - - if (!lookup_block(name)) - d_components[name] = block; - else - throw std::invalid_argument("name already in use"); + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "connecting: " << gr_endpoint(src, src_port) + << " -> " << gr_endpoint(dst, dst_port) << std::endl; + + if (src.get() == dst.get()) + throw std::invalid_argument("src and destination blocks cannot be the same"); + + // Assignments to block inputs or outputs + int max_port; + if (src.get() == d_owner) { + max_port = src->input_signature()->max_streams(); + if ((max_port != -1 && (src_port >= max_port)) || src_port < 0) + throw std::invalid_argument("source port out of range"); + return assign_input(src_port, dst_port, dst); + } + + if (dst.get() == d_owner) { + max_port = dst->output_signature()->max_streams(); + if ((max_port != -1 && (dst_port >= max_port)) || dst_port < 0) + throw std::invalid_argument("source port out of range"); + return assign_output(dst_port, src_port, src); + } + + // Internal connections + d_fg->connect(src, src_port, dst, dst_port); + + // TODO: connects to NC } void -gr_hier_block2_detail::connect(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port) +gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) { - gr_io_signature_sptr src_io_signature; - gr_io_signature_sptr dst_io_signature; - - // Check against our *input_signature* if we're wiring from one of our external inputs - if (src_name == "self") - src_io_signature = d_owner->input_signature(); - else { - gr_basic_block_sptr src_block = lookup_block(src_name); - if (!src_block) - throw std::invalid_argument("undefined src name"); - src_io_signature = src_block->output_signature(); - } - - // Check against our *output_signature* if we're wiring to one of our external outputs - if (dst_name == "self") - dst_io_signature = d_owner->output_signature(); - else { - gr_basic_block_sptr dst_block = lookup_block(dst_name); - if (!dst_block) - throw std::invalid_argument("undefined dst name"); - dst_io_signature = dst_block->input_signature(); - } - - // Check port numbers are valid - check_valid_port(src_io_signature, src_port); - check_valid_port(dst_io_signature, dst_port); - - // Check destination port not already in use - check_dst_not_used(dst_name, dst_port); - - // Check endpoint types match - check_type_match(src_io_signature, src_port, dst_io_signature, dst_port); - - d_edges.push_back(gr_make_edge(src_name, src_port, dst_name, dst_port)); -} + // Handle disconnecting inputs and outputs -void -gr_hier_block2_detail::check_valid_port(gr_io_signature_sptr sig, int port) -{ - if (port < 0) - throw std::invalid_argument("port number must not be negative"); - - if (sig->max_streams() >= 0 && port >= sig->max_streams()) - throw std::invalid_argument("port number exceeds max streams"); + d_fg->disconnect(src, src_port, dst, dst_port); } -void -gr_hier_block2_detail::check_dst_not_used(const std::string name, int port) +void +gr_hier_block2_detail::assign_input(int my_port, int port, gr_basic_block_sptr block) { - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if ((*p)->dst_name() == name && (*p)->dst_port() == port) - throw std::invalid_argument("destination port in use"); -} + if (my_port < 0 || my_port >= (signed)d_inputs.size()) + throw std::invalid_argument("input port number out of range"); -void -gr_hier_block2_detail::check_type_match(gr_io_signature_sptr src_sig, int src_port, - gr_io_signature_sptr dst_sig, int dst_port) -{ - if (src_sig->sizeof_stream_item(src_port) != dst_sig->sizeof_stream_item(dst_port)) - throw std::invalid_argument("type mismatch"); -} + if (d_inputs[my_port].block()) + throw std::invalid_argument("input port in use"); -std::string -gr_hier_block2_detail::prepend_prefix(const std::string &prefix, const std::string &str) -{ - return prefix + ((prefix == "") ? "" : ".") + str; + d_inputs[my_port] = gr_endpoint(block, port); } -gr_endpoint -gr_hier_block2_detail::match_endpoint(const std::string &name, int port, bool is_input) +void +gr_hier_block2_detail::assign_output(int my_port, int port, gr_basic_block_sptr block) { - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - if (is_input) { - if ((*p)->src_name() == name && (*p)->src_port() == port) - return resolve_endpoint((*p)->dst_name(), (*p)->dst_port(), "", !is_input); - } - else { - if ((*p)->dst_name() == name && (*p)->dst_port() == port) - return resolve_endpoint((*p)->src_name(), (*p)->src_port(), "", !is_input); - } - } - - // Should never get here - throw std::runtime_error("unable to match endpoint"); -} + if (my_port < 0 || my_port >= (signed)d_outputs.size()) + throw std::invalid_argument("output port number out of range"); -gr_endpoint -gr_hier_block2_detail::resolve_endpoint(const std::string &name, int port, - const std::string &prefix, bool is_input) -{ - gr_basic_block_sptr basic_block = lookup_block(name); - - // Check if 'name' points to gr_block (leaf node) - gr_block_sptr block(boost::dynamic_pointer_cast(basic_block)); - if (block) - return gr_endpoint(prepend_prefix(prefix, name), port); - - // Check if 'name' points to hierarchical block - gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(basic_block)); - if (hier_block2) { - std::string child_prefix = prepend_prefix(prefix, name); - gr_endpoint match(hier_block2->d_detail->match_endpoint("self", port, !is_input)); - return gr_endpoint(prepend_prefix(child_prefix, match.name()), match.port()); - } - - // Shouldn't ever get here - throw std::runtime_error("unable to resolve endpoint"); + if (d_outputs[my_port].block()) + throw std::invalid_argument("output port in use"); + + d_outputs[my_port] = gr_endpoint(block, port); } -void -gr_hier_block2_detail::flatten(gr_simple_flowgraph_sptr sfg, const std::string &prefix) +gr_endpoint +gr_hier_block2_detail::resolve_port(int port, bool is_input) { - flatten_components(sfg, prefix); - flatten_edges(sfg, prefix); + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "Resolving port " << port << " as an " + << (is_input ? "input" : "output") + << " of " << d_owner->name() << std::endl; + + gr_endpoint result; + + if (is_input) { + if (port < 0 || port >= (signed)d_inputs.size()) + throw std::runtime_error("input port number out of range"); + result = resolve_endpoint(d_inputs[port], true); + } + else { + if (port < 0 || port >= (signed)d_outputs.size()) + throw std::runtime_error("output port number out of range"); + result = resolve_endpoint(d_outputs[port], false); + } + + if (!result.block()) + throw std::runtime_error("unable to resolve port"); + + return result; } -void -gr_hier_block2_detail::flatten_components(gr_simple_flowgraph_sptr sfg, const std::string &prefix) +gr_endpoint +gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) { - // Add my non-hierarchical components to the simple flowgraph, then recurse - for (gr_hier_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { - std::string name = prepend_prefix(prefix, p->first); - - gr_basic_block_sptr basic_block = p->second; - gr_block_sptr block(boost::dynamic_pointer_cast(basic_block)); - if (block) - sfg->define_component(name, block); - - gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(basic_block)); - if (hier_block2) - hier_block2->d_detail->flatten_components(sfg, name); - } + // Check if endpoint is a leaf node + if (boost::dynamic_pointer_cast(endp.block())) + return endp; + + // Check if endpoint is a hierarchical block + gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(endp.block())); + if (hier_block2) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "Resolving endpoint " << endp << " as an " + << (is_input ? "input" : "output") + << ", recursing" << std::endl; + return hier_block2->d_detail->resolve_port(endp.port(), is_input); + } + + // Shouldn't ever get here + throw std::runtime_error("block is not a valid gr_block or gr_hier_block2!"); } void -gr_hier_block2_detail::flatten_edges(gr_simple_flowgraph_sptr sfg, const std::string &prefix) +gr_hier_block2_detail::flatten(gr_simple_flowgraph_sptr sfg) { - // Add my edges to the flow graph, resolving references to actual endpoints - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - // Connections to self get resolved/added by parent if actually connected - if ((*p)->src_name() == "self" || (*p)->dst_name() == "self") - continue; - - gr_endpoint src_endp = resolve_endpoint((*p)->src_name(), (*p)->src_port(), prefix, true); - gr_endpoint dst_endp = resolve_endpoint((*p)->dst_name(), (*p)->dst_port(), prefix, false); - sfg->connect(src_endp.name(), src_endp.port(), dst_endp.name(), dst_endp.port()); - } - - // Recurse hierarchical children - for (gr_hier_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { - gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(p->second)); - if (hier_block2) - hier_block2->d_detail->flatten_edges(sfg, prepend_prefix(prefix, p->first)); - } + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "flattening " << d_owner->name() << std::endl; + + // Add my edges to the flow graph, resolving references to actual endpoints + for (gr_edge_viter_t p = d_fg->d_detail->d_edges.begin(); p != d_fg->d_detail->d_edges.end(); p++) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "Flattening edge " << (*p) << std::endl; + + gr_endpoint src_endp = resolve_endpoint((*p)->src(), false); + gr_endpoint dst_endp = resolve_endpoint((*p)->dst(), true); + sfg->connect(src_endp, dst_endp); + } + + gr_basic_block_vector_t blocks = d_fg->d_detail->calc_used_blocks(); + + // Recurse hierarchical children + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(*p)); + if (hier_block2) + hier_block2->d_detail->flatten(sfg); + } } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index 095bd40f5..f0e7b7e82 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -1,5 +1,5 @@ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,9 +25,6 @@ #include #include -typedef std::map gr_hier_component_map_t; -typedef std::map::iterator gr_hier_component_miter_t; - class gr_hier_block2_detail : boost::noncopyable { private: @@ -39,26 +36,21 @@ private: // Private implementation data gr_hier_block2 *d_owner; - gr_hier_component_map_t d_components; - gr_edge_vector_t d_edges; + gr_simple_flowgraph_sptr d_fg; + gr_endpoint_vector_t d_inputs; + gr_endpoint_vector_t d_outputs; // Private implementation methods - void define_component(const std::string &name, gr_basic_block_sptr block); - gr_basic_block_sptr lookup_block(const std::string &name); - void connect(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port); - void check_valid_port(gr_io_signature_sptr sig, int port); - void check_dst_not_used(const std::string name, int port); - void check_type_match(gr_io_signature_sptr src_sig, int src_port, - gr_io_signature_sptr dst_sig, int dst_port); - std::string prepend_prefix(const std::string &prefix, const std::string &str); - void flatten(gr_simple_flowgraph_sptr sfg, const std::string &prefix = ""); - void flatten_components(gr_simple_flowgraph_sptr sfg, const std::string &prefix); - void flatten_edges(gr_simple_flowgraph_sptr sfg, const std::string &prefix); - gr_endpoint match_endpoint(const std::string &name, int port, bool is_input); - gr_endpoint resolve_endpoint(const std::string &name, int port, - const std::string &prefix, bool is_input); - + void connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port); + void disconnect(gr_basic_block_sptr, int src_port, + gr_basic_block_sptr, int dst_port); + void assign_input(int my_port, int port, gr_basic_block_sptr block); + void assign_output(int my_port, int port, gr_basic_block_sptr block); + void flatten(gr_simple_flowgraph_sptr sfg); + gr_endpoint resolve_port(int port, bool is_input); + gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input); + public: ~gr_hier_block2_detail(); }; diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.cc b/gnuradio-core/src/lib/runtime/gr_runtime.cc index aab8ea5ab..a8b932f21 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -34,57 +34,64 @@ static gr_runtime *s_runtime = 0; gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block) { - return gr_runtime_sptr(new gr_runtime(top_block)); + return gr_runtime_sptr(new gr_runtime(top_block)); } gr_runtime::gr_runtime(gr_hier_block2_sptr top_block) { - d_impl = new gr_runtime_impl(top_block); - s_runtime = this; + d_impl = new gr_runtime_impl(top_block); + s_runtime = this; } gr_runtime::~gr_runtime() { - s_runtime = 0; // we don't own this - delete d_impl; + s_runtime = 0; // we don't own this + delete d_impl; } // FIXME: This prevents using more than one gr_runtime instance static void runtime_sigint_handler(int signum) { - - if (s_runtime) - s_runtime->stop(); + if (s_runtime) + s_runtime->stop(); } void gr_runtime::start() { - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - d_impl->start(); + d_impl->start(); } void gr_runtime::stop() { - d_impl->stop(); + d_impl->stop(); } void gr_runtime::wait() { - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - d_impl->wait(); + d_impl->wait(); } void gr_runtime::run() { - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); + + d_impl->start(); + d_impl->wait(); +} + +void +gr_runtime::restart() +{ + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - d_impl->start(); - d_impl->wait(); + d_impl->restart(); } diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.h b/gnuradio-core/src/lib/runtime/gr_runtime.h index fc58da456..5aec6dcf0 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -29,21 +29,57 @@ class gr_runtime_impl; gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); +/*! + *\brief Runtime object that controls simple flow graph operation + * + * This class is instantiated with a top-level gr_hier_block2. The + * runtime then flattens the hierarchical block into a gr_simple_flowgraph, + * and allows control through start(), stop(), wait(), and run(). + * + */ class gr_runtime { private: - gr_runtime(gr_hier_block2_sptr top_block); - friend gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); + gr_runtime(gr_hier_block2_sptr top_block); + friend gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); - gr_runtime_impl *d_impl; + gr_runtime_impl *d_impl; public: - ~gr_runtime(); + ~gr_runtime(); + + /*! + * Start the flow graph. Creates an undetached scheduler thread for + * each flow graph partition. Returns to caller once created. + */ + void start(); + + /*! + * Stop a running flow graph. Tells each created scheduler thread + * to exit, then returns to caller. + */ + void stop(); + + /*! + * Wait for a stopped flow graph to complete. Joins each completed + * thread. + */ + void wait(); + + /*! + * Calls start(), then wait(). Used to run a flow graph that will stop + * on its own, or to run a flow graph indefinitely until SIGTERM is + * received(). + */ + void run(); - void start(); - void stop(); - void wait(); - void run(); + /*! + * Restart a running flow graph, after topology changes have + * been made to its top_block (or children). Causes each created + * scheduler thread to end, recalculates the flow graph, and + * recreates new threads (possibly a different number from before.) + */ + void restart(); }; #endif /* INCLUDED_GR_RUNTIME_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.i b/gnuradio-core/src/lib/runtime/gr_runtime.i index 3a8b7e0b6..10e757baa 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.i +++ b/gnuradio-core/src/lib/runtime/gr_runtime.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006 Free Software Foundation, Inc. + * Copyright 2004,2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -36,6 +36,7 @@ public: void start() throw (std::runtime_error); void stop() throw (std::runtime_error); void wait() throw (std::runtime_error); + void restart() throw (std::runtime_error); }; %{ @@ -72,4 +73,10 @@ void runtime_wait_unlocked(gr_runtime_sptr r) throw (std::runtime_error) r->wait(); } +void runtime_restart_unlocked(gr_runtime_sptr r) throw (std::runtime_error) +{ + ensure_py_gil_state2 _lock; + r->restart(); +} + %} diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc index f8d65261e..5cd75f3ce 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -36,8 +36,6 @@ #include #include -#define GR_RUNTIME_IMPL_DEBUG 0 - gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) : d_running(false), d_top_block(top_block), @@ -52,56 +50,82 @@ gr_runtime_impl::~gr_runtime_impl() void gr_runtime_impl::start() { - if (d_running) - throw std::runtime_error("already running"); - else - d_running = true; - - d_sfg->d_detail->reset(); - d_top_block->d_detail->flatten(d_sfg); - d_sfg->d_detail->validate(); - d_sfg->d_detail->setup_connections(); - - d_graphs = d_sfg->d_detail->partition(); - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "Flow graph has " << d_graphs.size() - << " sub-graphs." << std::endl; - - d_threads.clear(); - for (std::vector::iterator p = d_graphs.begin(); - p != d_graphs.end(); p++) { - gr_scheduler_thread *thread = new gr_scheduler_thread(*p); - thread->start(); - d_threads.push_back(thread); - } + if (d_running) + throw std::runtime_error("already running"); + else + d_running = true; + + // Create new simple flow graph by flattening hierarchical block + d_sfg->d_detail->reset(); + d_top_block->d_detail->flatten(d_sfg); + + // Validate new simple flow graph and wire it up + d_sfg->d_detail->validate(); + d_sfg->d_detail->setup_connections(); + + // Execute scheduler threads + start_threads(); +} + +void +gr_runtime_impl::start_threads() +{ + d_graphs = d_sfg->d_detail->partition(); + d_threads.clear(); + for (std::vector::iterator p = d_graphs.begin(); + p != d_graphs.end(); p++) { + gr_scheduler_thread *thread = new gr_scheduler_thread(*p); + thread->start(); + d_threads.push_back(thread); + } } void gr_runtime_impl::stop() { - if (!d_running) - throw std::runtime_error("not running"); + if (!d_running) + throw std::runtime_error("not running"); - for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) - (*p)->stop(); + for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) + (*p)->stop(); - d_running = false; + d_running = false; } void gr_runtime_impl::wait() { - void *dummy_status; // don't ever dereference this + void *dummy_status; // don't ever dereference this + + for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { + (*p)->join(&dummy_status); // pthreads will self-delete, so pointer is now dead + (*p) = 0; // FIXME: switch to stl::list and actually remove from container + } +} - for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { - (*p)->join(&dummy_status); // pthreads will self-delete, so pointer is now dead - (*p) = 0; // FIXME: switch to stl::list and actually remove from container - } +void +gr_runtime_impl::restart() +{ + if (!d_running) + throw std::runtime_error("not running"); + + // Stop scheduler threads and wait for completion + stop(); + wait(); + + // Create new simple flow graph + gr_simple_flowgraph_sptr new_sfg = gr_make_simple_flowgraph(); + d_top_block->d_detail->flatten(new_sfg); + new_sfg->validate(); + new_sfg->d_detail->merge_connections(d_sfg); + // d_sfg = new_sfg; + + start_threads(); } gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) : - omni_thread(NULL, PRIORITY_NORMAL), - d_sts(gr_make_single_threaded_scheduler(graph)) + omni_thread(NULL, PRIORITY_NORMAL), + d_sts(gr_make_single_threaded_scheduler(graph)) { } @@ -111,28 +135,29 @@ gr_scheduler_thread::~gr_scheduler_thread() void gr_scheduler_thread::start() { - start_undetached(); + start_undetached(); } void * gr_scheduler_thread::run_undetached(void *arg) { - // First code to run in new thread context + // First code to run in new thread context - // Mask off SIGINT in this thread to gaurantee mainline thread gets signal + // Mask off SIGINT in this thread to gaurantee mainline thread gets signal #ifdef HAVE_SIGPROCMASK - sigset_t old_set; - sigset_t new_set; - sigemptyset(&new_set); - sigaddset(&new_set, SIGINT); - sigprocmask(SIG_BLOCK, &new_set, &old_set); + sigset_t old_set; + sigset_t new_set; + sigemptyset(&new_set); + sigaddset(&new_set, SIGINT); + sigprocmask(SIG_BLOCK, &new_set, &old_set); #endif - // Run the single-threaded scheduler - d_sts->run(); - return 0; + // Run the single-threaded scheduler + d_sts->run(); + return 0; } -void gr_scheduler_thread::stop() +void +gr_scheduler_thread::stop() { - d_sts->stop(); + d_sts->stop(); } diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h index e69446719..bb2a08334 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -33,38 +33,56 @@ class gr_scheduler_thread; typedef std::vector gr_scheduler_thread_vector_t; typedef gr_scheduler_thread_vector_t::iterator gr_scheduler_thread_viter_t; +/*! + *\brief A single thread of execution for the scheduler + * + * This class implements a single thread that runs undetached, and + * invokes the single-threaded block scheduler. The runtime makes + * one of these for each distinct partition of a flowgraph and runs + * them in parallel. + * + */ class gr_scheduler_thread : public omni_thread { private: - gr_single_threaded_scheduler_sptr d_sts; + gr_single_threaded_scheduler_sptr d_sts; public: - gr_scheduler_thread(gr_block_vector_t graph); - ~gr_scheduler_thread(); + gr_scheduler_thread(gr_block_vector_t graph); + ~gr_scheduler_thread(); - virtual void *run_undetached(void *arg); - void start(); - void stop(); + virtual void *run_undetached(void *arg); + void start(); + void stop(); }; +/*! + *\brief Implementation details of gr_runtime + * + * The actual implementation of gr_runtime. Separate class allows + * decoupling of changes from dependent classes. + * + */ class gr_runtime_impl { private: - gr_runtime_impl(gr_hier_block2_sptr top_block); - friend class gr_runtime; + gr_runtime_impl(gr_hier_block2_sptr top_block); + friend class gr_runtime; - bool d_running; - gr_hier_block2_sptr d_top_block; - gr_simple_flowgraph_sptr d_sfg; - std::vector d_graphs; - gr_scheduler_thread_vector_t d_threads; + bool d_running; + gr_hier_block2_sptr d_top_block; + gr_simple_flowgraph_sptr d_sfg; + std::vector d_graphs; + gr_scheduler_thread_vector_t d_threads; - void start(); - void stop(); - void wait(); - + void start(); + void start_threads(); + void stop(); + void wait(); + void restart(); + public: - ~gr_runtime_impl(); + ~gr_runtime_impl(); }; diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc index 21aeb587c..780d51d78 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc @@ -28,11 +28,9 @@ #include #include -#define GR_SIMPLE_FLOWGRAPH_DEBUG 0 - gr_simple_flowgraph_sptr gr_make_simple_flowgraph() { - return gr_simple_flowgraph_sptr(new gr_simple_flowgraph()); + return gr_simple_flowgraph_sptr(new gr_simple_flowgraph()); } gr_simple_flowgraph::gr_simple_flowgraph() : @@ -42,26 +40,31 @@ d_detail(new gr_simple_flowgraph_detail()) gr_simple_flowgraph::~gr_simple_flowgraph() { - delete d_detail; + delete d_detail; +} + +void +gr_simple_flowgraph::connect(gr_basic_block_sptr src_block, int src_port, + gr_basic_block_sptr dst_block, int dst_port) +{ + d_detail->connect(gr_endpoint(src_block, src_port), gr_endpoint(dst_block, dst_port)); } void -gr_simple_flowgraph::define_component(const std::string &name, gr_block_sptr block) +gr_simple_flowgraph::connect(const gr_endpoint &src, const gr_endpoint &dst) { - if (GR_SIMPLE_FLOWGRAPH_DEBUG) - std::cout << "Defining block " << block << " as " << name << std::endl; - d_detail->define_component(name, block); + d_detail->connect(src, dst); } void -gr_simple_flowgraph::connect(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port) +gr_simple_flowgraph::disconnect(gr_basic_block_sptr src_block, int src_port, + gr_basic_block_sptr dst_block, int dst_port) { - d_detail->connect(src_name, src_port, dst_name, dst_port); + d_detail->disconnect(gr_endpoint(src_block, src_port), gr_endpoint(dst_block, dst_port)); } void gr_simple_flowgraph::validate() { - d_detail->validate(); + d_detail->validate(); } diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h index ca2c505e5..a22e558ff 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -31,22 +31,52 @@ gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); class gr_simple_flowgraph_detail; +class gr_endpoint +{ +private: + friend class gr_hier_block2_detail; + gr_basic_block_sptr d_block; + int d_port; + +public: + gr_endpoint() : d_block(), d_port(0) { } // Internal use only + gr_endpoint(gr_basic_block_sptr block, int port) { d_block = block; d_port = port; } + gr_basic_block_sptr block() const { return d_block; } + int port() const { return d_port; } +}; + +typedef std::vector gr_endpoint_vector_t; + +/*! + *\brief Class representing a low-level, "flattened" flow graph + * + * This class holds the results of the call to gr.hier_block2.flatten(), + * which is a graph that has only the connected blocks and edges of + * the original hier_block2, with all the hierarchy removed. + * + * While this class is exported to Python via SWIG for ease of QA + * testing, it is not used by application developers, and there is + * no way to feed this to a gr.runtime() instance. + */ class gr_simple_flowgraph { private: - friend class gr_runtime_impl; - friend gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); - gr_simple_flowgraph(); + friend class gr_runtime_impl; + friend class gr_hier_block2_detail; + friend gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); + gr_simple_flowgraph(); - gr_simple_flowgraph_detail *d_detail; + gr_simple_flowgraph_detail *d_detail; public: - ~gr_simple_flowgraph(); + ~gr_simple_flowgraph(); - void define_component(const std::string &name, gr_block_sptr block); - void connect(const std::string &src, int src_port, - const std::string &dst, int dst_port); - void validate(); + void connect(gr_basic_block_sptr src_block, int src_port, + gr_basic_block_sptr dst_block, int dst_port); + void connect(const gr_endpoint &src, const gr_endpoint &dst); + void disconnect(gr_basic_block_sptr src_block, int src_port, + gr_basic_block_sptr dst_block, int dst_port); + void validate(); }; #endif /* INCLUDED_GR_SIMPLE_FLOWGRAPH_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i deleted file mode 100644 index c3654fe50..000000000 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -class gr_simple_flowgraph; -typedef boost::shared_ptr gr_simple_flowgraph_sptr; -%template(gr_simple_flowgraph_sptr) boost::shared_ptr; -%rename(simple_flowgraph) gr_make_simple_flowgraph; -%ignore gr_simple_flowgraph; - -gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); - -class gr_simple_flowgraph -{ -private: - gr_simple_flowgraph(); - -public: - ~gr_simple_flowgraph(); - void define_component(const std::string name, gr_block_sptr block) - throw (std::invalid_argument); - void connect(const std::string &src, int src_port, - const std::string &dst, int dst_port) - throw (std::invalid_argument); - void validate() - throw (std::runtime_error); -}; diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc index 0c9c9b707..13d23efe5 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -32,31 +32,16 @@ #include #include -#define GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG 0 - gr_edge_sptr -gr_make_edge(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port) -{ - return gr_edge_sptr(new gr_edge(src_name, src_port, dst_name, dst_port)); -} - -gr_edge::gr_edge(const std::string &src_name, int src_port, const std::string &dst_name, int dst_port) - : d_src(src_name, src_port), - d_dst(dst_name, dst_port) +gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst) { + return gr_edge_sptr(new gr_edge(src, dst)); } gr_edge::~gr_edge() { } -gr_simple_flowgraph_detail::gr_simple_flowgraph_detail() : -d_components(), -d_edges() -{ -} - gr_simple_flowgraph_detail::~gr_simple_flowgraph_detail() { } @@ -64,498 +49,435 @@ gr_simple_flowgraph_detail::~gr_simple_flowgraph_detail() void gr_simple_flowgraph_detail::reset() { - // Boost shared pointers will deallocate as needed - d_edges.clear(); - d_components.clear(); -} - -gr_block_sptr -gr_simple_flowgraph_detail::lookup_block(const std::string &name) -{ - gr_component_miter_t p = d_components.find(name); - if (p != d_components.end()) - return p->second; - else - return gr_block_sptr(); -} - -std::string -gr_simple_flowgraph_detail::lookup_name(gr_block_sptr block) -{ - for (gr_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { - if (p->second == block) - return p->first; - } - - return std::string(""); // Not found + // Boost shared pointers will deallocate as needed + d_edges.clear(); + d_blocks.clear(); } void -gr_simple_flowgraph_detail::define_component(const std::string &name, gr_block_sptr block) +gr_simple_flowgraph_detail::connect(const gr_endpoint &src, const gr_endpoint &dst) { - if (!block) - throw std::invalid_argument("null block passed"); - - if (!lookup_block(name)) - d_components[name] = block; - else - throw std::invalid_argument("name already in use"); + check_valid_port(src.block()->output_signature(), src.port()); + check_valid_port(dst.block()->input_signature(), dst.port()); + check_dst_not_used(dst); + check_type_match(src, dst); + d_edges.push_back(gr_make_edge(src,dst)); } void -gr_simple_flowgraph_detail::connect(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port) +gr_simple_flowgraph_detail::disconnect(const gr_endpoint &src, const gr_endpoint &dst) { - gr_block_sptr src_block = lookup_block(src_name); - gr_block_sptr dst_block = lookup_block(dst_name); - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Connecting " << src_name << ":" << src_port << "->" - << dst_name << ":" << dst_port << std::endl; - - if (!src_block) - throw std::invalid_argument("unknown src name"); - if (!dst_block) - throw std::invalid_argument("unknown dst name"); - - check_valid_port(src_block->output_signature(), src_port); - check_valid_port(dst_block->input_signature(), dst_port); - check_dst_not_used(dst_name, dst_port); - check_type_match(src_block, src_port, dst_block, dst_port); + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + if (src.block() == (*p)->src().block() && src.port() == (*p)->src().port() && + dst.block() == (*p)->dst().block() && dst.port() == (*p)->dst().port()) { + d_edges.erase(p); + return; + } + } - d_edges.push_back(gr_make_edge(src_name, src_port, dst_name, dst_port)); + throw std::invalid_argument("edge to disconnect not found"); } void gr_simple_flowgraph_detail::check_valid_port(gr_io_signature_sptr sig, int port) { - if (port < 0) - throw std::invalid_argument("negative port number"); - if (sig->max_streams() >= 0 && port >= sig->max_streams()) - throw std::invalid_argument("port number exceeds max"); + if (port < 0) + throw std::invalid_argument("negative port number"); + if (sig->max_streams() >= 0 && port >= sig->max_streams()) + throw std::invalid_argument("port number exceeds max"); } void -gr_simple_flowgraph_detail::check_dst_not_used(const std::string &name, int port) +gr_simple_flowgraph_detail::check_dst_not_used(const gr_endpoint &dst) { - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if ((*p)->dst_name() == name && (*p)->dst_port() == port) - throw std::invalid_argument("dst already in use"); + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if ((*p)->dst().block() == dst.block() && + (*p)->dst().port() == dst.port()) + throw std::invalid_argument("dst already in use"); } void -gr_simple_flowgraph_detail::check_type_match(gr_block_sptr src_block, int src_port, - gr_block_sptr dst_block, int dst_port) +gr_simple_flowgraph_detail::check_type_match(const gr_endpoint &src, const gr_endpoint &dst) { - int src_size = src_block->output_signature()->sizeof_stream_item(src_port); - int dst_size = dst_block->input_signature()->sizeof_stream_item(dst_port); + int src_size = src.block()->output_signature()->sizeof_stream_item(src.port()); + int dst_size = dst.block()->input_signature()->sizeof_stream_item(dst.port()); - if (src_size != dst_size) - throw std::invalid_argument("type size mismatch"); + if (src_size != dst_size) + throw std::invalid_argument("type size mismatch while attempting to connect"); } void gr_simple_flowgraph_detail::validate() { - for (gr_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { - std::vector used_ports; - int ninputs, noutputs; + d_blocks = calc_used_blocks(); - used_ports = calc_used_ports(p->first, true); // inputs - ninputs = used_ports.size(); - check_contiguity(p->second, used_ports, true); // inputs + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + std::vector used_ports; + int ninputs, noutputs; - used_ports = calc_used_ports(p->first, false); // outputs - noutputs = used_ports.size(); - check_contiguity(p->second, used_ports, false); // outputs + used_ports = calc_used_ports(*p, true); // inputs + ninputs = used_ports.size(); + check_contiguity(*p, used_ports, true); // inputs - if (!(p->second->check_topology(ninputs, noutputs))) - throw std::runtime_error("check topology failed"); - } + used_ports = calc_used_ports(*p, false); // outputs + noutputs = used_ports.size(); + check_contiguity(*p, used_ports, false); // outputs + + if (!((*p)->check_topology(ninputs, noutputs))) + throw std::runtime_error("check topology failed"); + } } std::vector -gr_simple_flowgraph_detail::calc_used_ports(const std::string &name, bool check_inputs) +gr_simple_flowgraph_detail::calc_used_ports(gr_basic_block_sptr block, bool check_inputs) { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Calculating used " << (check_inputs ? "input " : "output ") - << "ports..."; - - std::vector tmp, result; - std::insert_iterator > inserter(result, result.begin()); - - gr_edge_vector_t edges = calc_connections(name, check_inputs); - - for (gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) { - if (check_inputs == true) - tmp.push_back((*p)->dst_port()); - else - tmp.push_back((*p)->src_port()); - } - - // remove duplicates - std::sort(tmp.begin(), tmp.end()); - std::unique_copy(tmp.begin(), tmp.end(), inserter); + std::vector tmp, result; + std::insert_iterator > inserter(result, result.begin()); - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << result.size() << std::endl; + gr_edge_vector_t edges = calc_connections(block, check_inputs); + for (gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) { + if (check_inputs == true) + tmp.push_back((*p)->dst().port()); + else + tmp.push_back((*p)->src().port()); + } - return result; + // remove duplicates + std::sort(tmp.begin(), tmp.end()); + std::unique_copy(tmp.begin(), tmp.end(), inserter); + return result; } gr_edge_vector_t -gr_simple_flowgraph_detail::calc_connections(const std::string &name, bool check_inputs) +gr_simple_flowgraph_detail::calc_connections(gr_basic_block_sptr block, bool check_inputs) { - gr_edge_vector_t result; - - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - if (check_inputs) { - if ((*p)->dst_name() == name) - result.push_back(*p); - } - else { - if ((*p)->src_name() == name) - result.push_back(*p); - } + gr_edge_vector_t result; + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + if (check_inputs) { + if ((*p)->dst().block() == block) + result.push_back(*p); } + else { + if ((*p)->src().block() == block) + result.push_back(*p); + } + } - return result; // assumes no duplicates + return result; // assumes no duplicates } void -gr_simple_flowgraph_detail::check_contiguity(gr_block_sptr block, +gr_simple_flowgraph_detail::check_contiguity(gr_basic_block_sptr block, const std::vector &used_ports, bool check_inputs) { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Checking " << (check_inputs ? "input " : "output ") - << "contiguity..."; - - gr_io_signature_sptr sig = - check_inputs ? block->input_signature() : block->output_signature(); - - int nports = used_ports.size(); - int min_ports = sig->min_streams(); - - if (nports == 0) { - if (min_ports == 0) { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "ok." << std::endl; - return; - } - else { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "needs " << min_ports << ", only has " - << nports << std::endl; - - throw std::runtime_error("insufficient ports"); - } - } + gr_io_signature_sptr sig = + check_inputs ? block->input_signature() : block->output_signature(); - if (used_ports[nports-1]+1 != nports) { - for (int i = 0; i < nports; i++) { - if (used_ports[i] != i) { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "missing " << (check_inputs ? "input ":"output ") - << i << std::endl; + int nports = used_ports.size(); + int min_ports = sig->min_streams(); - throw std::runtime_error("missing input assignment"); - } - } - } - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "ok." << std::endl; + if (nports == 0) { + if (min_ports == 0) + return; + else + throw std::runtime_error("insufficient ports"); + } + + if (used_ports[nports-1]+1 != nports) { + for (int i = 0; i < nports; i++) + if (used_ports[i] != i) + throw std::runtime_error("missing input assignment"); + } } void gr_simple_flowgraph_detail::setup_connections() { - // Assign block details to component blocks - for (gr_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Allocating output buffers for " << p->first << "..." << std::endl; - - int ninputs = calc_used_ports(p->first, true).size(); - int noutputs = calc_used_ports(p->first, false).size(); - gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); - for (int i = 0; i < noutputs; i++) - detail->set_output(i, allocate_buffer(p->first, i)); - p->second->set_detail(detail); - } - - // Connect inputs to outputs for each block - for(gr_component_miter_t p = d_components.begin(); p != d_components.end(); p++) { - // Get its detail and edges that feed into it - gr_block_detail_sptr detail = p->second->detail(); - gr_edge_vector_t in_edges = calc_upstream_edges(p->first); - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - if (in_edges.size() > 0) - std::cout << "Connecting inputs to " << p->first << "..." << std::endl; - - // For each edge that feeds into it - for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) { - // Set the input buffer on the destination port to the output - // buffer on the source port - int dst_port = (*e)->dst_port(); - int src_port = (*e)->src_port(); - gr_block_sptr src_block = lookup_block((*e)->src_name()); - gr_buffer_sptr src_buffer = src_block->detail()->output(src_port); - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Setting input on " << (*e)->dst_name() - << ":" << dst_port << std::endl; - - detail->set_input(dst_port, gr_buffer_add_reader(src_buffer, p->second->history()-1)); - } + // Assign block details to blocks + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + int ninputs = calc_used_ports(*p, true).size(); + int noutputs = calc_used_ports(*p, false).size(); + gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); + for (int i = 0; i < noutputs; i++) + detail->set_output(i, allocate_buffer(*p, i)); + + boost::dynamic_pointer_cast(*p)->set_detail(detail); + } + + // Connect inputs to outputs for each block + for(gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + gr_block_sptr grblock(boost::dynamic_pointer_cast(*p)); + if (!grblock) + throw std::runtime_error("setup_connections found non-gr_block"); + + // Get its detail and edges that feed into it + gr_block_detail_sptr detail = grblock->detail(); + gr_edge_vector_t in_edges = calc_upstream_edges(*p); + + // For each edge that feeds into it + for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) { + // Set the input reader on the destination port to the output + // buffer on the source port + int dst_port = (*e)->dst().port(); + int src_port = (*e)->src().port(); + gr_basic_block_sptr src_block = (*e)->src().block(); + gr_block_sptr src_grblock(boost::dynamic_pointer_cast(src_block)); + if (!grblock) + throw std::runtime_error("setup_connections found non-gr_block"); + gr_buffer_sptr src_buffer = src_grblock->detail()->output(src_port); + + detail->set_input(dst_port, gr_buffer_add_reader(src_buffer, grblock->history()-1)); } + } } gr_buffer_sptr -gr_simple_flowgraph_detail::allocate_buffer(const std::string &name, int port) +gr_simple_flowgraph_detail::allocate_buffer(gr_basic_block_sptr block, int port) { - gr_block_sptr block = lookup_block(name); - int item_size = block->output_signature()->sizeof_stream_item(port); - int nitems = s_fixed_buffer_size/item_size; - - // Make sure there are at least twice the output_multiple no. of items - if (nitems < 2*block->output_multiple()) // Note: this means output_multiple() - nitems = 2*block->output_multiple(); // can't be changed by block dynamically - - // If any downstream blocks are decimators and/or have a large output_multiple, - // ensure we have a buffer at least twice their decimation factor*output_multiple - gr_block_vector_t blocks = calc_downstream_blocks(name, port); - for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - int decimation = (int)(1.0/(*p)->relative_rate()); - int multiple = (*p)->output_multiple(); - int history = (*p)->history(); - nitems = std::max(nitems, 2*(decimation*multiple+history)); - } - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Allocating buffer for port " << port << " with " - << nitems << " items of size " << item_size << std::endl; - - return gr_make_buffer(nitems, item_size); + gr_block_sptr grblock(boost::dynamic_pointer_cast(block)); + if (!grblock) + throw std::runtime_error("allocate_buffer found non-gr_block"); + int item_size = block->output_signature()->sizeof_stream_item(port); + int nitems = s_fixed_buffer_size/item_size; + + // Make sure there are at least twice the output_multiple no. of items + if (nitems < 2*grblock->output_multiple()) // Note: this means output_multiple() + nitems = 2*grblock->output_multiple(); // can't be changed by block dynamically + + // If any downstream blocks are decimators and/or have a large output_multiple, + // ensure we have a buffer at least twice their decimation factor*output_multiple + gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + gr_block_sptr dgrblock(boost::dynamic_pointer_cast(*p)); + if (!dgrblock) + throw std::runtime_error("allocate_buffer found non-gr_block"); + int decimation = (int)(1.0/dgrblock->relative_rate()); + int multiple = dgrblock->output_multiple(); + int history = dgrblock->history(); + nitems = std::max(nitems, 2*(decimation*multiple+history)); + } + + return gr_make_buffer(nitems, item_size); } -gr_block_vector_t -gr_simple_flowgraph_detail::calc_downstream_blocks(const std::string &name, int port) +gr_basic_block_vector_t +gr_simple_flowgraph_detail::calc_downstream_blocks(gr_basic_block_sptr block, int port) { - gr_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); + gr_basic_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if ((*p)->src_name() == name && (*p)->src_port() == port) - tmp.push_back(lookup_block((*p)->dst_name())); + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if ((*p)->src().block() == block && (*p)->src().port() == port) + tmp.push_back((*p)->dst().block()); - // Remove duplicates - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; + // Remove duplicates + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; } -gr_block_vector_t -gr_simple_flowgraph_detail::calc_downstream_blocks(const std::string &name) +gr_basic_block_vector_t +gr_simple_flowgraph_detail::calc_downstream_blocks(gr_basic_block_sptr block) { - gr_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); + gr_basic_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if ((*p)->src_name() == name) - tmp.push_back(lookup_block((*p)->dst_name())); + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if ((*p)->src().block() == block) + tmp.push_back((*p)->dst().block()); - // Remove duplicates - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; + // Remove duplicates + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; } gr_edge_vector_t -gr_simple_flowgraph_detail::calc_upstream_edges(const std::string &name) +gr_simple_flowgraph_detail::calc_upstream_edges(gr_basic_block_sptr block) { - gr_edge_vector_t result; + gr_edge_vector_t result; - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if ((*p)->dst_name() == name) - result.push_back(*p); + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if ((*p)->dst().block() == block) + result.push_back(*p); - return result; // Assume no duplicates + return result; // Assume no duplicates } -gr_block_vector_t +gr_basic_block_vector_t gr_simple_flowgraph_detail::calc_used_blocks() { - std::vector tmp, tmp_unique; - std::insert_iterator > inserter(tmp_unique, tmp_unique.begin()); - gr_block_vector_t result; + gr_basic_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - tmp.push_back((*p)->src_name()); - tmp.push_back((*p)->dst_name()); - } - - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - - for (std::vector::iterator p = tmp_unique.begin(); - p != tmp_unique.end(); p++) - result.push_back(lookup_block(*p)); - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Flowgraph uses " << result.size() - << " distinct blocks." << std::endl; + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + tmp.push_back((*p)->src().block()); + tmp.push_back((*p)->dst().block()); + } - return result; + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; } std::vector gr_simple_flowgraph_detail::partition() { - std::vector result; - gr_block_vector_t blocks = calc_used_blocks(); - gr_block_vector_t graph; + std::vector result; + gr_basic_block_vector_t blocks = calc_used_blocks(); + gr_basic_block_vector_t graph; - while (blocks.size() > 0) { - graph = calc_reachable_blocks(blocks[0], blocks); - assert(graph.size()); - result.push_back(topological_sort(graph)); + while (blocks.size() > 0) { + graph = calc_reachable_blocks(blocks[0], blocks); + assert(graph.size()); + result.push_back(topological_sort(graph)); - for (gr_block_viter_t p = graph.begin(); p != graph.end(); p++) - blocks.erase(find(blocks.begin(), blocks.end(), *p)); - } + for (gr_basic_block_viter_t p = graph.begin(); p != graph.end(); p++) + blocks.erase(find(blocks.begin(), blocks.end(), *p)); + } - return result; + return result; } -gr_block_vector_t -gr_simple_flowgraph_detail::calc_reachable_blocks(gr_block_sptr block, gr_block_vector_t &blocks) +gr_basic_block_vector_t +gr_simple_flowgraph_detail::calc_reachable_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) { - gr_block_vector_t result; + gr_basic_block_vector_t result; - // Mark all blocks as unvisited - for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) - (*p)->detail()->set_color(gr_block_detail::WHITE); + // Mark all blocks as unvisited + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) + boost::dynamic_pointer_cast(*p)->detail()->set_color(gr_block_detail::WHITE); - // Recursively mark all reachable blocks - reachable_dfs_visit(block, blocks); + // Recursively mark all reachable blocks + reachable_dfs_visit(block, blocks); - // Collect all the blocks that have been visited - for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) - if ((*p)->detail()->color() == gr_block_detail::BLACK) - result.push_back(*p); + // Collect all the blocks that have been visited + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) + if ((boost::dynamic_pointer_cast(*p))->detail()->color() == gr_block_detail::BLACK) + result.push_back(*p); - return result; + return result; } // Recursively mark all reachable blocks from given block and block list void -gr_simple_flowgraph_detail::reachable_dfs_visit(gr_block_sptr block, gr_block_vector_t &blocks) +gr_simple_flowgraph_detail::reachable_dfs_visit(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) { - // Mark the current one as visited - block->detail()->set_color(gr_block_detail::BLACK); + // Mark the current one as visited + boost::dynamic_pointer_cast(block)->detail()->set_color(gr_block_detail::BLACK); - // Recurse into adjacent vertices - gr_block_vector_t adjacent = calc_adjacent_blocks(block, blocks); + // Recurse into adjacent vertices + gr_basic_block_vector_t adjacent = calc_adjacent_blocks(block, blocks); - for (gr_block_viter_t p = adjacent.begin(); p != adjacent.end(); p++) - if ((*p)->detail()->color() == gr_block_detail::WHITE) - reachable_dfs_visit(*p, blocks); + for (gr_basic_block_viter_t p = adjacent.begin(); p != adjacent.end(); p++) + if (boost::dynamic_pointer_cast(*p)->detail()->color() == gr_block_detail::WHITE) + reachable_dfs_visit(*p, blocks); } // Return a list of block adjacent to a given block along any edge -gr_block_vector_t -gr_simple_flowgraph_detail::calc_adjacent_blocks(gr_block_sptr block, gr_block_vector_t &blocks) +gr_basic_block_vector_t +gr_simple_flowgraph_detail::calc_adjacent_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) { - gr_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); + gr_basic_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); - // Find any blocks that are inputs or outputs - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - if (lookup_block((*p)->src_name()) == block) - tmp.push_back(lookup_block((*p)->dst_name())); - if (lookup_block((*p)->dst_name()) == block) - tmp.push_back(lookup_block((*p)->src_name())); - } - - // Remove duplicates - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; + // Find any blocks that are inputs or outputs + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + + if ((*p)->src().block() == block) + tmp.push_back((*p)->dst().block()); + if ((*p)->dst().block() == block) + tmp.push_back((*p)->src().block()); + } + + // Remove duplicates + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; } gr_block_vector_t -gr_simple_flowgraph_detail::topological_sort(gr_block_vector_t &blocks) +gr_simple_flowgraph_detail::topological_sort(gr_basic_block_vector_t &blocks) { - gr_block_vector_t result, tmp; - tmp = sort_sources_first(blocks); + gr_basic_block_vector_t tmp; + gr_block_vector_t result; + tmp = sort_sources_first(blocks); - // Start 'em all white - for (gr_block_viter_t p = tmp.begin(); p != tmp.end(); p++) - (*p)->detail()->set_color(gr_block_detail::WHITE); + // Start 'em all white + for (gr_basic_block_viter_t p = tmp.begin(); p != tmp.end(); p++) + boost::dynamic_pointer_cast(*p)->detail()->set_color(gr_block_detail::WHITE); - for (gr_block_viter_t p = tmp.begin(); p != tmp.end(); p++) { - if ((*p)->detail()->color() == gr_block_detail::WHITE) - topological_dfs_visit(*p, result); - } + for (gr_basic_block_viter_t p = tmp.begin(); p != tmp.end(); p++) { + if (boost::dynamic_pointer_cast(*p)->detail()->color() == gr_block_detail::WHITE) + topological_dfs_visit(*p, result); + } - reverse(result.begin(), result.end()); + reverse(result.begin(), result.end()); - return result; + return result; } bool -gr_simple_flowgraph_detail::source_p(gr_block_sptr block) +gr_simple_flowgraph_detail::source_p(gr_basic_block_sptr block) { - return (calc_upstream_edges(lookup_name(block)).size() == 0); + return (calc_upstream_edges(block).size() == 0); } -gr_block_vector_t -gr_simple_flowgraph_detail::sort_sources_first(gr_block_vector_t &blocks) +gr_basic_block_vector_t +gr_simple_flowgraph_detail::sort_sources_first(gr_basic_block_vector_t &blocks) { - gr_block_vector_t sources, nonsources, result; + gr_basic_block_vector_t sources, nonsources, result; - for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - if (source_p(*p)) - sources.push_back(*p); - else - nonsources.push_back(*p); - } + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + if (source_p(*p)) + sources.push_back(*p); + else + nonsources.push_back(*p); + } - for (gr_block_viter_t p = sources.begin(); p != sources.end(); p++) - result.push_back(*p); + for (gr_basic_block_viter_t p = sources.begin(); p != sources.end(); p++) + result.push_back(*p); - for (gr_block_viter_t p = nonsources.begin(); p != nonsources.end(); p++) - result.push_back(*p); + for (gr_basic_block_viter_t p = nonsources.begin(); p != nonsources.end(); p++) + result.push_back(*p); - return result; + return result; } void -gr_simple_flowgraph_detail::topological_dfs_visit(gr_block_sptr block, gr_block_vector_t &output) +gr_simple_flowgraph_detail::topological_dfs_visit(gr_basic_block_sptr block, gr_block_vector_t &output) { - block->detail()->set_color(gr_block_detail::GREY); + boost::dynamic_pointer_cast(block)->detail()->set_color(gr_block_detail::GREY); - gr_block_vector_t blocks(calc_downstream_blocks(lookup_name(block))); + gr_basic_block_vector_t blocks(calc_downstream_blocks(block)); - for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - switch ((*p)->detail()->color()) { - case gr_block_detail::WHITE: - topological_dfs_visit(*p, output); - break; + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + switch (boost::dynamic_pointer_cast(*p)->detail()->color()) { + case gr_block_detail::WHITE: + topological_dfs_visit(*p, output); + break; - case gr_block_detail::GREY: - throw std::runtime_error("flow graph has loops!"); + case gr_block_detail::GREY: + throw std::runtime_error("flow graph has loops!"); - case gr_block_detail::BLACK: - continue; + case gr_block_detail::BLACK: + continue; - default: - throw std::runtime_error("invalid color on block!"); - } + default: + throw std::runtime_error("invalid color on block!"); } + } - block->detail()->set_color(gr_block_detail::BLACK); - output.push_back(block); + gr_block_sptr result_block(boost::dynamic_pointer_cast(block)); + + result_block->detail()->set_color(gr_block_detail::BLACK); + output.push_back(result_block); +} + +void +gr_simple_flowgraph_detail::merge_connections(gr_simple_flowgraph_sptr sfg) +{ + // NOT IMPLEMENTED } diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h index 2df1575ad..6e9058bba 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,48 +23,30 @@ #ifndef INCLUDED_GR_SIMPLE_FLOWGRAPH_DETAIL_H #define INCLUDED_GR_SIMPLE_FLOWGRAPH_DETAIL_H -#include -#include +#include +#include +#include #define GR_FIXED_BUFFER_SIZE (32*(1L<<10)) -typedef std::map gr_component_map_t; -typedef std::map::iterator gr_component_miter_t; - -class gr_endpoint -{ -private: - std::string d_name; - int d_port; - -public: - gr_endpoint(const std::string &name, int port) { d_name = name; d_port = port; } - const std::string &name() const { return d_name; } - int port() const { return d_port; } -}; - class gr_edge; typedef boost::shared_ptr gr_edge_sptr; -gr_edge_sptr gr_make_edge(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port); +gr_edge_sptr gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst); class gr_edge { private: - friend gr_edge_sptr gr_make_edge(const std::string &src_name, int src_port, - const std::string &dst_name, int dst_port); - gr_edge(const std::string &name, int src_port, - const std::string &name, int dst_port); + friend gr_edge_sptr gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst); + gr_edge(const gr_endpoint &src, const gr_endpoint &dst) : d_src(src), d_dst(dst) { } - gr_endpoint d_src; - gr_endpoint d_dst; + gr_endpoint d_src; + gr_endpoint d_dst; public: - ~gr_edge(); - const std::string src_name() const { return d_src.name(); } - const std::string dst_name() const { return d_dst.name(); } - int src_port() const { return d_src.port(); } - int dst_port() const { return d_dst.port(); } + ~gr_edge(); + + const gr_endpoint &src() const { return d_src; } + const gr_endpoint &dst() const { return d_dst; } }; typedef std::vector gr_edge_vector_t; @@ -73,63 +55,68 @@ typedef std::vector::iterator gr_edge_viter_t; class gr_simple_flowgraph_detail { private: - friend class gr_simple_flowgraph; - friend class gr_runtime_impl; - friend class topo_block_cmp; + friend class gr_simple_flowgraph; + friend class gr_runtime_impl; + friend class gr_hier_block2_detail; + friend class topo_block_cmp; - gr_simple_flowgraph_detail(); + gr_simple_flowgraph_detail() : d_blocks(), d_edges() { } - gr_component_map_t d_components; - gr_edge_vector_t d_edges; - static const unsigned int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE; + gr_basic_block_vector_t d_blocks; + gr_edge_vector_t d_edges; + static const unsigned int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE; - void reset(); - void define_component(const std::string &name, gr_block_sptr block); - void connect(const std::string &src, int src_port, - const std::string &dst, int dst_port); - gr_block_sptr lookup_block(const std::string &name); - std::string lookup_name(const gr_block_sptr block); - - void check_valid_port(gr_io_signature_sptr sig, int port); - void check_dst_not_used(const std::string &name, int port); - void check_type_match(gr_block_sptr src_block, int src_port, - gr_block_sptr dst_block, int dst_port); - void validate(); - gr_edge_vector_t calc_connections(const std::string &name, bool check_inputs); // false=use outputs - std::vector calc_used_ports(const std::string &name, bool check_inputs); - void check_contiguity(gr_block_sptr block, const std::vector &used_ports, - bool check_inputs); - void setup_connections(); - gr_buffer_sptr allocate_buffer(const std::string &name, int port); - gr_block_vector_t calc_downstream_blocks(const std::string &name, int port); - gr_block_vector_t calc_downstream_blocks(const std::string &name); - gr_edge_vector_t calc_upstream_edges(const std::string &name); - gr_block_vector_t calc_used_blocks(); - std::vector partition(); - gr_block_vector_t calc_reachable_blocks(gr_block_sptr block, gr_block_vector_t &blocks); - gr_block_vector_t topological_sort(gr_block_vector_t &blocks); - void reachable_dfs_visit(gr_block_sptr block, gr_block_vector_t &blocks); - gr_block_vector_t calc_adjacent_blocks(gr_block_sptr block, gr_block_vector_t &blocks); - bool source_p(gr_block_sptr block); - gr_block_vector_t sort_sources_first(gr_block_vector_t &blocks); - void topological_dfs_visit(gr_block_sptr block, gr_block_vector_t &output); + void reset(); + void connect(const gr_endpoint &src, const gr_endpoint &dst); + void disconnect(const gr_endpoint &src, const gr_endpoint &dst); + void check_valid_port(gr_io_signature_sptr sig, int port); + void check_dst_not_used(const gr_endpoint &dst); + void check_type_match(const gr_endpoint &src, const gr_endpoint &dst); + void validate(); + gr_edge_vector_t calc_connections(gr_basic_block_sptr block, bool check_inputs); // false=use outputs + std::vector calc_used_ports(gr_basic_block_sptr block, bool check_inputs); + void check_contiguity(gr_basic_block_sptr block, const std::vector &used_ports, bool check_inputs); + void setup_connections(); + void merge_connections(gr_simple_flowgraph_sptr sfg); + + gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port); + gr_basic_block_vector_t calc_downstream_blocks(gr_basic_block_sptr block, int port); + gr_basic_block_vector_t calc_downstream_blocks(gr_basic_block_sptr block); + gr_edge_vector_t calc_upstream_edges(gr_basic_block_sptr block); + gr_basic_block_vector_t calc_used_blocks(); + std::vector partition(); + gr_basic_block_vector_t calc_reachable_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks); + gr_block_vector_t topological_sort(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); + bool source_p(gr_basic_block_sptr block); + gr_basic_block_vector_t sort_sources_first(gr_basic_block_vector_t &blocks); + void topological_dfs_visit(gr_basic_block_sptr block, gr_block_vector_t &output); public: - ~gr_simple_flowgraph_detail(); + ~gr_simple_flowgraph_detail(); }; inline std::ostream& -operator <<(std::ostream& os, const gr_block_sptr p) +operator <<(std::ostream &os, const gr_endpoint endp) { - os << "name() << " (" << p->unique_id() << ")>"; - return os; + os << endp.block()->name() << ":" << endp.port(); + return os; } inline std::ostream& -operator <<(std::ostream &os, const gr_endpoint endp) +operator <<(std::ostream &os, const gr_edge_sptr edge) +{ + os << edge->src() << "->" << edge->dst(); + return os; +} + +inline void +enumerate_edges(gr_edge_vector_t &edges) { - os << endp.name() << ":" << endp.port(); - return os; + std::cout << "Edge list has " << edges.size() << " elements" << std::endl; + for(gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) + std::cout << *p << std::endl; } #endif /* INCLUDED_GR_SIMPLE_FLOWGRAPH_H */ diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index cab338630..caa2166e0 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -48,7 +47,6 @@ %include %include %include -%include %include %include %include -- cgit From ba0df61e210f962ad9b1429437558ef6dfa9dc10 Mon Sep 17 00:00:00 2001 From: n4hy Date: Sat, 28 Apr 2007 16:01:09 +0000 Subject: replacing needed file git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5183 221aa14e-8319-0410-a670-987f0aec2ac5 --- .../src/lib/runtime/gr_simple_flowgraph.i | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i new file mode 100644 index 000000000..c3654fe50 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i @@ -0,0 +1,45 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +class gr_simple_flowgraph; +typedef boost::shared_ptr gr_simple_flowgraph_sptr; +%template(gr_simple_flowgraph_sptr) boost::shared_ptr; +%rename(simple_flowgraph) gr_make_simple_flowgraph; +%ignore gr_simple_flowgraph; + +gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); + +class gr_simple_flowgraph +{ +private: + gr_simple_flowgraph(); + +public: + ~gr_simple_flowgraph(); + void define_component(const std::string name, gr_block_sptr block) + throw (std::invalid_argument); + void connect(const std::string &src, int src_port, + const std::string &dst, int dst_port) + throw (std::invalid_argument); + void validate() + throw (std::runtime_error); +}; -- cgit From 1350802218d8e718ad6615f37fb9e8fec6fa739f Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 28 Apr 2007 16:05:10 +0000 Subject: Reverting changeset r5183, not needed. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5184 221aa14e-8319-0410-a670-987f0aec2ac5 --- .../src/lib/runtime/gr_simple_flowgraph.i | 45 ---------------------- 1 file changed, 45 deletions(-) delete mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i deleted file mode 100644 index c3654fe50..000000000 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.i +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 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 2, 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -class gr_simple_flowgraph; -typedef boost::shared_ptr gr_simple_flowgraph_sptr; -%template(gr_simple_flowgraph_sptr) boost::shared_ptr; -%rename(simple_flowgraph) gr_make_simple_flowgraph; -%ignore gr_simple_flowgraph; - -gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); - -class gr_simple_flowgraph -{ -private: - gr_simple_flowgraph(); - -public: - ~gr_simple_flowgraph(); - void define_component(const std::string name, gr_block_sptr block) - throw (std::invalid_argument); - void connect(const std::string &src, int src_port, - const std::string &dst, int dst_port) - throw (std::invalid_argument); - void validate() - throw (std::runtime_error); -}; -- cgit From 0ad83f0492d51806e6bf30a89f04affda3a71ca2 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 4 May 2007 21:50:13 +0000 Subject: Merged r5230:5237 from jcorgan/disc2. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5238 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_block_detail.h | 8 + gnuradio-core/src/lib/runtime/gr_block_detail.i | 8 + gnuradio-core/src/lib/runtime/gr_buffer.h | 6 + .../src/lib/runtime/gr_hier_block2_detail.cc | 48 +++- .../src/lib/runtime/gr_hier_block2_detail.h | 6 +- gnuradio-core/src/lib/runtime/gr_runtime.cc | 25 +- gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 70 +++++- gnuradio-core/src/lib/runtime/gr_runtime_impl.h | 1 + .../src/lib/runtime/gr_simple_flowgraph.h | 1 + .../src/lib/runtime/gr_simple_flowgraph_detail.cc | 270 +++++++++++++++------ .../src/lib/runtime/gr_simple_flowgraph_detail.h | 9 +- 11 files changed, 336 insertions(+), 116 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index d89b7fea1..9aa5ef4b0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -55,6 +55,14 @@ class gr_block_detail { return d_input[which]; } + void clear_input (unsigned int which) + { + if (which >= d_ninputs) + throw std::invalid_argument ("gr_block_detail::input"); + if (d_input[which]) + d_input[which].reset(); + } + void set_output (unsigned int which, gr_buffer_sptr buffer); gr_buffer_sptr output (unsigned int which) { diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.i b/gnuradio-core/src/lib/runtime/gr_block_detail.i index 9ac5ae96d..6a01482c6 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.i +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.i @@ -46,6 +46,14 @@ class gr_block_detail { return d_input[which]; } + void clear_input (unsigned int which) + { + if (which >= d_ninputs) + throw std::invalid_argument ("gr_block_detail::input"); + if (d_input[which]) + d_input[which].reset(); + } + void set_output (unsigned int which, gr_buffer_sptr buffer); gr_buffer_sptr output (unsigned int which) { diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 46017f6ad..51474c0e7 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -156,6 +156,12 @@ class gr_buffer_reader { */ int items_available () const; + /*! + * \brief Return buffer this reader reads from. + */ + gr_buffer_sptr buffer () const { return d_buffer; } + + /*! * \brief Return maximum number of items that could ever be available for reading. * This is used as a sanity check in the scheduler to avoid looping forever. diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index b41d0c65c..af029bdc7 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -55,20 +55,20 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, if (src.get() == dst.get()) throw std::invalid_argument("src and destination blocks cannot be the same"); - // Assignments to block inputs or outputs + // Connectments to block inputs or outputs int max_port; if (src.get() == d_owner) { max_port = src->input_signature()->max_streams(); if ((max_port != -1 && (src_port >= max_port)) || src_port < 0) throw std::invalid_argument("source port out of range"); - return assign_input(src_port, dst_port, dst); + return connect_input(src_port, dst_port, dst); } if (dst.get() == d_owner) { max_port = dst->output_signature()->max_streams(); if ((max_port != -1 && (dst_port >= max_port)) || dst_port < 0) throw std::invalid_argument("source port out of range"); - return assign_output(dst_port, src_port, src); + return connect_output(dst_port, src_port, src); } // Internal connections @@ -81,13 +81,25 @@ void gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { - // Handle disconnecting inputs and outputs + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "disconnecting: " << gr_endpoint(src, src_port) + << " -> " << gr_endpoint(dst, dst_port) << std::endl; + + if (src.get() == dst.get()) + throw std::invalid_argument("src and destination blocks cannot be the same"); + + if (src.get() == d_owner) + return disconnect_input(src_port, dst_port, dst); + if (dst.get() == d_owner) + return disconnect_output(dst_port, src_port, src); + + // Internal connections d_fg->disconnect(src, src_port, dst, dst_port); } void -gr_hier_block2_detail::assign_input(int my_port, int port, gr_basic_block_sptr block) +gr_hier_block2_detail::connect_input(int my_port, int port, gr_basic_block_sptr block) { if (my_port < 0 || my_port >= (signed)d_inputs.size()) throw std::invalid_argument("input port number out of range"); @@ -99,7 +111,7 @@ gr_hier_block2_detail::assign_input(int my_port, int port, gr_basic_block_sptr b } void -gr_hier_block2_detail::assign_output(int my_port, int port, gr_basic_block_sptr block) +gr_hier_block2_detail::connect_output(int my_port, int port, gr_basic_block_sptr block) { if (my_port < 0 || my_port >= (signed)d_outputs.size()) throw std::invalid_argument("output port number out of range"); @@ -110,6 +122,30 @@ gr_hier_block2_detail::assign_output(int my_port, int port, gr_basic_block_sptr d_outputs[my_port] = gr_endpoint(block, port); } +void +gr_hier_block2_detail::disconnect_input(int my_port, int port, gr_basic_block_sptr block) +{ + if (my_port < 0 || my_port >= (signed)d_inputs.size()) + throw std::invalid_argument("input port number out of range"); + + if (d_inputs[my_port].block() != block) + throw std::invalid_argument("block not assigned to given input, can't disconnect"); + + d_inputs[my_port] = gr_endpoint(); +} + +void +gr_hier_block2_detail::disconnect_output(int my_port, int port, gr_basic_block_sptr block) +{ + if (my_port < 0 || my_port >= (signed)d_outputs.size()) + throw std::invalid_argument("input port number out of range"); + + if (d_outputs[my_port].block() != block) + throw std::invalid_argument("block not assigned to given output, can't disconnect"); + + d_outputs[my_port] = gr_endpoint(); +} + gr_endpoint gr_hier_block2_detail::resolve_port(int port, bool is_input) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index f0e7b7e82..15c8548c6 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -45,8 +45,10 @@ private: gr_basic_block_sptr dst, int dst_port); void disconnect(gr_basic_block_sptr, int src_port, gr_basic_block_sptr, int dst_port); - void assign_input(int my_port, int port, gr_basic_block_sptr block); - void assign_output(int my_port, int port, gr_basic_block_sptr block); + void connect_input(int my_port, int port, gr_basic_block_sptr block); + void connect_output(int my_port, int port, gr_basic_block_sptr block); + void disconnect_input(int my_port, int port, gr_basic_block_sptr block); + void disconnect_output(int my_port, int port, gr_basic_block_sptr block); void flatten(gr_simple_flowgraph_sptr sfg); gr_endpoint resolve_port(int port, bool is_input); gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input); diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.cc b/gnuradio-core/src/lib/runtime/gr_runtime.cc index a8b932f21..3a992f689 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime.cc @@ -26,11 +26,8 @@ #include #include -#include #include -static gr_runtime *s_runtime = 0; - gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block) { @@ -40,28 +37,16 @@ gr_make_runtime(gr_hier_block2_sptr top_block) gr_runtime::gr_runtime(gr_hier_block2_sptr top_block) { d_impl = new gr_runtime_impl(top_block); - s_runtime = this; } gr_runtime::~gr_runtime() { - s_runtime = 0; // we don't own this delete d_impl; } -// FIXME: This prevents using more than one gr_runtime instance -static void -runtime_sigint_handler(int signum) -{ - if (s_runtime) - s_runtime->stop(); -} - void gr_runtime::start() { - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - d_impl->start(); } @@ -74,24 +59,18 @@ gr_runtime::stop() void gr_runtime::wait() { - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - d_impl->wait(); } void gr_runtime::run() { - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - - d_impl->start(); - d_impl->wait(); + start(); + wait(); } void gr_runtime::restart() { - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - d_impl->restart(); } diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc index 5cd75f3ce..64fbca9c9 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,10 +24,12 @@ #include "config.h" #endif +#include #include #include #include #include +#include #ifdef HAVE_SIGNAL_H #include @@ -36,24 +38,42 @@ #include #include +#define GR_RUNTIME_IMPL_DEBUG 1 + +static gr_runtime_impl *s_runtime = 0; + +// FIXME: This prevents using more than one gr_runtime instance +void +runtime_sigint_handler(int signum) +{ + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "SIGINT received, calling stop() on all threads" << std::endl; + + if (s_runtime) + s_runtime->stop(); +} + gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) : d_running(false), d_top_block(top_block), d_sfg(gr_make_simple_flowgraph()) { + s_runtime = this; } gr_runtime_impl::~gr_runtime_impl() { + s_runtime = 0; // we don't own this } void gr_runtime_impl::start() { + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "start: entered" << std::endl; + if (d_running) throw std::runtime_error("already running"); - else - d_running = true; // Create new simple flow graph by flattening hierarchical block d_sfg->d_detail->reset(); @@ -70,24 +90,33 @@ gr_runtime_impl::start() void gr_runtime_impl::start_threads() { + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "start_threads: entered" << std::endl; + d_graphs = d_sfg->d_detail->partition(); - d_threads.clear(); for (std::vector::iterator p = d_graphs.begin(); p != d_graphs.end(); p++) { gr_scheduler_thread *thread = new gr_scheduler_thread(*p); - thread->start(); d_threads.push_back(thread); + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "start_threads: starting " << thread << std::endl; + thread->start(); } + + d_running = true; } void gr_runtime_impl::stop() { - if (!d_running) - throw std::runtime_error("not running"); + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "stop: entered" << std::endl; - for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) - (*p)->stop(); + for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "stop: stopping thread " << (*p) << std::endl; + (*p)->stop(); + } d_running = false; } @@ -95,30 +124,48 @@ gr_runtime_impl::stop() void gr_runtime_impl::wait() { + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "wait: entered" << std::endl; + void *dummy_status; // don't ever dereference this + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "wait: joining thread " << (*p) << std::endl; (*p)->join(&dummy_status); // pthreads will self-delete, so pointer is now dead (*p) = 0; // FIXME: switch to stl::list and actually remove from container + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "wait: join returned" << std::endl; } + + d_threads.clear(); } void gr_runtime_impl::restart() { + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "restart: entered" << std::endl; + if (!d_running) throw std::runtime_error("not running"); // Stop scheduler threads and wait for completion stop(); wait(); - + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "restart: threads stopped" << std::endl; + // Create new simple flow graph gr_simple_flowgraph_sptr new_sfg = gr_make_simple_flowgraph(); d_top_block->d_detail->flatten(new_sfg); new_sfg->validate(); new_sfg->d_detail->merge_connections(d_sfg); - // d_sfg = new_sfg; + + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "restart: replacing old flow graph with new" << std::endl; + d_sfg = new_sfg; start_threads(); } @@ -161,3 +208,4 @@ gr_scheduler_thread::stop() { d_sts->stop(); } + diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h index bb2a08334..0fb6e1f0d 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h @@ -67,6 +67,7 @@ class gr_runtime_impl { private: gr_runtime_impl(gr_hier_block2_sptr top_block); + friend void runtime_sigint_handler(int signum); friend class gr_runtime; bool d_running; diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h index a22e558ff..04b83c8cc 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h @@ -62,6 +62,7 @@ class gr_simple_flowgraph { private: friend class gr_runtime_impl; + friend class gr_simple_flowgraph_detail; friend class gr_hier_block2_detail; friend gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); gr_simple_flowgraph(); diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc index 13d23efe5..a725adb6e 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc @@ -31,6 +31,9 @@ #include #include #include +#include + +#define GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG 1 gr_edge_sptr gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst) @@ -115,6 +118,9 @@ gr_simple_flowgraph_detail::validate() std::vector used_ports; int ninputs, noutputs; + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Validating block: " << (*p) << std::endl; + used_ports = calc_used_ports(*p, true); // inputs ninputs = used_ports.size(); check_contiguity(*p, used_ports, true); // inputs @@ -192,76 +198,6 @@ gr_simple_flowgraph_detail::check_contiguity(gr_basic_block_sptr block, } } -void -gr_simple_flowgraph_detail::setup_connections() -{ - // Assign block details to blocks - for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { - int ninputs = calc_used_ports(*p, true).size(); - int noutputs = calc_used_ports(*p, false).size(); - gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); - for (int i = 0; i < noutputs; i++) - detail->set_output(i, allocate_buffer(*p, i)); - - boost::dynamic_pointer_cast(*p)->set_detail(detail); - } - - // Connect inputs to outputs for each block - for(gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { - gr_block_sptr grblock(boost::dynamic_pointer_cast(*p)); - if (!grblock) - throw std::runtime_error("setup_connections found non-gr_block"); - - // Get its detail and edges that feed into it - gr_block_detail_sptr detail = grblock->detail(); - gr_edge_vector_t in_edges = calc_upstream_edges(*p); - - // For each edge that feeds into it - for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) { - // Set the input reader on the destination port to the output - // buffer on the source port - int dst_port = (*e)->dst().port(); - int src_port = (*e)->src().port(); - gr_basic_block_sptr src_block = (*e)->src().block(); - gr_block_sptr src_grblock(boost::dynamic_pointer_cast(src_block)); - if (!grblock) - throw std::runtime_error("setup_connections found non-gr_block"); - gr_buffer_sptr src_buffer = src_grblock->detail()->output(src_port); - - detail->set_input(dst_port, gr_buffer_add_reader(src_buffer, grblock->history()-1)); - } - } -} - -gr_buffer_sptr -gr_simple_flowgraph_detail::allocate_buffer(gr_basic_block_sptr block, int port) -{ - gr_block_sptr grblock(boost::dynamic_pointer_cast(block)); - if (!grblock) - throw std::runtime_error("allocate_buffer found non-gr_block"); - int item_size = block->output_signature()->sizeof_stream_item(port); - int nitems = s_fixed_buffer_size/item_size; - - // Make sure there are at least twice the output_multiple no. of items - if (nitems < 2*grblock->output_multiple()) // Note: this means output_multiple() - nitems = 2*grblock->output_multiple(); // can't be changed by block dynamically - - // If any downstream blocks are decimators and/or have a large output_multiple, - // ensure we have a buffer at least twice their decimation factor*output_multiple - gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); - for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - gr_block_sptr dgrblock(boost::dynamic_pointer_cast(*p)); - if (!dgrblock) - throw std::runtime_error("allocate_buffer found non-gr_block"); - int decimation = (int)(1.0/dgrblock->relative_rate()); - int multiple = dgrblock->output_multiple(); - int history = dgrblock->history(); - nitems = std::max(nitems, 2*(decimation*multiple+history)); - } - - return gr_make_buffer(nitems, item_size); -} - gr_basic_block_vector_t gr_simple_flowgraph_detail::calc_downstream_blocks(gr_basic_block_sptr block, int port) { @@ -476,8 +412,198 @@ gr_simple_flowgraph_detail::topological_dfs_visit(gr_basic_block_sptr block, gr_ output.push_back(result_block); } +bool +gr_simple_flowgraph_detail::has_block_p(gr_basic_block_sptr block) +{ + gr_basic_block_viter_t result; + result = std::find(d_blocks.begin(), d_blocks.end(), block); + return (result != d_blocks.end()); +} + +gr_edge_sptr +gr_simple_flowgraph_detail::calc_upstream_edge(gr_basic_block_sptr block, int port) +{ + gr_edge_sptr result; + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + if ((*p)->dst().block() == block && (*p)->dst().port() == port) { + result = (*p); + break; + } + } + + return result; +} + +gr_block_detail_sptr +gr_simple_flowgraph_detail::allocate_block_detail(gr_basic_block_sptr block, gr_block_detail_sptr old_detail) +{ + int ninputs = calc_used_ports(block, true).size(); + int noutputs = calc_used_ports(block, false).size(); + gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Creating block detail for " << block << std::endl; + + // Re-use or allocate output buffers + for (int i = 0; i < noutputs; i++) { + gr_buffer_sptr buffer; + + if (!old_detail || i >= old_detail->noutputs()) { + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Allocating new buffer for output " << i << std::endl; + buffer = allocate_buffer(block, i); + } + else { + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Reusing old buffer for output " << i << std::endl; + buffer = old_detail->output(i); + } + + detail->set_output(i, buffer); + } + + return detail; +} + void -gr_simple_flowgraph_detail::merge_connections(gr_simple_flowgraph_sptr sfg) +gr_simple_flowgraph_detail::connect_block_inputs(gr_basic_block_sptr block) +{ + gr_block_sptr grblock(boost::dynamic_pointer_cast(block)); + if (!grblock) + throw std::runtime_error("found non-gr_block"); + + // Get its detail and edges that feed into it + gr_block_detail_sptr detail = grblock->detail(); + gr_edge_vector_t in_edges = calc_upstream_edges(block); + + // For each edge that feeds into it + for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) { + // Set the buffer reader on the destination port to the output + // buffer on the source port + int dst_port = (*e)->dst().port(); + int src_port = (*e)->src().port(); + gr_basic_block_sptr src_block = (*e)->src().block(); + gr_block_sptr src_grblock(boost::dynamic_pointer_cast(src_block)); + if (!grblock) + throw std::runtime_error("found non-gr_block"); + gr_buffer_sptr src_buffer = src_grblock->detail()->output(src_port); + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Setting input " << dst_port << " from edge " << (*e) << std::endl; + + detail->set_input(dst_port, gr_buffer_add_reader(src_buffer, grblock->history()-1)); + } +} + +gr_buffer_sptr +gr_simple_flowgraph_detail::allocate_buffer(gr_basic_block_sptr block, int port) { - // NOT IMPLEMENTED + gr_block_sptr grblock(boost::dynamic_pointer_cast(block)); + if (!grblock) + throw std::runtime_error("allocate_buffer found non-gr_block"); + int item_size = block->output_signature()->sizeof_stream_item(port); + int nitems = s_fixed_buffer_size/item_size; + + // Make sure there are at least twice the output_multiple no. of items + if (nitems < 2*grblock->output_multiple()) // Note: this means output_multiple() + nitems = 2*grblock->output_multiple(); // can't be changed by block dynamically + + // If any downstream blocks are decimators and/or have a large output_multiple, + // ensure we have a buffer at least twice their decimation factor*output_multiple + gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + gr_block_sptr dgrblock(boost::dynamic_pointer_cast(*p)); + if (!dgrblock) + throw std::runtime_error("allocate_buffer found non-gr_block"); + int decimation = (int)(1.0/dgrblock->relative_rate()); + int multiple = dgrblock->output_multiple(); + int history = dgrblock->history(); + nitems = std::max(nitems, 2*(decimation*multiple+history)); + } + + return gr_make_buffer(nitems, item_size); +} + +void +gr_simple_flowgraph_detail::setup_connections() +{ + // Assign block details to blocks + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) + boost::dynamic_pointer_cast(*p)->set_detail(allocate_block_detail(*p)); + + // Connect inputs to outputs for each block + for(gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) + connect_block_inputs(*p); +} + +void +gr_simple_flowgraph_detail::merge_connections(gr_simple_flowgraph_sptr old_sfg) +{ + std::map old_details; + + // Allocate or reuse output buffers + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + gr_block_sptr block(boost::dynamic_pointer_cast(*p)); + + gr_block_detail_sptr old_detail = block->detail(); + block->set_detail(allocate_block_detail(block, old_detail)); + + // Save old detail for use in next step + old_details[block] = old_detail; + } + + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + gr_block_sptr block(boost::dynamic_pointer_cast(*p)); + + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "merge: testing " << (*p) << "..."; + + if (old_sfg->d_detail->has_block_p(*p)) { + // Block exists in old flow graph + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "used in old flow graph" << std::endl; + gr_block_detail_sptr detail = block->detail(); + + // Iterate through the inputs and see what needs to be done + for (int i = 0; i < detail->ninputs(); i++) { + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "Checking input " << i << "..."; + + gr_edge_sptr edge = calc_upstream_edge(*p, i); + if (!edge) + throw std::runtime_error("merge: missing input edge"); + + // Fish out old buffer reader and see if it matches correct buffer from edge list + gr_block_sptr src_block(boost::dynamic_pointer_cast(edge->src().block())); + gr_block_detail_sptr src_detail = src_block->detail(); + gr_buffer_sptr src_buffer = src_detail->output(edge->src().port()); + gr_buffer_reader_sptr old_reader; + gr_block_detail_sptr old_detail = old_details[block]; + if (old_detail && i < old_detail->ninputs()) + old_reader = old_detail->input(i); + + // If there's a match, use it + if (old_reader && (src_buffer == old_reader->buffer())) { + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "matched" << std::endl; + detail->set_input(i, old_reader); + + } + else { + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "needs a new reader" << std::endl; + + // Create new buffer reader and assign + detail->set_input(i, gr_buffer_add_reader(src_buffer, block->history()-1)); + } + } + } + else { + // Block is new, it just needs buffer readers at this point + if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) + std::cout << "new block" << std::endl; + connect_block_inputs(block); + } + } } diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h index 6e9058bba..5d01c38f0 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h @@ -79,9 +79,13 @@ private: void setup_connections(); void merge_connections(gr_simple_flowgraph_sptr sfg); + void connect_block_inputs(gr_basic_block_sptr block); + gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block, + gr_block_detail_sptr old_detail=gr_block_detail_sptr()); gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port); gr_basic_block_vector_t calc_downstream_blocks(gr_basic_block_sptr block, int port); gr_basic_block_vector_t calc_downstream_blocks(gr_basic_block_sptr block); + gr_edge_sptr calc_upstream_edge(gr_basic_block_sptr block, int port); gr_edge_vector_t calc_upstream_edges(gr_basic_block_sptr block); gr_basic_block_vector_t calc_used_blocks(); std::vector partition(); @@ -92,7 +96,8 @@ private: bool source_p(gr_basic_block_sptr block); gr_basic_block_vector_t sort_sources_first(gr_basic_block_vector_t &blocks); void topological_dfs_visit(gr_basic_block_sptr block, gr_block_vector_t &output); - + bool has_block_p(gr_basic_block_sptr block); + public: ~gr_simple_flowgraph_detail(); }; @@ -100,7 +105,7 @@ public: inline std::ostream& operator <<(std::ostream &os, const gr_endpoint endp) { - os << endp.block()->name() << ":" << endp.port(); + os << endp.block() << ":" << endp.port(); return os; } -- cgit From 6b1e25d6c62d82369548ecad4b86a0795be23025 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 4 May 2007 21:59:50 +0000 Subject: Post merge cleanup. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5239 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_block_detail.h | 8 -------- gnuradio-core/src/lib/runtime/gr_block_detail.i | 8 -------- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 2 +- 3 files changed, 1 insertion(+), 17 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 9aa5ef4b0..d89b7fea1 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -55,14 +55,6 @@ class gr_block_detail { return d_input[which]; } - void clear_input (unsigned int which) - { - if (which >= d_ninputs) - throw std::invalid_argument ("gr_block_detail::input"); - if (d_input[which]) - d_input[which].reset(); - } - void set_output (unsigned int which, gr_buffer_sptr buffer); gr_buffer_sptr output (unsigned int which) { diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.i b/gnuradio-core/src/lib/runtime/gr_block_detail.i index 6a01482c6..9ac5ae96d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.i +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.i @@ -46,14 +46,6 @@ class gr_block_detail { return d_input[which]; } - void clear_input (unsigned int which) - { - if (which >= d_ninputs) - throw std::invalid_argument ("gr_block_detail::input"); - if (d_input[which]) - d_input[which].reset(); - } - void set_output (unsigned int which, gr_buffer_sptr buffer); gr_buffer_sptr output (unsigned int which) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index af029bdc7..4e9380689 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -55,7 +55,7 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, if (src.get() == dst.get()) throw std::invalid_argument("src and destination blocks cannot be the same"); - // Connectments to block inputs or outputs + // Connections to block inputs or outputs int max_port; if (src.get() == d_owner) { max_port = src->input_signature()->max_streams(); -- cgit From b37d879f6b46225fab22862f193f10d1908400e1 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 5 May 2007 18:26:33 +0000 Subject: Merged r5241:5242 from jcorgan/reconf into trunk. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5243 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 22 ++++++++ gnuradio-core/src/lib/runtime/gr_hier_block2.h | 7 ++- gnuradio-core/src/lib/runtime/gr_hier_block2.i | 2 + .../src/lib/runtime/gr_hier_block2_detail.cc | 61 +++++++++++++++++++++- .../src/lib/runtime/gr_hier_block2_detail.h | 7 ++- gnuradio-core/src/lib/runtime/gr_runtime.cc | 15 +++++- gnuradio-core/src/lib/runtime/gr_runtime.h | 20 +++++++ gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 37 +++++++++++-- gnuradio-core/src/lib/runtime/gr_runtime_impl.h | 9 +++- 9 files changed, 170 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index d5ed4ccc9..9811b9def 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -29,6 +29,8 @@ #include #include +#define GR_HIER_BLOCK2_DEBUG 1 + gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature) @@ -62,3 +64,23 @@ gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, { d_detail->disconnect(src, src_port, dst, dst_port); } + +void +gr_hier_block2::set_runtime(gr_runtime *runtime) +{ + if (GR_HIER_BLOCK2_DEBUG) + std::cout << "Setting runtime on " << this << " to " << runtime << std::endl; + d_detail->set_runtime(runtime); +} + +void +gr_hier_block2::lock() +{ + d_detail->lock(); +} + +void +gr_hier_block2::unlock() +{ + d_detail->unlock(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 53a23bb47..da483098e 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -50,7 +50,10 @@ private: * \brief Private implementation details of gr_hier_block2 */ gr_hier_block2_detail *d_detail; - + + /* Internal use only */ + void set_runtime(gr_runtime *runtime); + protected: gr_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, @@ -63,6 +66,8 @@ public: gr_basic_block_sptr dst, int dst_port); void disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); + void lock(); + void unlock(); }; #endif /* INCLUDED_GR_HIER_BLOCK2_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index f9a126fe2..f899b6894 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -50,4 +50,6 @@ public: void disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) throw (std::invalid_argument); + void lock(); + void unlock(); }; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 4e9380689..307cbabeb 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -33,9 +34,11 @@ gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : d_owner(owner), + d_parent_detail(0), d_fg(gr_make_simple_flowgraph()), d_inputs(owner->input_signature()->max_streams()), - d_outputs(owner->output_signature()->max_streams()) + d_outputs(owner->output_signature()->max_streams()), + d_runtime() { } @@ -55,6 +58,21 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, if (src.get() == dst.get()) throw std::invalid_argument("src and destination blocks cannot be the same"); + gr_hier_block2_sptr src_block(boost::dynamic_pointer_cast(src)); + gr_hier_block2_sptr dst_block(boost::dynamic_pointer_cast(dst)); + + if (src_block && src.get() != d_owner) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "connect: src is hierarchical, setting parent to " << this << std::endl; + src_block->d_detail->d_parent_detail = this; + } + + if (dst_block && dst.get() != d_owner) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "connect: dst is hierarchical, setting parent to " << this << std::endl; + dst_block->d_detail->d_parent_detail = this; + } + // Connections to block inputs or outputs int max_port; if (src.get() == d_owner) { @@ -88,6 +106,21 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, if (src.get() == dst.get()) throw std::invalid_argument("src and destination blocks cannot be the same"); + gr_hier_block2_sptr src_block(boost::dynamic_pointer_cast(src)); + gr_hier_block2_sptr dst_block(boost::dynamic_pointer_cast(dst)); + + if (src_block && src.get() != d_owner) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "connect: src is hierarchical, clearing parent" << std::endl; + src_block->d_detail->d_parent_detail = 0; + } + + if (dst_block && dst.get() != d_owner) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "connect: dst is hierarchical, clearing parent" << std::endl; + dst_block->d_detail->d_parent_detail = 0; + } + if (src.get() == d_owner) return disconnect_input(src_port, dst_port, dst); @@ -219,3 +252,29 @@ gr_hier_block2_detail::flatten(gr_simple_flowgraph_sptr sfg) hier_block2->d_detail->flatten(sfg); } } + +void +gr_hier_block2_detail::lock() +{ + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "lock: entered in " << this << std::endl; + + if (d_parent_detail) + d_parent_detail->lock(); + else + if (d_runtime) + d_runtime->lock(); +} + +void +gr_hier_block2_detail::unlock() +{ + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "unlock: entered in " << this << std::endl; + + if (d_parent_detail) + d_parent_detail->unlock(); + else + if (d_runtime) + d_runtime->unlock(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index 15c8548c6..254709ffb 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -36,10 +36,12 @@ private: // Private implementation data gr_hier_block2 *d_owner; + gr_hier_block2_detail *d_parent_detail; gr_simple_flowgraph_sptr d_fg; gr_endpoint_vector_t d_inputs; gr_endpoint_vector_t d_outputs; - + gr_runtime *d_runtime; + // Private implementation methods void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); @@ -52,6 +54,9 @@ private: void flatten(gr_simple_flowgraph_sptr sfg); gr_endpoint resolve_port(int port, bool is_input); gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input); + void set_runtime(gr_runtime *runtime) { d_runtime = runtime; } + void lock(); + void unlock(); public: ~gr_hier_block2_detail(); diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.cc b/gnuradio-core/src/lib/runtime/gr_runtime.cc index 3a992f689..a77aac432 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime.cc @@ -36,7 +36,7 @@ gr_make_runtime(gr_hier_block2_sptr top_block) gr_runtime::gr_runtime(gr_hier_block2_sptr top_block) { - d_impl = new gr_runtime_impl(top_block); + d_impl = new gr_runtime_impl(top_block, this); } gr_runtime::~gr_runtime() @@ -74,3 +74,16 @@ gr_runtime::restart() { d_impl->restart(); } + +void +gr_runtime::lock() +{ + d_impl->lock(); +} + +void +gr_runtime::unlock() +{ + d_impl->unlock(); +} + diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.h b/gnuradio-core/src/lib/runtime/gr_runtime.h index 5aec6dcf0..23bdfaa78 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime.h @@ -80,6 +80,26 @@ public: * recreates new threads (possibly a different number from before.) */ void restart(); + + /*! + * Lock a flow graph in preparation for reconfiguration. When an equal + * number of calls to lock() and unlock() have occurred, the flow graph + * will be restarted automatically. + * + * N.B. lock() and unlock() cannot be called from a flow graph thread or + * deadlock will occur when reconfiguration happens. + */ + void lock(); + + /*! + * Lock a flow graph in preparation for reconfiguration. When an equal + * number of calls to lock() and unlock() have occurred, the flow graph + * will be restarted automatically. + * + * N.B. lock() and unlock() cannot be called from a flow graph thread or + * deadlock will occur when reconfiguration happens. + */ + void unlock(); }; #endif /* INCLUDED_GR_RUNTIME_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc index 64fbca9c9..54fc7d19a 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -53,17 +53,20 @@ runtime_sigint_handler(int signum) s_runtime->stop(); } -gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) +gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block, gr_runtime *owner) : d_running(false), d_top_block(top_block), - d_sfg(gr_make_simple_flowgraph()) + d_sfg(gr_make_simple_flowgraph()), + d_owner(owner) { s_runtime = this; + top_block->set_runtime(d_owner); } gr_runtime_impl::~gr_runtime_impl() { - s_runtime = 0; // we don't own this + s_runtime = 0; // don't call delete we don't own these + d_owner = 0; } void @@ -142,6 +145,33 @@ gr_runtime_impl::wait() d_threads.clear(); } + +// N.B. lock() and unlock() cannot be called from a flow graph thread or +// deadlock will occur when reconfiguration happens +void +gr_runtime_impl::lock() +{ + omni_mutex_lock lock(d_reconf); + d_lock_count++; + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "runtime: locked, count = " << d_lock_count << std::endl; +} + +void +gr_runtime_impl::unlock() +{ + omni_mutex_lock lock(d_reconf); + if (d_lock_count == 0) + throw std::runtime_error("unpaired unlock() call"); + + d_lock_count--; + if (GR_RUNTIME_IMPL_DEBUG) + std::cout << "runtime: unlocked, count = " << d_lock_count << std::endl; + + if (d_lock_count == 0) + restart(); +} + void gr_runtime_impl::restart() { @@ -208,4 +238,3 @@ gr_scheduler_thread::stop() { d_sts->stop(); } - diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h index 0fb6e1f0d..5dc2311cb 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h @@ -66,7 +66,7 @@ public: class gr_runtime_impl { private: - gr_runtime_impl(gr_hier_block2_sptr top_block); + gr_runtime_impl(gr_hier_block2_sptr top_block, gr_runtime *owner); friend void runtime_sigint_handler(int signum); friend class gr_runtime; @@ -75,12 +75,17 @@ private: gr_simple_flowgraph_sptr d_sfg; std::vector d_graphs; gr_scheduler_thread_vector_t d_threads; - + gr_runtime *d_owner; + int d_lock_count; + omni_mutex d_reconf; + void start(); void start_threads(); void stop(); void wait(); void restart(); + void lock(); + void unlock(); public: ~gr_runtime_impl(); -- cgit From 7e24277efcd3589884170bdc0dcb4302b8262e97 Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 23 May 2007 03:27:07 +0000 Subject: fix calculation of mid-pri for realtime_scheduling git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5520 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_realtime.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.cc b/gnuradio-core/src/lib/runtime/gr_realtime.cc index a5b8b0477..a0aedfd8b 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_realtime.cc @@ -39,7 +39,7 @@ gr_rt_status_t gr_enable_realtime_scheduling() { int policy = SCHED_FIFO; - int pri = (sched_get_priority_max (policy) - sched_get_priority_min (policy)) / 2; + int pri = (sched_get_priority_max (policy) + sched_get_priority_min (policy)) / 2; int pid = 0; // this process struct sched_param param; -- cgit From 37c779b0c6394a3cec53370beb3b5a95e898b66a Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 16 Jul 2007 05:28:38 +0000 Subject: Merged r5950:5978 from features/pager into trunk. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5979 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 2 +- gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 2 +- gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index 9811b9def..fc74ff431 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -29,7 +29,7 @@ #include #include -#define GR_HIER_BLOCK2_DEBUG 1 +#define GR_HIER_BLOCK2_DEBUG 0 gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 307cbabeb..4fefed28b 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -30,7 +30,7 @@ #include #include -#define GR_HIER_BLOCK2_DETAIL_DEBUG 1 +#define GR_HIER_BLOCK2_DETAIL_DEBUG 0 gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : d_owner(owner), diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc index 54fc7d19a..e792774b9 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -38,7 +38,7 @@ #include #include -#define GR_RUNTIME_IMPL_DEBUG 1 +#define GR_RUNTIME_IMPL_DEBUG 0 static gr_runtime_impl *s_runtime = 0; diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc index a725adb6e..432cde0ae 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc @@ -33,7 +33,7 @@ #include #include -#define GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG 1 +#define GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG 0 gr_edge_sptr gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst) -- cgit From 937b719d2e57d0497293d603da10cac2532346f6 Mon Sep 17 00:00:00 2001 From: eb Date: Sat, 21 Jul 2007 03:44:38 +0000 Subject: Updated license from GPL version 2 or later to GPL version 3 or later. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6044 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 2 +- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_basic_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_basic_block.i | 2 +- gnuradio-core/src/lib/runtime/gr_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_block.i | 2 +- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 2 +- gnuradio-core/src/lib/runtime/gr_block_detail.i | 2 +- gnuradio-core/src/lib/runtime/gr_buffer.cc | 2 +- gnuradio-core/src/lib/runtime/gr_buffer.h | 2 +- gnuradio-core/src/lib/runtime/gr_buffer.i | 2 +- gnuradio-core/src/lib/runtime/gr_complex.h | 2 +- gnuradio-core/src/lib/runtime/gr_dispatcher.cc | 2 +- gnuradio-core/src/lib/runtime/gr_dispatcher.h | 2 +- gnuradio-core/src/lib/runtime/gr_dispatcher.i | 2 +- gnuradio-core/src/lib/runtime/gr_error_handler.cc | 2 +- gnuradio-core/src/lib/runtime/gr_error_handler.h | 2 +- gnuradio-core/src/lib/runtime/gr_error_handler.i | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2.i | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h | 2 +- gnuradio-core/src/lib/runtime/gr_io_signature.cc | 2 +- gnuradio-core/src/lib/runtime/gr_io_signature.h | 2 +- gnuradio-core/src/lib/runtime/gr_io_signature.i | 2 +- gnuradio-core/src/lib/runtime/gr_local_sighandler.cc | 2 +- gnuradio-core/src/lib/runtime/gr_local_sighandler.h | 2 +- gnuradio-core/src/lib/runtime/gr_message.cc | 2 +- gnuradio-core/src/lib/runtime/gr_message.h | 2 +- gnuradio-core/src/lib/runtime/gr_message.i | 2 +- gnuradio-core/src/lib/runtime/gr_msg_handler.cc | 2 +- gnuradio-core/src/lib/runtime/gr_msg_handler.h | 2 +- gnuradio-core/src/lib/runtime/gr_msg_handler.i | 2 +- gnuradio-core/src/lib/runtime/gr_msg_queue.cc | 2 +- gnuradio-core/src/lib/runtime/gr_msg_queue.h | 2 +- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 2 +- gnuradio-core/src/lib/runtime/gr_pagesize.cc | 2 +- gnuradio-core/src/lib/runtime/gr_pagesize.h | 2 +- gnuradio-core/src/lib/runtime/gr_preferences.cc | 2 +- gnuradio-core/src/lib/runtime/gr_preferences.h | 2 +- gnuradio-core/src/lib/runtime/gr_realtime.cc | 2 +- gnuradio-core/src/lib/runtime/gr_realtime.h | 2 +- gnuradio-core/src/lib/runtime/gr_runtime.cc | 2 +- gnuradio-core/src/lib/runtime/gr_runtime.h | 2 +- gnuradio-core/src/lib/runtime/gr_runtime.i | 2 +- gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 2 +- gnuradio-core/src/lib/runtime/gr_runtime_impl.h | 2 +- gnuradio-core/src/lib/runtime/gr_runtime_types.h | 2 +- gnuradio-core/src/lib/runtime/gr_select_handler.cc | 2 +- gnuradio-core/src/lib/runtime/gr_select_handler.h | 2 +- gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc | 2 +- gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h | 2 +- gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc | 2 +- gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h | 2 +- gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc | 2 +- gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h | 2 +- gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i | 2 +- gnuradio-core/src/lib/runtime/gr_swig_block_magic.i | 2 +- gnuradio-core/src/lib/runtime/gr_sync_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_sync_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_sync_block.i | 2 +- gnuradio-core/src/lib/runtime/gr_sync_decimator.cc | 2 +- gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 2 +- gnuradio-core/src/lib/runtime/gr_sync_decimator.i | 2 +- gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc | 2 +- gnuradio-core/src/lib/runtime/gr_sync_interpolator.h | 2 +- gnuradio-core/src/lib/runtime/gr_sync_interpolator.i | 2 +- gnuradio-core/src/lib/runtime/gr_timer.h | 2 +- gnuradio-core/src/lib/runtime/gr_tmp_path.cc | 2 +- gnuradio-core/src/lib/runtime/gr_tmp_path.h | 2 +- gnuradio-core/src/lib/runtime/gr_types.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h | 2 +- gnuradio-core/src/lib/runtime/qa_gr_block.cc | 2 +- gnuradio-core/src/lib/runtime/qa_gr_block.h | 2 +- gnuradio-core/src/lib/runtime/qa_gr_buffer.cc | 2 +- gnuradio-core/src/lib/runtime/qa_gr_buffer.h | 2 +- gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc | 2 +- gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h | 2 +- gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc | 2 +- gnuradio-core/src/lib/runtime/qa_gr_io_signature.h | 2 +- gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc | 2 +- gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h | 2 +- gnuradio-core/src/lib/runtime/qa_runtime.cc | 2 +- gnuradio-core/src/lib/runtime/qa_runtime.h | 2 +- gnuradio-core/src/lib/runtime/runtime.i | 2 +- gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc | 2 +- 98 files changed, 98 insertions(+), 98 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index ee71fcdbc..b15e651dd 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -5,7 +5,7 @@ # # 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 2, or (at your option) +# 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, diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index a5f1a4f83..33cc3c2e9 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 583c3241d..c47430e12 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 33b895d43..60e08aac3 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 1b1d35756..0a8fb92c2 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 247238bb0..aa2b0bde9 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index 5d0f5fb1b..c2e2aa4b8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 5feb180f7..e545d833d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index d89b7fea1..78b1019eb 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.i b/gnuradio-core/src/lib/runtime/gr_block_detail.i index 9ac5ae96d..c8600c3cf 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.i +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 300d66f67..77f0c7c43 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 51474c0e7..cf578c89d 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.i b/gnuradio-core/src/lib/runtime/gr_buffer.i index 0434bdfc1..38e1d945d 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.i +++ b/gnuradio-core/src/lib/runtime/gr_buffer.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_complex.h b/gnuradio-core/src/lib/runtime/gr_complex.h index 732aa997d..f705d95dc 100644 --- a/gnuradio-core/src/lib/runtime/gr_complex.h +++ b/gnuradio-core/src/lib/runtime/gr_complex.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.cc b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc index 3c84edd4c..1b0a1d7a3 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.cc +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.h b/gnuradio-core/src/lib/runtime/gr_dispatcher.h index 69e7f851c..acfc428a2 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.h +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.i b/gnuradio-core/src/lib/runtime/gr_dispatcher.i index 1e8ce1043..fc361701a 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.i +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.cc b/gnuradio-core/src/lib/runtime/gr_error_handler.cc index 4d4ca6eea..4b4cdacef 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.h b/gnuradio-core/src/lib/runtime/gr_error_handler.h index a001bcb90..eb69fccb5 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.i b/gnuradio-core/src/lib/runtime/gr_error_handler.i index aea4598d7..b4aa1fa39 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.i +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index fc74ff431..5b6688412 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index da483098e..02ce10106 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index f899b6894..b3882a6a8 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 4fefed28b..46656360e 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -5,7 +5,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index 254709ffb..9002dde1d 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -5,7 +5,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.cc b/gnuradio-core/src/lib/runtime/gr_io_signature.cc index ace27314e..1c1b06f02 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index d33a1cf34..aa839ad0c 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.i b/gnuradio-core/src/lib/runtime/gr_io_signature.i index ef79cd2fb..78465b19e 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.i +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc index 009d62bdb..c6448f872 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h index 011b0853a..c753f0ff5 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_message.cc b/gnuradio-core/src/lib/runtime/gr_message.cc index 7586376dc..f14ed9d9c 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.cc +++ b/gnuradio-core/src/lib/runtime/gr_message.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_message.h b/gnuradio-core/src/lib/runtime/gr_message.h index cae599da1..e3c52a581 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.h +++ b/gnuradio-core/src/lib/runtime/gr_message.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_message.i b/gnuradio-core/src/lib/runtime/gr_message.i index 7be0e73ca..44636fde6 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.i +++ b/gnuradio-core/src/lib/runtime/gr_message.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.cc b/gnuradio-core/src/lib/runtime/gr_msg_handler.cc index 5b5604949..a3a85a463 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.h b/gnuradio-core/src/lib/runtime/gr_msg_handler.h index 3ddc25678..443611841 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.i b/gnuradio-core/src/lib/runtime/gr_msg_handler.i index bda1e3ed3..17ccd0ec5 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc index 6d105b71b..922eeda03 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.h b/gnuradio-core/src/lib/runtime/gr_msg_queue.h index a2bd70dd2..fc4c2407f 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 0fe0d2906..68dbfd645 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_pagesize.cc b/gnuradio-core/src/lib/runtime/gr_pagesize.cc index a3896b0b9..09fdf5578 100644 --- a/gnuradio-core/src/lib/runtime/gr_pagesize.cc +++ b/gnuradio-core/src/lib/runtime/gr_pagesize.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_pagesize.h b/gnuradio-core/src/lib/runtime/gr_pagesize.h index ae7d74442..3c1b8eb6b 100644 --- a/gnuradio-core/src/lib/runtime/gr_pagesize.h +++ b/gnuradio-core/src/lib/runtime/gr_pagesize.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index f8cd339d5..16c9bcafe 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.h b/gnuradio-core/src/lib/runtime/gr_preferences.h index 55c42e127..7f2a25e6b 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.h +++ b/gnuradio-core/src/lib/runtime/gr_preferences.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.cc b/gnuradio-core/src/lib/runtime/gr_realtime.cc index a0aedfd8b..878411df2 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_realtime.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.h b/gnuradio-core/src/lib/runtime/gr_realtime.h index e4d676e15..49a52a0d5 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.h +++ b/gnuradio-core/src/lib/runtime/gr_realtime.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.cc b/gnuradio-core/src/lib/runtime/gr_runtime.cc index a77aac432..6b1419e20 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.h b/gnuradio-core/src/lib/runtime/gr_runtime.h index 23bdfaa78..1168b3eda 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.i b/gnuradio-core/src/lib/runtime/gr_runtime.i index 10e757baa..d750553a4 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime.i +++ b/gnuradio-core/src/lib/runtime/gr_runtime.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc index e792774b9..134690a1a 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h index 5dc2311cb..17a8a985c 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_types.h b/gnuradio-core/src/lib/runtime/gr_runtime_types.h index dfa0ce94f..6ab1ac8f7 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_types.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_types.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.cc b/gnuradio-core/src/lib/runtime/gr_select_handler.cc index faaa96e56..869e46511 100644 --- a/gnuradio-core/src/lib/runtime/gr_select_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.h b/gnuradio-core/src/lib/runtime/gr_select_handler.h index 482a0ea65..cc883dc90 100644 --- a/gnuradio-core/src/lib/runtime/gr_select_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc index 780d51d78..be74cec40 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h index 04b83c8cc..998bcb64f 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc index 432cde0ae..2da2dad52 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h index 5d01c38f0..53b620350 100644 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc index 794291f2c..6aaaf954b 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h index 5e21d8d08..139e50b13 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i index 12c3065ad..fb2ff0d7f 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i b/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i index cbcd1b005..083d60689 100644 --- a/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i +++ b/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.cc b/gnuradio-core/src/lib/runtime/gr_sync_block.cc index ac2e90b63..1427570ae 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index 7607cd190..dcc7e2e73 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.i b/gnuradio-core/src/lib/runtime/gr_sync_block.i index 2bfcd2b7d..8e140bb88 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.i +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc index 1526cf8fc..1add2fadd 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h index d6ee14deb..4666ece8e 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.i b/gnuradio-core/src/lib/runtime/gr_sync_decimator.i index 167e843a6..821b2648e 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.i +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc index 0a88cc7cd..f61e59ea1 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index 5151b7f92..46851de2d 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i index 5c42dfdd2..4443ed0aa 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_timer.h b/gnuradio-core/src/lib/runtime/gr_timer.h index c0c3c92aa..2e1106037 100644 --- a/gnuradio-core/src/lib/runtime/gr_timer.h +++ b/gnuradio-core/src/lib/runtime/gr_timer.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc b/gnuradio-core/src/lib/runtime/gr_tmp_path.cc index 4c156fb97..1f0c830cd 100644 --- a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc +++ b/gnuradio-core/src/lib/runtime/gr_tmp_path.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.h b/gnuradio-core/src/lib/runtime/gr_tmp_path.h index 987df64e4..3d02043c7 100644 --- a/gnuradio-core/src/lib/runtime/gr_tmp_path.h +++ b/gnuradio-core/src/lib/runtime/gr_tmp_path.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h index d37d3bee0..ad8f145b8 100644 --- a/gnuradio-core/src/lib/runtime/gr_types.h +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc index a302c010a..a70229610 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h index 49039fd36..c224b7852 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc index 75f28e888..65fe0c488 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h index 20aff94b2..c866e80e8 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc index 1d8694cd0..3017036ef 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h index a852b813f..1444a68d7 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc index b898498e5..173b3f732 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h index b43de2ef5..5c84dd69a 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc index ccb169b95..88869dc75 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h index cfa683255..d5f739ae4 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_block.cc index 5a0875335..ea3f3e14c 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.h b/gnuradio-core/src/lib/runtime/qa_gr_block.h index 58aeb6dae..24634998e 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc index d5a63c68a..ad40f724d 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.h b/gnuradio-core/src/lib/runtime/qa_gr_buffer.h index 46e3ddc11..7e812e721 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc index b800b57b5..07b9d5ecf 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h index a6bd8d97b..a07ed7bf8 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc index 3b8976c6e..07abe10b3 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h index 3b22105f6..02fc9ddc4 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc index 594e36882..2e787ac28 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h index 8ae1d8a03..42f6a1917 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index ca0c71d3c..2abdc36b3 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -5,7 +5,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.h b/gnuradio-core/src/lib/runtime/qa_runtime.h index b9a920ba7..c55208c39 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.h +++ b/gnuradio-core/src/lib/runtime/qa_runtime.h @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index caa2166e0..d162cff9b 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, diff --git a/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc b/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc index 11704e415..e541c5402 100644 --- a/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc +++ b/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, -- cgit From f561a45ce55debd0662ea38e17b2ea4ad50ad771 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 23 Aug 2007 18:46:20 +0000 Subject: Merge r6160:6168 from jcorgan/fg into trunk. Refactors gr_simple_flowgraph into gr_flowgraph and gr_flat_flowgraph. Adds cppunit-based QA. Trial fix for ticket:164 included for free. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6169 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 12 +- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 3 +- gnuradio-core/src/lib/runtime/gr_basic_block.h | 12 + gnuradio-core/src/lib/runtime/gr_block.h | 7 +- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 3 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 8 - gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 223 ++++++++ gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 65 +++ gnuradio-core/src/lib/runtime/gr_flowgraph.cc | 436 +++++++++++++++ gnuradio-core/src/lib/runtime/gr_flowgraph.h | 188 +++++++ .../src/lib/runtime/gr_hier_block2_detail.cc | 15 +- .../src/lib/runtime/gr_hier_block2_detail.h | 6 +- gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 41 +- gnuradio-core/src/lib/runtime/gr_runtime_impl.h | 4 +- gnuradio-core/src/lib/runtime/gr_runtime_types.h | 18 +- .../src/lib/runtime/gr_simple_flowgraph.cc | 70 --- .../src/lib/runtime/gr_simple_flowgraph.h | 83 --- .../src/lib/runtime/gr_simple_flowgraph_detail.cc | 609 --------------------- .../src/lib/runtime/gr_simple_flowgraph_detail.h | 127 ----- gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc | 245 +++++++++ gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h | 75 +++ gnuradio-core/src/lib/runtime/qa_runtime.cc | 4 +- 22 files changed, 1314 insertions(+), 940 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h create mode 100644 gnuradio-core/src/lib/runtime/gr_flowgraph.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_flowgraph.h delete mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h delete mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index b15e651dd..346f23b6a 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -31,8 +31,8 @@ libruntime_la_LIBADD = \ libruntime_la_SOURCES = \ gr_basic_block.cc \ - gr_simple_flowgraph.cc \ - gr_simple_flowgraph_detail.cc \ + gr_flowgraph.cc \ + gr_flat_flowgraph.cc \ gr_block.cc \ gr_block_detail.cc \ gr_hier_block2.cc \ @@ -66,14 +66,15 @@ libruntime_qa_la_SOURCES = \ qa_gr_block.cc \ qa_gr_hier_block2.cc \ qa_gr_buffer.cc \ + qa_gr_flowgraph.cc \ qa_gr_io_signature.cc \ qa_gr_vmcircbuf.cc \ qa_runtime.cc grinclude_HEADERS = \ gr_basic_block.h \ - gr_simple_flowgraph.h \ - gr_simple_flowgraph_detail.h \ + gr_flowgraph.h \ + gr_flat_flowgraph.h \ gr_block.h \ gr_block_detail.h \ gr_hier_block2.h \ @@ -109,6 +110,7 @@ noinst_HEADERS = \ gr_vmcircbuf_sysv_shm.h \ gr_vmcircbuf_createfilemapping.h \ qa_gr_block.h \ + qa_gr_flowgraph.h \ qa_gr_hier_block2.h \ qa_gr_buffer.h \ qa_gr_io_signature.h \ @@ -135,3 +137,5 @@ swiginclude_HEADERS = \ gr_sync_interpolator.i \ gr_swig_block_magic.i \ runtime.i + +MOSTLYCLEANFILES = *~ *.loT diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 33cc3c2e9..e94e089e2 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -42,7 +42,8 @@ gr_basic_block::gr_basic_block(const std::string &name, : d_name(name), d_input_signature(input_signature), d_output_signature(output_signature), - d_unique_id(s_next_id++) + d_unique_id(s_next_id++), + d_color(WHITE) { s_ncurrently_allocated++; } diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index c47430e12..b2b8b42a3 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -41,10 +41,16 @@ class gr_basic_block : public boost::enable_shared_from_this { protected: + friend class gr_flowgraph; + friend class gr_flat_flowgraph; // TODO: will be redundant + + enum vcolor { WHITE, GREY, BLACK }; + std::string d_name; gr_io_signature_sptr d_input_signature; gr_io_signature_sptr d_output_signature; long d_unique_id; + vcolor d_color; //! Protected constructor prevents instantiation by non-derived classes gr_basic_block(const std::string &name, @@ -61,6 +67,12 @@ protected: d_output_signature = iosig; } + /*! + * \brief Allow the flowgraph to set for sorting and partitioning + */ + void set_color(vcolor color) { d_color = color; } + vcolor color() const { return d_color; } + public: virtual ~gr_basic_block(); long unique_id() const { return d_unique_id; } diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index aa2b0bde9..ce58ca9ac 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 Free Software Foundation, Inc. + * Copyright 2004,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -214,4 +214,9 @@ class gr_block : public gr_basic_block { typedef std::vector gr_block_vector_t; typedef std::vector::iterator gr_block_viter_t; +inline gr_block_sptr make_gr_block_sptr(gr_basic_block_sptr p) +{ + return boost::dynamic_pointer_cast(p); +} + #endif /* INCLUDED_GR_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index e545d833d..ae1ea2562 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -38,8 +38,7 @@ gr_block_detail_ncurrently_allocated () gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), - d_done (false), - d_color (gr_block_detail::WHITE) + d_done (false) { s_ncurrently_allocated++; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 78b1019eb..a3b7731c0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -75,13 +75,6 @@ class gr_block_detail { void produce_each (int how_many_items); - /*! - * \brief Allow the flowgraph to set for sorting and partitioning - */ - enum vcolor { WHITE, GREY, BLACK }; - void set_color(vcolor color) { d_color = color; } - vcolor color() const { return d_color; } - // ---------------------------------------------------------------------------- private: @@ -90,7 +83,6 @@ class gr_block_detail { std::vector d_input; std::vector d_output; bool d_done; - vcolor d_color; gr_block_detail (unsigned int ninputs, unsigned int noutputs); diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc new file mode 100644 index 000000000..d7f3ffb51 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -0,0 +1,223 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#define GR_FLAT_FLOWGRAPH_DEBUG 0 + +gr_flat_flowgraph_sptr +gr_make_flat_flowgraph() +{ + return gr_flat_flowgraph_sptr(new gr_flat_flowgraph()); +} + +gr_flat_flowgraph::gr_flat_flowgraph() +{ +} + +gr_flat_flowgraph::~gr_flat_flowgraph() +{ +} + +void +gr_flat_flowgraph::setup_connections() +{ + gr_basic_block_vector_t blocks = calc_used_blocks(); + + // Assign block details to blocks + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) + make_gr_block_sptr(*p)->set_detail(allocate_block_detail(*p)); + + // Connect inputs to outputs for each block + for(gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) + connect_block_inputs(*p); +} + +gr_block_detail_sptr +gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block, gr_block_detail_sptr old_detail) +{ + int ninputs = calc_used_ports(block, true).size(); + int noutputs = calc_used_ports(block, false).size(); + gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); + + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "Creating block detail for " << block << std::endl; + + // Re-use or allocate output buffers + for (int i = 0; i < noutputs; i++) { + gr_buffer_sptr buffer; + + if (!old_detail || i >= old_detail->noutputs()) { + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "Allocating new buffer for output " << i << std::endl; + buffer = allocate_buffer(block, i); + } + else { + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "Reusing old buffer for output " << i << std::endl; + buffer = old_detail->output(i); + } + + detail->set_output(i, buffer); + } + + return detail; +} + +gr_buffer_sptr +gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) +{ + gr_block_sptr grblock = make_gr_block_sptr(block); + if (!grblock) + throw std::runtime_error("allocate_buffer found non-gr_block"); + int item_size = block->output_signature()->sizeof_stream_item(port); + int nitems = s_fixed_buffer_size/item_size; + + // Make sure there are at least twice the output_multiple no. of items + if (nitems < 2*grblock->output_multiple()) // Note: this means output_multiple() + nitems = 2*grblock->output_multiple(); // can't be changed by block dynamically + + // If any downstream blocks are decimators and/or have a large output_multiple, + // ensure we have a buffer at least twice their decimation factor*output_multiple + gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); + + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + gr_block_sptr dgrblock = make_gr_block_sptr(*p); + if (!dgrblock) + throw std::runtime_error("allocate_buffer found non-gr_block"); + + double decimation = (1.0/dgrblock->relative_rate()); + int multiple = dgrblock->output_multiple(); + int history = dgrblock->history(); + nitems = std::max(nitems, static_cast(2*(decimation*multiple+history))); + } + + return gr_make_buffer(nitems, item_size); +} + +void +gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) +{ + gr_block_sptr grblock = make_gr_block_sptr(block); + if (!grblock) + throw std::runtime_error("found non-gr_block"); + + // Get its detail and edges that feed into it + gr_block_detail_sptr detail = grblock->detail(); + gr_edge_vector_t in_edges = calc_upstream_edges(block); + + // For each edge that feeds into it + for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) { + // Set the buffer reader on the destination port to the output + // buffer on the source port + int dst_port = e->dst().port(); + int src_port = e->src().port(); + gr_basic_block_sptr src_block = e->src().block(); + gr_block_sptr src_grblock = make_gr_block_sptr(src_block); + if (!src_grblock) + throw std::runtime_error("found non-gr_block"); + gr_buffer_sptr src_buffer = src_grblock->detail()->output(src_port); + + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "Setting input " << dst_port << " from edge " << (*e) << std::endl; + + detail->set_input(dst_port, gr_buffer_add_reader(src_buffer, grblock->history()-1)); + } +} + +void +gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) +{ + std::map old_details; + + // Allocate or reuse output buffers + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + gr_block_sptr block = make_gr_block_sptr(*p); + + gr_block_detail_sptr old_detail = block->detail(); + block->set_detail(allocate_block_detail(block, old_detail)); + + // Save old detail for use in next step + old_details[block] = old_detail; + } + + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + gr_block_sptr block = make_gr_block_sptr(*p); + + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "merge: testing " << (*p) << "..."; + + if (old_ffg->has_block_p(*p)) { + // Block exists in old flow graph + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "used in old flow graph" << std::endl; + gr_block_detail_sptr detail = block->detail(); + + // Iterate through the inputs and see what needs to be done + for (int i = 0; i < detail->ninputs(); i++) { + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "Checking input " << i << "..."; + gr_edge edge = calc_upstream_edge(*p, i); + + // Fish out old buffer reader and see if it matches correct buffer from edge list + gr_block_sptr src_block = make_gr_block_sptr(edge.src().block()); + gr_block_detail_sptr src_detail = src_block->detail(); + gr_buffer_sptr src_buffer = src_detail->output(edge.src().port()); + gr_buffer_reader_sptr old_reader; + gr_block_detail_sptr old_detail = old_details[block]; + if (old_detail && i < old_detail->ninputs()) + old_reader = old_detail->input(i); + + // If there's a match, use it + if (old_reader && (src_buffer == old_reader->buffer())) { + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "matched" << std::endl; + detail->set_input(i, old_reader); + + } + else { + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "needs a new reader" << std::endl; + + // Create new buffer reader and assign + detail->set_input(i, gr_buffer_add_reader(src_buffer, block->history()-1)); + } + } + } + else { + // Block is new, it just needs buffer readers at this point + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "new block" << std::endl; + connect_block_inputs(block); + } + } +} + diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h new file mode 100644 index 000000000..0f4928064 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_FLAT_FLOWGRAPH_H +#define INCLUDED_GR_FLAT_FLOWGRAPH_H + +#include +#include + +// 32Kbyte buffer size between blocks +#define GR_FIXED_BUFFER_SIZE (32*(1L<<10)) + +// Create a shared pointer to a heap allocated gr_flat_flowgraph +// (types defined in gr_runtime_types.h) +gr_flat_flowgraph_sptr gr_make_flat_flowgraph(); + +/*! + *\brief Class specializing gr_flat_flowgraph that has all nodes + * as gr_blocks, with no hierarchy + * + */ +class gr_flat_flowgraph : public gr_flowgraph +{ +public: + friend gr_flat_flowgraph_sptr gr_make_flat_flowgraph(); + + // Destruct an arbitrary gr_flat_flowgraph + ~gr_flat_flowgraph(); + + // Wire gr_blocks together in new flat_flowgraph + void setup_connections(); + + // Merge applicable connections from existing flat flowgraph + void merge_connections(gr_flat_flowgraph_sptr sfg); + +private: + gr_flat_flowgraph(); + + static const unsigned int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE; + gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block, + gr_block_detail_sptr old_detail=gr_block_detail_sptr()); + gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port); + void connect_block_inputs(gr_basic_block_sptr block); +}; + +#endif /* INCLUDED_GR_FLAT_FLOWGRAPH_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc new file mode 100644 index 000000000..8e96dba75 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc @@ -0,0 +1,436 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#define GR_FLOWGRAPH_DEBUG 0 + +gr_edge::~gr_edge() +{ +} + +gr_flowgraph_sptr gr_make_flowgraph() +{ + return gr_flowgraph_sptr(new gr_flowgraph()); +} + +gr_flowgraph::gr_flowgraph() +{ +} + +gr_flowgraph::~gr_flowgraph() +{ +} + +void +gr_flowgraph::connect(const gr_endpoint &src, const gr_endpoint &dst) +{ + check_valid_port(src.block()->output_signature(), src.port()); + check_valid_port(dst.block()->input_signature(), dst.port()); + check_dst_not_used(dst); + check_type_match(src, dst); + + // All ist klar, Herr Kommisar + d_edges.push_back(gr_edge(src,dst)); +} + +void +gr_flowgraph::disconnect(const gr_endpoint &src, const gr_endpoint &dst) +{ + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + if (src == p->src() && dst == p->dst()) { + d_edges.erase(p); + return; + } + } + + throw std::invalid_argument("edge to disconnect not found"); +} + +void +gr_flowgraph::validate() +{ + d_blocks = calc_used_blocks(); + + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + std::vector used_ports; + int ninputs, noutputs; + + if (GR_FLOWGRAPH_DEBUG) + std::cout << "Validating block: " << (*p) << std::endl; + + used_ports = calc_used_ports(*p, true); // inputs + ninputs = used_ports.size(); + check_contiguity(*p, used_ports, true); // inputs + + used_ports = calc_used_ports(*p, false); // outputs + noutputs = used_ports.size(); + check_contiguity(*p, used_ports, false); // outputs + + if (!((*p)->check_topology(ninputs, noutputs))) + throw std::runtime_error("check topology failed"); + } +} + +void +gr_flowgraph::clear() +{ + // Boost shared pointers will deallocate as needed + d_blocks.clear(); + d_edges.clear(); +} + +void +gr_flowgraph::check_valid_port(gr_io_signature_sptr sig, int port) +{ + if (port < 0) + throw std::invalid_argument("negative port number"); + if (sig->max_streams() >= 0 && port >= sig->max_streams()) + throw std::invalid_argument("port number exceeds max"); +} + +void +gr_flowgraph::check_dst_not_used(const gr_endpoint &dst) +{ + // A destination is in use if it is already on the edge list + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if (p->dst() == dst) + throw std::invalid_argument("dst already in use"); +} + +void +gr_flowgraph::check_type_match(const gr_endpoint &src, const gr_endpoint &dst) +{ + int src_size = src.block()->output_signature()->sizeof_stream_item(src.port()); + int dst_size = dst.block()->input_signature()->sizeof_stream_item(dst.port()); + + if (src_size != dst_size) + throw std::invalid_argument("itemsize mismatch between src and dst"); +} + +gr_basic_block_vector_t +gr_flowgraph::calc_used_blocks() +{ + gr_basic_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); + + // Collect all blocks in the edge list + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + tmp.push_back(p->src().block()); + tmp.push_back(p->dst().block()); + } + + // Return vector of unique blocks + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; +} + +std::vector +gr_flowgraph::calc_used_ports(gr_basic_block_sptr block, bool check_inputs) +{ + std::vector tmp, result; + std::insert_iterator > inserter(result, result.begin()); + + // Collect all seen ports + gr_edge_vector_t edges = calc_connections(block, check_inputs); + for (gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) { + if (check_inputs == true) + tmp.push_back(p->dst().port()); + else + tmp.push_back(p->src().port()); + } + + // Return vector of unique values + std::sort(tmp.begin(), tmp.end()); + std::unique_copy(tmp.begin(), tmp.end(), inserter); + return result; +} + +gr_edge_vector_t +gr_flowgraph::calc_connections(gr_basic_block_sptr block, bool check_inputs) +{ + gr_edge_vector_t result; + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + if (check_inputs) { + if (p->dst().block() == block) + result.push_back(*p); + } + else { + if (p->src().block() == block) + result.push_back(*p); + } + } + + return result; // assumes no duplicates +} + +void +gr_flowgraph::check_contiguity(gr_basic_block_sptr block, + const std::vector &used_ports, + bool check_inputs) +{ + gr_io_signature_sptr sig = + check_inputs ? block->input_signature() : block->output_signature(); + + int nports = used_ports.size(); + int min_ports = sig->min_streams(); + + if (nports == 0) { + if (min_ports == 0) + return; + else + throw std::runtime_error("insufficient ports"); + } + + if (used_ports[nports-1]+1 != nports) { + for (int i = 0; i < nports; i++) + if (used_ports[i] != i) + throw std::runtime_error("missing input assignment"); + } +} + +gr_basic_block_vector_t +gr_flowgraph::calc_downstream_blocks(gr_basic_block_sptr block, int port) +{ + gr_basic_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if (p->src() == gr_endpoint(block, port)) + tmp.push_back(p->dst().block()); + + // Remove duplicates + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; +} + +gr_basic_block_vector_t +gr_flowgraph::calc_downstream_blocks(gr_basic_block_sptr block) +{ + gr_basic_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if (p->src().block() == block) + tmp.push_back(p->dst().block()); + + // Remove duplicates + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; +} + +gr_edge_vector_t +gr_flowgraph::calc_upstream_edges(gr_basic_block_sptr block) +{ + gr_edge_vector_t result; + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) + if (p->dst().block() == block) + result.push_back(*p); + + return result; // Assume no duplicates +} + +bool +gr_flowgraph::has_block_p(gr_basic_block_sptr block) +{ + gr_basic_block_viter_t result; + result = std::find(d_blocks.begin(), d_blocks.end(), block); + return (result != d_blocks.end()); +} + +gr_edge +gr_flowgraph::calc_upstream_edge(gr_basic_block_sptr block, int port) +{ + gr_edge result; + + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + if (p->dst() == gr_endpoint(block, port)) { + result = (*p); + break; + } + } + + return result; +} + +std::vector +gr_flowgraph::partition() +{ + std::vector result; + gr_basic_block_vector_t blocks = calc_used_blocks(); + gr_basic_block_vector_t graph; + + while (blocks.size() > 0) { + graph = calc_reachable_blocks(blocks[0], blocks); + assert(graph.size()); + result.push_back(topological_sort(graph)); + + for (gr_basic_block_viter_t p = graph.begin(); p != graph.end(); p++) + blocks.erase(find(blocks.begin(), blocks.end(), *p)); + } + + return result; +} + +gr_basic_block_vector_t +gr_flowgraph::calc_reachable_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) +{ + gr_basic_block_vector_t result; + + // Mark all blocks as unvisited + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) + (*p)->set_color(gr_basic_block::WHITE); + + // Recursively mark all reachable blocks + reachable_dfs_visit(block, blocks); + + // Collect all the blocks that have been visited + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) + if ((*p)->color() == gr_basic_block::BLACK) + result.push_back(*p); + + return result; +} + +// Recursively mark all reachable blocks from given block and block list +void +gr_flowgraph::reachable_dfs_visit(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) +{ + // Mark the current one as visited + block->set_color(gr_basic_block::BLACK); + + // Recurse into adjacent vertices + gr_basic_block_vector_t adjacent = calc_adjacent_blocks(block, blocks); + + for (gr_basic_block_viter_t p = adjacent.begin(); p != adjacent.end(); p++) + if ((*p)->color() == gr_basic_block::WHITE) + reachable_dfs_visit(*p, blocks); +} + +// Return a list of block adjacent to a given block along any edge +gr_basic_block_vector_t +gr_flowgraph::calc_adjacent_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) +{ + gr_basic_block_vector_t tmp, result; + std::insert_iterator inserter(result, result.begin()); + + // Find any blocks that are inputs or outputs + for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { + + if (p->src().block() == block) + tmp.push_back(p->dst().block()); + if (p->dst().block() == block) + tmp.push_back(p->src().block()); + } + + // Remove duplicates + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); + return result; +} + +gr_basic_block_vector_t +gr_flowgraph::topological_sort(gr_basic_block_vector_t &blocks) +{ + gr_basic_block_vector_t tmp; + gr_basic_block_vector_t result; + tmp = sort_sources_first(blocks); + + // Start 'em all white + for (gr_basic_block_viter_t p = tmp.begin(); p != tmp.end(); p++) + (*p)->set_color(gr_basic_block::WHITE); + + for (gr_basic_block_viter_t p = tmp.begin(); p != tmp.end(); p++) { + if ((*p)->color() == gr_basic_block::WHITE) + topological_dfs_visit(*p, result); + } + + reverse(result.begin(), result.end()); + return result; +} + +gr_basic_block_vector_t +gr_flowgraph::sort_sources_first(gr_basic_block_vector_t &blocks) +{ + gr_basic_block_vector_t sources, nonsources, result; + + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + if (source_p(*p)) + sources.push_back(*p); + else + nonsources.push_back(*p); + } + + for (gr_basic_block_viter_t p = sources.begin(); p != sources.end(); p++) + result.push_back(*p); + + for (gr_basic_block_viter_t p = nonsources.begin(); p != nonsources.end(); p++) + result.push_back(*p); + + return result; +} + +bool +gr_flowgraph::source_p(gr_basic_block_sptr block) +{ + return (calc_upstream_edges(block).size() == 0); +} + +void +gr_flowgraph::topological_dfs_visit(gr_basic_block_sptr block, gr_basic_block_vector_t &output) +{ + block->set_color(gr_basic_block::GREY); + gr_basic_block_vector_t blocks(calc_downstream_blocks(block)); + + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + switch ((*p)->color()) { + case gr_basic_block::WHITE: + topological_dfs_visit(*p, output); + break; + + case gr_basic_block::GREY: + throw std::runtime_error("flow graph has loops!"); + + case gr_basic_block::BLACK: + continue; + + default: + throw std::runtime_error("invalid color on block!"); + } + } + + block->set_color(gr_basic_block::BLACK); + output.push_back(block); +} + diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flowgraph.h new file mode 100644 index 000000000..131e41bb9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.h @@ -0,0 +1,188 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_FLOWGRAPH_H +#define INCLUDED_GR_FLOWGRAPH_H + +#include +#include + +/*! + *\brief Class representing a specific input or output graph endpoint + * + */ +class gr_endpoint +{ +private: + gr_basic_block_sptr d_basic_block; + int d_port; + +public: + gr_endpoint() : d_basic_block(), d_port(0) { } + gr_endpoint(gr_basic_block_sptr block, int port) { d_basic_block = block; d_port = port; } + gr_basic_block_sptr block() const { return d_basic_block; } + int port() const { return d_port; } + + bool operator==(const gr_endpoint &other) const; +}; + +inline bool gr_endpoint::operator==(const gr_endpoint &other) const +{ + return (d_basic_block == other.d_basic_block && + d_port == other.d_port); +} + +// Hold vectors of gr_endpoint objects +typedef std::vector gr_endpoint_vector_t; +typedef std::vector::iterator gr_endpoint_viter_t; + +/*! + *\brief Class representing a connection between to graph endpoints + * + */ +class gr_edge +{ +public: + gr_edge() : d_src(), d_dst() { }; + gr_edge(const gr_endpoint &src, const gr_endpoint &dst) : d_src(src), d_dst(dst) { } + ~gr_edge(); + + const gr_endpoint &src() const { return d_src; } + const gr_endpoint &dst() const { return d_dst; } + +private: + gr_endpoint d_src; + gr_endpoint d_dst; +}; + +// Hold vectors of gr_edge objects +typedef std::vector gr_edge_vector_t; +typedef std::vector::iterator gr_edge_viter_t; + + +// Create a shared pointer to a heap allocated flowgraph +// (types defined in gr_runtime_types.h) +gr_flowgraph_sptr gr_make_flowgraph(); + +/*! + *\brief Class representing a directed, acyclic graph of basic blocks + * + */ +class gr_flowgraph +{ +public: + friend gr_flowgraph_sptr gr_make_flowgraph(); + + // Destruct an arbitrary flowgraph + ~gr_flowgraph(); + + // Connect two endpoints + void connect(const gr_endpoint &src, const gr_endpoint &dst); + + // Disconnect two endpoints + void disconnect(const gr_endpoint &src, const gr_endpoint &dst); + + // Connect an output port to an input port (convenience) + void connect(gr_basic_block_sptr src_block, int src_port, + gr_basic_block_sptr dst_block, int dst_port); + + // Disconnect an input port from an output port (convenience) + void disconnect(gr_basic_block_sptr src_block, int src_port, + gr_basic_block_sptr dst_block, int dst_port); + + // Validate connectivity, raise exception if invalid + void validate(); + + // Clear existing flowgraph + void clear(); + + // Return vector of edges + const gr_edge_vector_t &edges() const { return d_edges; } + + // Return vector of connected blocks + gr_basic_block_vector_t calc_used_blocks(); + + // Return vector of vectors of disjointly connected blocks, topologically + // sorted. + std::vector partition(); + +protected: + gr_basic_block_vector_t d_blocks; + gr_edge_vector_t d_edges; + + gr_flowgraph(); + std::vector calc_used_ports(gr_basic_block_sptr block, bool check_inputs); + gr_basic_block_vector_t calc_downstream_blocks(gr_basic_block_sptr block, int port); + gr_edge_vector_t calc_upstream_edges(gr_basic_block_sptr block); + bool has_block_p(gr_basic_block_sptr block); + gr_edge calc_upstream_edge(gr_basic_block_sptr block, int port); + +private: + + void check_valid_port(gr_io_signature_sptr sig, int port); + void check_dst_not_used(const gr_endpoint &dst); + void check_type_match(const gr_endpoint &src, const gr_endpoint &dst); + gr_edge_vector_t calc_connections(gr_basic_block_sptr block, bool check_inputs); // false=use outputs + void check_contiguity(gr_basic_block_sptr block, const std::vector &used_ports, bool check_inputs); + + gr_basic_block_vector_t calc_downstream_blocks(gr_basic_block_sptr block); + 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); +}; + +// Convenience functions +inline +void gr_flowgraph::connect(gr_basic_block_sptr src_block, int src_port, + gr_basic_block_sptr dst_block, int dst_port) +{ + connect(gr_endpoint(src_block, src_port), + gr_endpoint(dst_block, dst_port)); +} + +inline +void gr_flowgraph::disconnect(gr_basic_block_sptr src_block, int src_port, + gr_basic_block_sptr dst_block, int dst_port) +{ + disconnect(gr_endpoint(src_block, src_port), + gr_endpoint(dst_block, dst_port)); +} + +inline std::ostream& +operator <<(std::ostream &os, const gr_endpoint endp) +{ + os << endp.block() << ":" << endp.port(); + return os; +} + +inline std::ostream& +operator <<(std::ostream &os, const gr_edge edge) +{ + os << edge.src() << "->" << edge.dst(); + return os; +} + +#endif /* INCLUDED_GR_FLOWGRAPH_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 46656360e..99131afb6 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -24,7 +24,6 @@ #endif #include -#include #include #include #include @@ -35,7 +34,7 @@ gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : d_owner(owner), d_parent_detail(0), - d_fg(gr_make_simple_flowgraph()), + d_fg(gr_make_flowgraph()), d_inputs(owner->input_signature()->max_streams()), d_outputs(owner->output_signature()->max_streams()), d_runtime() @@ -228,22 +227,24 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) } void -gr_hier_block2_detail::flatten(gr_simple_flowgraph_sptr sfg) +gr_hier_block2_detail::flatten(gr_flat_flowgraph_sptr sfg) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "flattening " << d_owner->name() << std::endl; // Add my edges to the flow graph, resolving references to actual endpoints - for (gr_edge_viter_t p = d_fg->d_detail->d_edges.begin(); p != d_fg->d_detail->d_edges.end(); p++) { + gr_edge_vector_t edges = d_fg->edges(); + + for (gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "Flattening edge " << (*p) << std::endl; - gr_endpoint src_endp = resolve_endpoint((*p)->src(), false); - gr_endpoint dst_endp = resolve_endpoint((*p)->dst(), true); + gr_endpoint src_endp = resolve_endpoint(p->src(), false); + gr_endpoint dst_endp = resolve_endpoint(p->dst(), true); sfg->connect(src_endp, dst_endp); } - gr_basic_block_vector_t blocks = d_fg->d_detail->calc_used_blocks(); + gr_basic_block_vector_t blocks = d_fg->calc_used_blocks(); // Recurse hierarchical children for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index 9002dde1d..b315061be 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -22,7 +22,7 @@ #define INCLUDED_GR_HIER_BLOCK2_DETAIL_H #include -#include +#include #include class gr_hier_block2_detail : boost::noncopyable @@ -37,7 +37,7 @@ private: // Private implementation data gr_hier_block2 *d_owner; gr_hier_block2_detail *d_parent_detail; - gr_simple_flowgraph_sptr d_fg; + gr_flowgraph_sptr d_fg; gr_endpoint_vector_t d_inputs; gr_endpoint_vector_t d_outputs; gr_runtime *d_runtime; @@ -51,7 +51,7 @@ private: void connect_output(int my_port, int port, gr_basic_block_sptr block); void disconnect_input(int my_port, int port, gr_basic_block_sptr block); void disconnect_output(int my_port, int port, gr_basic_block_sptr block); - void flatten(gr_simple_flowgraph_sptr sfg); + void flatten(gr_flat_flowgraph_sptr sfg); gr_endpoint resolve_port(int port, bool is_input); gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input); void set_runtime(gr_runtime *runtime) { d_runtime = runtime; } diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc index 134690a1a..30a39f1d8 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -42,6 +42,19 @@ static gr_runtime_impl *s_runtime = 0; +// Make a vector of gr_block from a vector of gr_basic_block +static +gr_block_vector_t +make_gr_block_vector(gr_basic_block_vector_t &blocks) +{ + gr_block_vector_t result; + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + result.push_back(make_gr_block_sptr(*p)); + } + + return result; +} + // FIXME: This prevents using more than one gr_runtime instance void runtime_sigint_handler(int signum) @@ -56,7 +69,7 @@ runtime_sigint_handler(int signum) gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block, gr_runtime *owner) : d_running(false), d_top_block(top_block), - d_sfg(gr_make_simple_flowgraph()), + d_ffg(gr_make_flat_flowgraph()), d_owner(owner) { s_runtime = this; @@ -79,12 +92,12 @@ gr_runtime_impl::start() throw std::runtime_error("already running"); // Create new simple flow graph by flattening hierarchical block - d_sfg->d_detail->reset(); - d_top_block->d_detail->flatten(d_sfg); + d_ffg->clear(); + d_top_block->d_detail->flatten(d_ffg); // Validate new simple flow graph and wire it up - d_sfg->d_detail->validate(); - d_sfg->d_detail->setup_connections(); + d_ffg->validate(); + d_ffg->setup_connections(); // Execute scheduler threads start_threads(); @@ -96,10 +109,10 @@ gr_runtime_impl::start_threads() if (GR_RUNTIME_IMPL_DEBUG) std::cout << "start_threads: entered" << std::endl; - d_graphs = d_sfg->d_detail->partition(); - for (std::vector::iterator p = d_graphs.begin(); + d_graphs = d_ffg->partition(); + for (std::vector::iterator p = d_graphs.begin(); p != d_graphs.end(); p++) { - gr_scheduler_thread *thread = new gr_scheduler_thread(*p); + gr_scheduler_thread *thread = new gr_scheduler_thread(make_gr_block_vector(*p)); d_threads.push_back(thread); if (GR_RUNTIME_IMPL_DEBUG) std::cout << "start_threads: starting " << thread << std::endl; @@ -188,14 +201,14 @@ gr_runtime_impl::restart() std::cout << "restart: threads stopped" << std::endl; // Create new simple flow graph - gr_simple_flowgraph_sptr new_sfg = gr_make_simple_flowgraph(); - d_top_block->d_detail->flatten(new_sfg); - new_sfg->validate(); - new_sfg->d_detail->merge_connections(d_sfg); + gr_flat_flowgraph_sptr new_ffg = gr_make_flat_flowgraph(); + d_top_block->d_detail->flatten(new_ffg); + new_ffg->validate(); + new_ffg->merge_connections(d_ffg); if (GR_RUNTIME_IMPL_DEBUG) std::cout << "restart: replacing old flow graph with new" << std::endl; - d_sfg = new_sfg; + d_ffg = new_ffg; start_threads(); } diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h index 17a8a985c..f6230018a 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h @@ -72,8 +72,8 @@ private: bool d_running; gr_hier_block2_sptr d_top_block; - gr_simple_flowgraph_sptr d_sfg; - std::vector d_graphs; + gr_flat_flowgraph_sptr d_ffg; + std::vector d_graphs; gr_scheduler_thread_vector_t d_threads; gr_runtime *d_owner; int d_lock_count; diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_types.h b/gnuradio-core/src/lib/runtime/gr_runtime_types.h index 6ab1ac8f7..8af663cdf 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_types.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_types.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -36,17 +36,19 @@ class gr_hier_block2; class gr_io_signature; class gr_buffer; class gr_buffer_reader; -class gr_simple_flowgraph; +class gr_flowgraph; +class gr_flat_flowgraph; class gr_runtime; typedef boost::shared_ptr gr_basic_block_sptr; typedef boost::shared_ptr gr_block_sptr; -typedef boost::shared_ptr gr_block_detail_sptr; -typedef boost::shared_ptr gr_hier_block2_sptr; +typedef boost::shared_ptr gr_block_detail_sptr; +typedef boost::shared_ptr gr_hier_block2_sptr; typedef boost::shared_ptr gr_io_signature_sptr; -typedef boost::shared_ptr gr_buffer_sptr; -typedef boost::shared_ptr gr_buffer_reader_sptr; -typedef boost::shared_ptr gr_runtime_sptr; -typedef boost::shared_ptr gr_simple_flowgraph_sptr; +typedef boost::shared_ptr gr_buffer_sptr; +typedef boost::shared_ptr gr_buffer_reader_sptr; +typedef boost::shared_ptr gr_runtime_sptr; +typedef boost::shared_ptr gr_flowgraph_sptr; +typedef boost::shared_ptr gr_flat_flowgraph_sptr; #endif /* INCLUDED_GR_RUNTIME_TYPES_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc deleted file mode 100644 index be74cec40..000000000 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -gr_simple_flowgraph_sptr gr_make_simple_flowgraph() -{ - return gr_simple_flowgraph_sptr(new gr_simple_flowgraph()); -} - -gr_simple_flowgraph::gr_simple_flowgraph() : -d_detail(new gr_simple_flowgraph_detail()) -{ -} - -gr_simple_flowgraph::~gr_simple_flowgraph() -{ - delete d_detail; -} - -void -gr_simple_flowgraph::connect(gr_basic_block_sptr src_block, int src_port, - gr_basic_block_sptr dst_block, int dst_port) -{ - d_detail->connect(gr_endpoint(src_block, src_port), gr_endpoint(dst_block, dst_port)); -} - -void -gr_simple_flowgraph::connect(const gr_endpoint &src, const gr_endpoint &dst) -{ - d_detail->connect(src, dst); -} - -void -gr_simple_flowgraph::disconnect(gr_basic_block_sptr src_block, int src_port, - gr_basic_block_sptr dst_block, int dst_port) -{ - d_detail->disconnect(gr_endpoint(src_block, src_port), gr_endpoint(dst_block, dst_port)); -} - -void -gr_simple_flowgraph::validate() -{ - d_detail->validate(); -} diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h deleted file mode 100644 index 998bcb64f..000000000 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_SIMPLE_FLOWGRAPH_H -#define INCLUDED_GR_SIMPLE_FLOWGRAPH_H - -#include -#include -#include - -gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); - -class gr_simple_flowgraph_detail; - -class gr_endpoint -{ -private: - friend class gr_hier_block2_detail; - gr_basic_block_sptr d_block; - int d_port; - -public: - gr_endpoint() : d_block(), d_port(0) { } // Internal use only - gr_endpoint(gr_basic_block_sptr block, int port) { d_block = block; d_port = port; } - gr_basic_block_sptr block() const { return d_block; } - int port() const { return d_port; } -}; - -typedef std::vector gr_endpoint_vector_t; - -/*! - *\brief Class representing a low-level, "flattened" flow graph - * - * This class holds the results of the call to gr.hier_block2.flatten(), - * which is a graph that has only the connected blocks and edges of - * the original hier_block2, with all the hierarchy removed. - * - * While this class is exported to Python via SWIG for ease of QA - * testing, it is not used by application developers, and there is - * no way to feed this to a gr.runtime() instance. - */ -class gr_simple_flowgraph -{ -private: - friend class gr_runtime_impl; - friend class gr_simple_flowgraph_detail; - friend class gr_hier_block2_detail; - friend gr_simple_flowgraph_sptr gr_make_simple_flowgraph(); - gr_simple_flowgraph(); - - gr_simple_flowgraph_detail *d_detail; - -public: - ~gr_simple_flowgraph(); - - void connect(gr_basic_block_sptr src_block, int src_port, - gr_basic_block_sptr dst_block, int dst_port); - void connect(const gr_endpoint &src, const gr_endpoint &dst); - void disconnect(gr_basic_block_sptr src_block, int src_port, - gr_basic_block_sptr dst_block, int dst_port); - void validate(); -}; - -#endif /* INCLUDED_GR_SIMPLE_FLOWGRAPH_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc deleted file mode 100644 index 2da2dad52..000000000 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc +++ /dev/null @@ -1,609 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#define GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG 0 - -gr_edge_sptr -gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst) -{ - return gr_edge_sptr(new gr_edge(src, dst)); -} - -gr_edge::~gr_edge() -{ -} - -gr_simple_flowgraph_detail::~gr_simple_flowgraph_detail() -{ -} - -void -gr_simple_flowgraph_detail::reset() -{ - // Boost shared pointers will deallocate as needed - d_edges.clear(); - d_blocks.clear(); -} - -void -gr_simple_flowgraph_detail::connect(const gr_endpoint &src, const gr_endpoint &dst) -{ - check_valid_port(src.block()->output_signature(), src.port()); - check_valid_port(dst.block()->input_signature(), dst.port()); - check_dst_not_used(dst); - check_type_match(src, dst); - d_edges.push_back(gr_make_edge(src,dst)); -} - -void -gr_simple_flowgraph_detail::disconnect(const gr_endpoint &src, const gr_endpoint &dst) -{ - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - if (src.block() == (*p)->src().block() && src.port() == (*p)->src().port() && - dst.block() == (*p)->dst().block() && dst.port() == (*p)->dst().port()) { - d_edges.erase(p); - return; - } - } - - throw std::invalid_argument("edge to disconnect not found"); -} - -void -gr_simple_flowgraph_detail::check_valid_port(gr_io_signature_sptr sig, int port) -{ - if (port < 0) - throw std::invalid_argument("negative port number"); - if (sig->max_streams() >= 0 && port >= sig->max_streams()) - throw std::invalid_argument("port number exceeds max"); -} - -void -gr_simple_flowgraph_detail::check_dst_not_used(const gr_endpoint &dst) -{ - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if ((*p)->dst().block() == dst.block() && - (*p)->dst().port() == dst.port()) - throw std::invalid_argument("dst already in use"); -} - -void -gr_simple_flowgraph_detail::check_type_match(const gr_endpoint &src, const gr_endpoint &dst) -{ - int src_size = src.block()->output_signature()->sizeof_stream_item(src.port()); - int dst_size = dst.block()->input_signature()->sizeof_stream_item(dst.port()); - - if (src_size != dst_size) - throw std::invalid_argument("type size mismatch while attempting to connect"); -} - -void -gr_simple_flowgraph_detail::validate() -{ - d_blocks = calc_used_blocks(); - - for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { - std::vector used_ports; - int ninputs, noutputs; - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Validating block: " << (*p) << std::endl; - - used_ports = calc_used_ports(*p, true); // inputs - ninputs = used_ports.size(); - check_contiguity(*p, used_ports, true); // inputs - - used_ports = calc_used_ports(*p, false); // outputs - noutputs = used_ports.size(); - check_contiguity(*p, used_ports, false); // outputs - - if (!((*p)->check_topology(ninputs, noutputs))) - throw std::runtime_error("check topology failed"); - } -} - -std::vector -gr_simple_flowgraph_detail::calc_used_ports(gr_basic_block_sptr block, bool check_inputs) -{ - std::vector tmp, result; - std::insert_iterator > inserter(result, result.begin()); - - gr_edge_vector_t edges = calc_connections(block, check_inputs); - for (gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) { - if (check_inputs == true) - tmp.push_back((*p)->dst().port()); - else - tmp.push_back((*p)->src().port()); - } - - // remove duplicates - std::sort(tmp.begin(), tmp.end()); - std::unique_copy(tmp.begin(), tmp.end(), inserter); - return result; -} - -gr_edge_vector_t -gr_simple_flowgraph_detail::calc_connections(gr_basic_block_sptr block, bool check_inputs) -{ - gr_edge_vector_t result; - - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - if (check_inputs) { - if ((*p)->dst().block() == block) - result.push_back(*p); - } - else { - if ((*p)->src().block() == block) - result.push_back(*p); - } - } - - return result; // assumes no duplicates -} - -void -gr_simple_flowgraph_detail::check_contiguity(gr_basic_block_sptr block, - const std::vector &used_ports, - bool check_inputs) -{ - gr_io_signature_sptr sig = - check_inputs ? block->input_signature() : block->output_signature(); - - int nports = used_ports.size(); - int min_ports = sig->min_streams(); - - if (nports == 0) { - if (min_ports == 0) - return; - else - throw std::runtime_error("insufficient ports"); - } - - if (used_ports[nports-1]+1 != nports) { - for (int i = 0; i < nports; i++) - if (used_ports[i] != i) - throw std::runtime_error("missing input assignment"); - } -} - -gr_basic_block_vector_t -gr_simple_flowgraph_detail::calc_downstream_blocks(gr_basic_block_sptr block, int port) -{ - gr_basic_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); - - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if ((*p)->src().block() == block && (*p)->src().port() == port) - tmp.push_back((*p)->dst().block()); - - // Remove duplicates - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; -} - -gr_basic_block_vector_t -gr_simple_flowgraph_detail::calc_downstream_blocks(gr_basic_block_sptr block) -{ - gr_basic_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); - - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if ((*p)->src().block() == block) - tmp.push_back((*p)->dst().block()); - - // Remove duplicates - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; -} - -gr_edge_vector_t -gr_simple_flowgraph_detail::calc_upstream_edges(gr_basic_block_sptr block) -{ - gr_edge_vector_t result; - - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if ((*p)->dst().block() == block) - result.push_back(*p); - - return result; // Assume no duplicates -} - -gr_basic_block_vector_t -gr_simple_flowgraph_detail::calc_used_blocks() -{ - gr_basic_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); - - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - tmp.push_back((*p)->src().block()); - tmp.push_back((*p)->dst().block()); - } - - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; -} - -std::vector -gr_simple_flowgraph_detail::partition() -{ - std::vector result; - gr_basic_block_vector_t blocks = calc_used_blocks(); - gr_basic_block_vector_t graph; - - while (blocks.size() > 0) { - graph = calc_reachable_blocks(blocks[0], blocks); - assert(graph.size()); - result.push_back(topological_sort(graph)); - - for (gr_basic_block_viter_t p = graph.begin(); p != graph.end(); p++) - blocks.erase(find(blocks.begin(), blocks.end(), *p)); - } - - return result; -} - -gr_basic_block_vector_t -gr_simple_flowgraph_detail::calc_reachable_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) -{ - gr_basic_block_vector_t result; - - // Mark all blocks as unvisited - for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) - boost::dynamic_pointer_cast(*p)->detail()->set_color(gr_block_detail::WHITE); - - // Recursively mark all reachable blocks - reachable_dfs_visit(block, blocks); - - // Collect all the blocks that have been visited - for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) - if ((boost::dynamic_pointer_cast(*p))->detail()->color() == gr_block_detail::BLACK) - result.push_back(*p); - - return result; -} - -// Recursively mark all reachable blocks from given block and block list -void -gr_simple_flowgraph_detail::reachable_dfs_visit(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) -{ - // Mark the current one as visited - boost::dynamic_pointer_cast(block)->detail()->set_color(gr_block_detail::BLACK); - - // Recurse into adjacent vertices - gr_basic_block_vector_t adjacent = calc_adjacent_blocks(block, blocks); - - for (gr_basic_block_viter_t p = adjacent.begin(); p != adjacent.end(); p++) - if (boost::dynamic_pointer_cast(*p)->detail()->color() == gr_block_detail::WHITE) - reachable_dfs_visit(*p, blocks); -} - -// Return a list of block adjacent to a given block along any edge -gr_basic_block_vector_t -gr_simple_flowgraph_detail::calc_adjacent_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) -{ - gr_basic_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); - - // Find any blocks that are inputs or outputs - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - - if ((*p)->src().block() == block) - tmp.push_back((*p)->dst().block()); - if ((*p)->dst().block() == block) - tmp.push_back((*p)->src().block()); - } - - // Remove duplicates - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; -} - -gr_block_vector_t -gr_simple_flowgraph_detail::topological_sort(gr_basic_block_vector_t &blocks) -{ - gr_basic_block_vector_t tmp; - gr_block_vector_t result; - tmp = sort_sources_first(blocks); - - // Start 'em all white - for (gr_basic_block_viter_t p = tmp.begin(); p != tmp.end(); p++) - boost::dynamic_pointer_cast(*p)->detail()->set_color(gr_block_detail::WHITE); - - for (gr_basic_block_viter_t p = tmp.begin(); p != tmp.end(); p++) { - if (boost::dynamic_pointer_cast(*p)->detail()->color() == gr_block_detail::WHITE) - topological_dfs_visit(*p, result); - } - - reverse(result.begin(), result.end()); - - return result; -} - -bool -gr_simple_flowgraph_detail::source_p(gr_basic_block_sptr block) -{ - return (calc_upstream_edges(block).size() == 0); -} - -gr_basic_block_vector_t -gr_simple_flowgraph_detail::sort_sources_first(gr_basic_block_vector_t &blocks) -{ - gr_basic_block_vector_t sources, nonsources, result; - - for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - if (source_p(*p)) - sources.push_back(*p); - else - nonsources.push_back(*p); - } - - for (gr_basic_block_viter_t p = sources.begin(); p != sources.end(); p++) - result.push_back(*p); - - for (gr_basic_block_viter_t p = nonsources.begin(); p != nonsources.end(); p++) - result.push_back(*p); - - return result; -} - -void -gr_simple_flowgraph_detail::topological_dfs_visit(gr_basic_block_sptr block, gr_block_vector_t &output) -{ - boost::dynamic_pointer_cast(block)->detail()->set_color(gr_block_detail::GREY); - - gr_basic_block_vector_t blocks(calc_downstream_blocks(block)); - - for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - switch (boost::dynamic_pointer_cast(*p)->detail()->color()) { - case gr_block_detail::WHITE: - topological_dfs_visit(*p, output); - break; - - case gr_block_detail::GREY: - throw std::runtime_error("flow graph has loops!"); - - case gr_block_detail::BLACK: - continue; - - default: - throw std::runtime_error("invalid color on block!"); - } - } - - gr_block_sptr result_block(boost::dynamic_pointer_cast(block)); - - result_block->detail()->set_color(gr_block_detail::BLACK); - output.push_back(result_block); -} - -bool -gr_simple_flowgraph_detail::has_block_p(gr_basic_block_sptr block) -{ - gr_basic_block_viter_t result; - result = std::find(d_blocks.begin(), d_blocks.end(), block); - return (result != d_blocks.end()); -} - -gr_edge_sptr -gr_simple_flowgraph_detail::calc_upstream_edge(gr_basic_block_sptr block, int port) -{ - gr_edge_sptr result; - - for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - if ((*p)->dst().block() == block && (*p)->dst().port() == port) { - result = (*p); - break; - } - } - - return result; -} - -gr_block_detail_sptr -gr_simple_flowgraph_detail::allocate_block_detail(gr_basic_block_sptr block, gr_block_detail_sptr old_detail) -{ - int ninputs = calc_used_ports(block, true).size(); - int noutputs = calc_used_ports(block, false).size(); - gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Creating block detail for " << block << std::endl; - - // Re-use or allocate output buffers - for (int i = 0; i < noutputs; i++) { - gr_buffer_sptr buffer; - - if (!old_detail || i >= old_detail->noutputs()) { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Allocating new buffer for output " << i << std::endl; - buffer = allocate_buffer(block, i); - } - else { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Reusing old buffer for output " << i << std::endl; - buffer = old_detail->output(i); - } - - detail->set_output(i, buffer); - } - - return detail; -} - -void -gr_simple_flowgraph_detail::connect_block_inputs(gr_basic_block_sptr block) -{ - gr_block_sptr grblock(boost::dynamic_pointer_cast(block)); - if (!grblock) - throw std::runtime_error("found non-gr_block"); - - // Get its detail and edges that feed into it - gr_block_detail_sptr detail = grblock->detail(); - gr_edge_vector_t in_edges = calc_upstream_edges(block); - - // For each edge that feeds into it - for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) { - // Set the buffer reader on the destination port to the output - // buffer on the source port - int dst_port = (*e)->dst().port(); - int src_port = (*e)->src().port(); - gr_basic_block_sptr src_block = (*e)->src().block(); - gr_block_sptr src_grblock(boost::dynamic_pointer_cast(src_block)); - if (!grblock) - throw std::runtime_error("found non-gr_block"); - gr_buffer_sptr src_buffer = src_grblock->detail()->output(src_port); - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Setting input " << dst_port << " from edge " << (*e) << std::endl; - - detail->set_input(dst_port, gr_buffer_add_reader(src_buffer, grblock->history()-1)); - } -} - -gr_buffer_sptr -gr_simple_flowgraph_detail::allocate_buffer(gr_basic_block_sptr block, int port) -{ - gr_block_sptr grblock(boost::dynamic_pointer_cast(block)); - if (!grblock) - throw std::runtime_error("allocate_buffer found non-gr_block"); - int item_size = block->output_signature()->sizeof_stream_item(port); - int nitems = s_fixed_buffer_size/item_size; - - // Make sure there are at least twice the output_multiple no. of items - if (nitems < 2*grblock->output_multiple()) // Note: this means output_multiple() - nitems = 2*grblock->output_multiple(); // can't be changed by block dynamically - - // If any downstream blocks are decimators and/or have a large output_multiple, - // ensure we have a buffer at least twice their decimation factor*output_multiple - gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); - for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - gr_block_sptr dgrblock(boost::dynamic_pointer_cast(*p)); - if (!dgrblock) - throw std::runtime_error("allocate_buffer found non-gr_block"); - int decimation = (int)(1.0/dgrblock->relative_rate()); - int multiple = dgrblock->output_multiple(); - int history = dgrblock->history(); - nitems = std::max(nitems, 2*(decimation*multiple+history)); - } - - return gr_make_buffer(nitems, item_size); -} - -void -gr_simple_flowgraph_detail::setup_connections() -{ - // Assign block details to blocks - for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) - boost::dynamic_pointer_cast(*p)->set_detail(allocate_block_detail(*p)); - - // Connect inputs to outputs for each block - for(gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) - connect_block_inputs(*p); -} - -void -gr_simple_flowgraph_detail::merge_connections(gr_simple_flowgraph_sptr old_sfg) -{ - std::map old_details; - - // Allocate or reuse output buffers - for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { - gr_block_sptr block(boost::dynamic_pointer_cast(*p)); - - gr_block_detail_sptr old_detail = block->detail(); - block->set_detail(allocate_block_detail(block, old_detail)); - - // Save old detail for use in next step - old_details[block] = old_detail; - } - - for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { - gr_block_sptr block(boost::dynamic_pointer_cast(*p)); - - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "merge: testing " << (*p) << "..."; - - if (old_sfg->d_detail->has_block_p(*p)) { - // Block exists in old flow graph - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "used in old flow graph" << std::endl; - gr_block_detail_sptr detail = block->detail(); - - // Iterate through the inputs and see what needs to be done - for (int i = 0; i < detail->ninputs(); i++) { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "Checking input " << i << "..."; - - gr_edge_sptr edge = calc_upstream_edge(*p, i); - if (!edge) - throw std::runtime_error("merge: missing input edge"); - - // Fish out old buffer reader and see if it matches correct buffer from edge list - gr_block_sptr src_block(boost::dynamic_pointer_cast(edge->src().block())); - gr_block_detail_sptr src_detail = src_block->detail(); - gr_buffer_sptr src_buffer = src_detail->output(edge->src().port()); - gr_buffer_reader_sptr old_reader; - gr_block_detail_sptr old_detail = old_details[block]; - if (old_detail && i < old_detail->ninputs()) - old_reader = old_detail->input(i); - - // If there's a match, use it - if (old_reader && (src_buffer == old_reader->buffer())) { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "matched" << std::endl; - detail->set_input(i, old_reader); - - } - else { - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "needs a new reader" << std::endl; - - // Create new buffer reader and assign - detail->set_input(i, gr_buffer_add_reader(src_buffer, block->history()-1)); - } - } - } - else { - // Block is new, it just needs buffer readers at this point - if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) - std::cout << "new block" << std::endl; - connect_block_inputs(block); - } - } -} diff --git a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h b/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h deleted file mode 100644 index 53b620350..000000000 --- a/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_SIMPLE_FLOWGRAPH_DETAIL_H -#define INCLUDED_GR_SIMPLE_FLOWGRAPH_DETAIL_H - -#include -#include -#include - -#define GR_FIXED_BUFFER_SIZE (32*(1L<<10)) - -class gr_edge; -typedef boost::shared_ptr gr_edge_sptr; -gr_edge_sptr gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst); - -class gr_edge -{ -private: - friend gr_edge_sptr gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst); - gr_edge(const gr_endpoint &src, const gr_endpoint &dst) : d_src(src), d_dst(dst) { } - - gr_endpoint d_src; - gr_endpoint d_dst; - -public: - ~gr_edge(); - - const gr_endpoint &src() const { return d_src; } - const gr_endpoint &dst() const { return d_dst; } -}; - -typedef std::vector gr_edge_vector_t; -typedef std::vector::iterator gr_edge_viter_t; - -class gr_simple_flowgraph_detail -{ -private: - friend class gr_simple_flowgraph; - friend class gr_runtime_impl; - friend class gr_hier_block2_detail; - friend class topo_block_cmp; - - gr_simple_flowgraph_detail() : d_blocks(), d_edges() { } - - gr_basic_block_vector_t d_blocks; - gr_edge_vector_t d_edges; - static const unsigned int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE; - - void reset(); - void connect(const gr_endpoint &src, const gr_endpoint &dst); - void disconnect(const gr_endpoint &src, const gr_endpoint &dst); - void check_valid_port(gr_io_signature_sptr sig, int port); - void check_dst_not_used(const gr_endpoint &dst); - void check_type_match(const gr_endpoint &src, const gr_endpoint &dst); - void validate(); - gr_edge_vector_t calc_connections(gr_basic_block_sptr block, bool check_inputs); // false=use outputs - std::vector calc_used_ports(gr_basic_block_sptr block, bool check_inputs); - void check_contiguity(gr_basic_block_sptr block, const std::vector &used_ports, bool check_inputs); - void setup_connections(); - void merge_connections(gr_simple_flowgraph_sptr sfg); - - void connect_block_inputs(gr_basic_block_sptr block); - gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block, - gr_block_detail_sptr old_detail=gr_block_detail_sptr()); - gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port); - gr_basic_block_vector_t calc_downstream_blocks(gr_basic_block_sptr block, int port); - gr_basic_block_vector_t calc_downstream_blocks(gr_basic_block_sptr block); - gr_edge_sptr calc_upstream_edge(gr_basic_block_sptr block, int port); - gr_edge_vector_t calc_upstream_edges(gr_basic_block_sptr block); - gr_basic_block_vector_t calc_used_blocks(); - std::vector partition(); - gr_basic_block_vector_t calc_reachable_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks); - gr_block_vector_t topological_sort(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); - bool source_p(gr_basic_block_sptr block); - gr_basic_block_vector_t sort_sources_first(gr_basic_block_vector_t &blocks); - void topological_dfs_visit(gr_basic_block_sptr block, gr_block_vector_t &output); - bool has_block_p(gr_basic_block_sptr block); - -public: - ~gr_simple_flowgraph_detail(); -}; - -inline std::ostream& -operator <<(std::ostream &os, const gr_endpoint endp) -{ - os << endp.block() << ":" << endp.port(); - return os; -} - -inline std::ostream& -operator <<(std::ostream &os, const gr_edge_sptr edge) -{ - os << edge->src() << "->" << edge->dst(); - return os; -} - -inline void -enumerate_edges(gr_edge_vector_t &edges) -{ - std::cout << "Edge list has " << edges.size() << " elements" << std::endl; - for(gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) - std::cout << *p << std::endl; -} - -#endif /* INCLUDED_GR_SIMPLE_FLOWGRAPH_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc new file mode 100644 index 000000000..c883c1678 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc @@ -0,0 +1,245 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +void qa_gr_flowgraph::t0() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + CPPUNIT_ASSERT(fg); +} + +void qa_gr_flowgraph::t1_connect() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); +} + +void qa_gr_flowgraph::t2_connect_invalid_src_port_neg() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(nop1, -1, nop2, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t3_connect_src_port_exceeds() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(src, 1, dst, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t4_connect_invalid_dst_port_neg() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(nop1, 0, nop2, -1), std::invalid_argument); +} + +void qa_gr_flowgraph::t5_connect_dst_port_exceeds() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(src, 0, dst, 1), std::invalid_argument); +} + +void qa_gr_flowgraph::t6_connect_dst_in_use() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr src1 = gr_make_null_source(sizeof(int)); + gr_block_sptr src2 = gr_make_null_source(sizeof(int)); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + fg->connect(src1, 0, dst, 0); + CPPUNIT_ASSERT_THROW(fg->connect(src2, 0, dst, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t7_connect_one_src_two_dst() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr dst1 = gr_make_null_sink(sizeof(int)); + gr_block_sptr dst2 = gr_make_null_sink(sizeof(int)); + + fg->connect(src, 0, dst1, 0); + fg->connect(src, 0, dst2, 0); +} + +void qa_gr_flowgraph::t8_connect_type_mismatch() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(char)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + CPPUNIT_ASSERT_THROW(fg->connect(nop1, 0, nop2, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t9_disconnect() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + fg->disconnect(nop1, 0, nop2, 0); +} + +void qa_gr_flowgraph::t10_disconnect_unconnected_block() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + gr_block_sptr nop3 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + CPPUNIT_ASSERT_THROW(fg->disconnect(nop1, 0, nop3, 0), std::invalid_argument); +} + +void qa_gr_flowgraph::t11_disconnect_unconnected_port() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + CPPUNIT_ASSERT_THROW(fg->disconnect(nop1, 0, nop2, 1), std::invalid_argument); +} + +void qa_gr_flowgraph::t12_validate() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + fg->validate(); +} + +void qa_gr_flowgraph::t13_validate_missing_input_assignment() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + fg->connect(nop1, 0, nop2, 2); + CPPUNIT_ASSERT_THROW(fg->validate(), std::runtime_error); +} + +void qa_gr_flowgraph::t14_validate_missing_output_assignment() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + fg->connect(nop1, 2, nop2, 1); + CPPUNIT_ASSERT_THROW(fg->validate(), std::runtime_error); +} + +void qa_gr_flowgraph::t15_clear() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop1 = gr_make_nop(sizeof(int)); + gr_block_sptr nop2 = gr_make_nop(sizeof(int)); + + fg->connect(nop1, 0, nop2, 0); + + CPPUNIT_ASSERT(fg->edges().size() == 1); + CPPUNIT_ASSERT(fg->calc_used_blocks().size() == 2); + + fg->clear(); + + CPPUNIT_ASSERT(fg->edges().size() == 0); + CPPUNIT_ASSERT(fg->calc_used_blocks().size() == 0); +} + +void qa_gr_flowgraph::t16_partition() +{ + gr_flowgraph_sptr fg = gr_make_flowgraph(); + + gr_block_sptr nop11 = gr_make_nop(sizeof(int)); + gr_block_sptr nop12 = gr_make_nop(sizeof(int)); + gr_block_sptr nop13 = gr_make_nop(sizeof(int)); + gr_block_sptr nop14 = gr_make_nop(sizeof(int)); + + gr_block_sptr nop21 = gr_make_nop(sizeof(int)); + gr_block_sptr nop22 = gr_make_nop(sizeof(int)); + gr_block_sptr nop23 = gr_make_nop(sizeof(int)); + + gr_block_sptr nop31 = gr_make_nop(sizeof(int)); + gr_block_sptr nop32 = gr_make_nop(sizeof(int)); + + // Build disjoint graph #1 + fg->connect(nop11, 0, nop12, 0); + fg->connect(nop12, 0, nop13, 0); + fg->connect(nop13, 0, nop14, 0); + + // Build disjoint graph #2 + fg->connect(nop21, 0, nop22, 0); + fg->connect(nop22, 0, nop23, 0); + + // Build disjoint graph #3 + fg->connect(nop31, 0, nop32, 0); + + std::vector graphs = fg->partition(); + + CPPUNIT_ASSERT(graphs.size() == 3); + CPPUNIT_ASSERT(graphs[0].size() == 4); + CPPUNIT_ASSERT(graphs[1].size() == 3); + CPPUNIT_ASSERT(graphs[2].size() == 2); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h b/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h new file mode 100644 index 000000000..2253afccd --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h @@ -0,0 +1,75 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_QA_GR_FLOWGRAPH_H +#define INCLUDED_QA_GR_FLOWGRAPH_H + +#include +#include +#include + +class qa_gr_flowgraph : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_gr_flowgraph); + + CPPUNIT_TEST(t0); + CPPUNIT_TEST(t1_connect); + CPPUNIT_TEST(t2_connect_invalid_src_port_neg); + CPPUNIT_TEST(t3_connect_src_port_exceeds); + CPPUNIT_TEST(t4_connect_invalid_dst_port_neg); + CPPUNIT_TEST(t5_connect_dst_port_exceeds); + CPPUNIT_TEST(t6_connect_dst_in_use); + CPPUNIT_TEST(t7_connect_one_src_two_dst); + CPPUNIT_TEST(t8_connect_type_mismatch); + CPPUNIT_TEST(t9_disconnect); + CPPUNIT_TEST(t10_disconnect_unconnected_block); + CPPUNIT_TEST(t11_disconnect_unconnected_port); + CPPUNIT_TEST(t12_validate); + CPPUNIT_TEST(t13_validate_missing_input_assignment); + CPPUNIT_TEST(t14_validate_missing_output_assignment); + CPPUNIT_TEST(t15_clear); + CPPUNIT_TEST(t16_partition); + + CPPUNIT_TEST_SUITE_END(); + +private: + + void t0(); + void t1_connect(); + void t2_connect_invalid_src_port_neg(); + void t3_connect_src_port_exceeds(); + void t4_connect_invalid_dst_port_neg(); + void t5_connect_dst_port_exceeds(); + void t6_connect_dst_in_use(); + void t7_connect_one_src_two_dst(); + void t8_connect_type_mismatch(); + void t9_disconnect(); + void t10_disconnect_unconnected_block(); + void t11_disconnect_unconnected_port(); + void t12_validate(); + void t13_validate_missing_input_assignment(); + void t14_validate_missing_output_assignment(); + void t15_clear(); + void t16_partition(); +}; + +#endif /* INCLUDED_QA_GR_FLOWGRAPH_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 2abdc36b3..5c00a4fbe 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -1,5 +1,5 @@ /* - * Copyright 2002 Free Software Foundation, Inc. + * Copyright 2002,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,7 @@ qa_runtime::suite () s->addTest (qa_gr_vmcircbuf::suite ()); s->addTest (qa_gr_io_signature::suite ()); s->addTest (qa_gr_block::suite ()); + s->addTest (qa_gr_flowgraph::suite ()); s->addTest (qa_gr_hier_block2::suite ()); s->addTest (qa_gr_buffer::suite ()); -- cgit From c088a546ac7ae55748e5421201f3387f3e1286f9 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 27 Aug 2007 18:49:11 +0000 Subject: Merged r6171:6186 from jcorgan/fg into trunk. Changes hierarchical flow graph API to use gr.top_block instead of gr.runtime. See discuss-gnuradio mailing list for explanation of changes. GRC has not been updated to use the changed API. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6187 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 16 +- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 22 +- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 48 ++-- .../src/lib/runtime/gr_hier_block2_detail.cc | 10 +- .../src/lib/runtime/gr_hier_block2_detail.h | 2 - gnuradio-core/src/lib/runtime/gr_runtime.cc | 89 -------- gnuradio-core/src/lib/runtime/gr_runtime.h | 105 --------- gnuradio-core/src/lib/runtime/gr_runtime.i | 82 ------- gnuradio-core/src/lib/runtime/gr_runtime_impl.cc | 253 --------------------- gnuradio-core/src/lib/runtime/gr_runtime_impl.h | 95 -------- gnuradio-core/src/lib/runtime/gr_runtime_types.h | 5 +- .../src/lib/runtime/gr_scheduler_thread.cc | 75 ++++++ .../src/lib/runtime/gr_scheduler_thread.h | 58 +++++ gnuradio-core/src/lib/runtime/gr_top_block.cc | 87 +++++++ gnuradio-core/src/lib/runtime/gr_top_block.h | 95 ++++++++ gnuradio-core/src/lib/runtime/gr_top_block.i | 71 ++++++ gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 210 +++++++++++++++++ gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 71 ++++++ gnuradio-core/src/lib/runtime/qa_gr_top_block.cc | 110 +++++++++ gnuradio-core/src/lib/runtime/qa_gr_top_block.h | 51 +++++ gnuradio-core/src/lib/runtime/qa_runtime.cc | 2 + gnuradio-core/src/lib/runtime/runtime.i | 4 +- 22 files changed, 881 insertions(+), 680 deletions(-) delete mode 100644 gnuradio-core/src/lib/runtime/gr_runtime.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_runtime.h delete mode 100644 gnuradio-core/src/lib/runtime/gr_runtime.i delete mode 100644 gnuradio-core/src/lib/runtime/gr_runtime_impl.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_runtime_impl.h create mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler_thread.h create mode 100644 gnuradio-core/src/lib/runtime/gr_top_block.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_top_block.h create mode 100644 gnuradio-core/src/lib/runtime/gr_top_block.i create mode 100644 gnuradio-core/src/lib/runtime/gr_top_block_impl.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_top_block_impl.h create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_top_block.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_top_block.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 346f23b6a..4b51f7f4d 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2003,2004 Free Software Foundation, Inc. +# Copyright 2003,2004,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -48,12 +48,13 @@ libruntime_la_SOURCES = \ gr_pagesize.cc \ gr_preferences.cc \ gr_realtime.cc \ - gr_runtime.cc \ - gr_runtime_impl.cc \ + gr_scheduler_thread.cc \ gr_single_threaded_scheduler.cc \ gr_sync_block.cc \ gr_sync_decimator.cc \ gr_sync_interpolator.cc \ + gr_top_block.cc \ + gr_top_block_impl.cc \ gr_tmp_path.cc \ gr_vmcircbuf.cc \ gr_vmcircbuf_mmap_shm_open.cc \ @@ -67,6 +68,7 @@ libruntime_qa_la_SOURCES = \ qa_gr_hier_block2.cc \ qa_gr_buffer.cc \ qa_gr_flowgraph.cc \ + qa_gr_top_block.cc \ qa_gr_io_signature.cc \ qa_gr_vmcircbuf.cc \ qa_runtime.cc @@ -91,14 +93,15 @@ grinclude_HEADERS = \ gr_pagesize.h \ gr_preferences.h \ gr_realtime.h \ - gr_runtime.h \ - gr_runtime_impl.h \ gr_runtime_types.h \ + gr_scheduler_thread.h \ gr_select_handler.h \ gr_single_threaded_scheduler.h \ gr_sync_block.h \ gr_sync_decimator.h \ gr_sync_interpolator.h \ + gr_top_block.h \ + gr_top_block_impl.h \ gr_timer.h \ gr_tmp_path.h \ gr_types.h \ @@ -114,6 +117,7 @@ noinst_HEADERS = \ qa_gr_hier_block2.h \ qa_gr_buffer.h \ qa_gr_io_signature.h \ + qa_gr_top_block.h \ qa_gr_vmcircbuf.h \ qa_runtime.h @@ -130,12 +134,12 @@ swiginclude_HEADERS = \ gr_msg_handler.i \ gr_msg_queue.i \ gr_realtime.i \ - gr_runtime.i \ gr_single_threaded_scheduler.i \ gr_sync_block.i \ gr_sync_decimator.i \ gr_sync_interpolator.i \ gr_swig_block_magic.i \ + gr_top_block.i \ runtime.i MOSTLYCLEANFILES = *~ *.loT diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index 5b6688412..890638bae 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -35,7 +35,7 @@ gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature) { - return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); + return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); } gr_hier_block2::gr_hier_block2(const std::string &name, @@ -48,39 +48,37 @@ gr_hier_block2::gr_hier_block2(const std::string &name, gr_hier_block2::~gr_hier_block2() { - delete d_detail; + delete d_detail; } void gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { - d_detail->connect(src, src_port, dst, dst_port); + d_detail->connect(src, src_port, dst, dst_port); } void gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { - d_detail->disconnect(src, src_port, dst, dst_port); + d_detail->disconnect(src, src_port, dst, dst_port); } void -gr_hier_block2::set_runtime(gr_runtime *runtime) +gr_hier_block2::lock() { - if (GR_HIER_BLOCK2_DEBUG) - std::cout << "Setting runtime on " << this << " to " << runtime << std::endl; - d_detail->set_runtime(runtime); + d_detail->lock(); } void -gr_hier_block2::lock() +gr_hier_block2::unlock() { - d_detail->lock(); + d_detail->unlock(); } void -gr_hier_block2::unlock() +gr_hier_block2::flatten(gr_flat_flowgraph_sptr ffg) { - d_detail->unlock(); + d_detail->flatten(ffg); } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 02ce10106..75223d149 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -40,34 +40,32 @@ class gr_hier_block2_detail; class gr_hier_block2 : public gr_basic_block { private: - friend class gr_hier_block2_detail; - friend class gr_runtime_impl; - friend gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - - /*! - * \brief Private implementation details of gr_hier_block2 - */ - gr_hier_block2_detail *d_detail; - - /* Internal use only */ - void set_runtime(gr_runtime *runtime); - + friend class gr_hier_block2_detail; + friend gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + + /*! + * \brief Private implementation details of gr_hier_block2 + */ + gr_hier_block2_detail *d_detail; + protected: - gr_hier_block2(const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - + gr_hier_block2(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + public: - virtual ~gr_hier_block2(); + virtual ~gr_hier_block2(); + + void connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port); + void disconnect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port); + virtual void lock(); + virtual void unlock(); - void connect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port); - void disconnect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port); - void lock(); - void unlock(); + void flatten(gr_flat_flowgraph_sptr ffg); }; #endif /* INCLUDED_GR_HIER_BLOCK2_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 99131afb6..15c898c77 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -36,8 +35,7 @@ gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : d_parent_detail(0), d_fg(gr_make_flowgraph()), d_inputs(owner->input_signature()->max_streams()), - d_outputs(owner->output_signature()->max_streams()), - d_runtime() + d_outputs(owner->output_signature()->max_streams()) { } @@ -263,8 +261,7 @@ gr_hier_block2_detail::lock() if (d_parent_detail) d_parent_detail->lock(); else - if (d_runtime) - d_runtime->lock(); + d_owner->lock(); } void @@ -276,6 +273,5 @@ gr_hier_block2_detail::unlock() if (d_parent_detail) d_parent_detail->unlock(); else - if (d_runtime) - d_runtime->unlock(); + d_owner->unlock(); } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index b315061be..ace22ea9a 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -40,7 +40,6 @@ private: gr_flowgraph_sptr d_fg; gr_endpoint_vector_t d_inputs; gr_endpoint_vector_t d_outputs; - gr_runtime *d_runtime; // Private implementation methods void connect(gr_basic_block_sptr src, int src_port, @@ -54,7 +53,6 @@ private: void flatten(gr_flat_flowgraph_sptr sfg); gr_endpoint resolve_port(int port, bool is_input); gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input); - void set_runtime(gr_runtime *runtime) { d_runtime = runtime; } void lock(); void unlock(); diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.cc b/gnuradio-core/src/lib/runtime/gr_runtime.cc deleted file mode 100644 index 6b1419e20..000000000 --- a/gnuradio-core/src/lib/runtime/gr_runtime.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -gr_runtime_sptr -gr_make_runtime(gr_hier_block2_sptr top_block) -{ - return gr_runtime_sptr(new gr_runtime(top_block)); -} - -gr_runtime::gr_runtime(gr_hier_block2_sptr top_block) -{ - d_impl = new gr_runtime_impl(top_block, this); -} - -gr_runtime::~gr_runtime() -{ - delete d_impl; -} - -void -gr_runtime::start() -{ - d_impl->start(); -} - -void -gr_runtime::stop() -{ - d_impl->stop(); -} - -void -gr_runtime::wait() -{ - d_impl->wait(); -} - -void -gr_runtime::run() -{ - start(); - wait(); -} - -void -gr_runtime::restart() -{ - d_impl->restart(); -} - -void -gr_runtime::lock() -{ - d_impl->lock(); -} - -void -gr_runtime::unlock() -{ - d_impl->unlock(); -} - diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.h b/gnuradio-core/src/lib/runtime/gr_runtime.h deleted file mode 100644 index 1168b3eda..000000000 --- a/gnuradio-core/src/lib/runtime/gr_runtime.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_RUNTIME_H -#define INCLUDED_GR_RUNTIME_H - -#include - -class gr_runtime_impl; - -gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); - -/*! - *\brief Runtime object that controls simple flow graph operation - * - * This class is instantiated with a top-level gr_hier_block2. The - * runtime then flattens the hierarchical block into a gr_simple_flowgraph, - * and allows control through start(), stop(), wait(), and run(). - * - */ -class gr_runtime -{ -private: - gr_runtime(gr_hier_block2_sptr top_block); - friend gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); - - gr_runtime_impl *d_impl; - -public: - ~gr_runtime(); - - /*! - * Start the flow graph. Creates an undetached scheduler thread for - * each flow graph partition. Returns to caller once created. - */ - void start(); - - /*! - * Stop a running flow graph. Tells each created scheduler thread - * to exit, then returns to caller. - */ - void stop(); - - /*! - * Wait for a stopped flow graph to complete. Joins each completed - * thread. - */ - void wait(); - - /*! - * Calls start(), then wait(). Used to run a flow graph that will stop - * on its own, or to run a flow graph indefinitely until SIGTERM is - * received(). - */ - void run(); - - /*! - * Restart a running flow graph, after topology changes have - * been made to its top_block (or children). Causes each created - * scheduler thread to end, recalculates the flow graph, and - * recreates new threads (possibly a different number from before.) - */ - void restart(); - - /*! - * Lock a flow graph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flow graph - * will be restarted automatically. - * - * N.B. lock() and unlock() cannot be called from a flow graph thread or - * deadlock will occur when reconfiguration happens. - */ - void lock(); - - /*! - * Lock a flow graph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flow graph - * will be restarted automatically. - * - * N.B. lock() and unlock() cannot be called from a flow graph thread or - * deadlock will occur when reconfiguration happens. - */ - void unlock(); -}; - -#endif /* INCLUDED_GR_RUNTIME_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_runtime.i b/gnuradio-core/src/lib/runtime/gr_runtime.i deleted file mode 100644 index d750553a4..000000000 --- a/gnuradio-core/src/lib/runtime/gr_runtime.i +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2006,2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -class gr_runtime; -typedef boost::shared_ptr gr_runtime_sptr; -%template(gr_runtime_sptr) boost::shared_ptr; - -gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block); - -class gr_runtime -{ -protected: - gr_runtime(gr_hier_block2_sptr top_block); - -public: - void run() throw (std::runtime_error); - void start() throw (std::runtime_error); - void stop() throw (std::runtime_error); - void wait() throw (std::runtime_error); - void restart() throw (std::runtime_error); -}; - -%{ -class ensure_py_gil_state2 { - PyGILState_STATE d_gstate; -public: - ensure_py_gil_state2() { d_gstate = PyGILState_Ensure(); } - ~ensure_py_gil_state2() { PyGILState_Release(d_gstate); } -}; -%} - -%inline %{ -void runtime_run_unlocked(gr_runtime_sptr r) throw (std::runtime_error) -{ - ensure_py_gil_state2 _lock; - r->run(); -} - -void runtime_start_unlocked(gr_runtime_sptr r) throw (std::runtime_error) -{ - ensure_py_gil_state2 _lock; - r->start(); -} - -void runtime_stop_unlocked(gr_runtime_sptr r) throw (std::runtime_error) -{ - ensure_py_gil_state2 _lock; - r->stop(); -} - -void runtime_wait_unlocked(gr_runtime_sptr r) throw (std::runtime_error) -{ - ensure_py_gil_state2 _lock; - r->wait(); -} - -void runtime_restart_unlocked(gr_runtime_sptr r) throw (std::runtime_error) -{ - ensure_py_gil_state2 _lock; - r->restart(); -} - -%} diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc b/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc deleted file mode 100644 index 30a39f1d8..000000000 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc +++ /dev/null @@ -1,253 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_SIGNAL_H -#include -#endif - -#include -#include - -#define GR_RUNTIME_IMPL_DEBUG 0 - -static gr_runtime_impl *s_runtime = 0; - -// Make a vector of gr_block from a vector of gr_basic_block -static -gr_block_vector_t -make_gr_block_vector(gr_basic_block_vector_t &blocks) -{ - gr_block_vector_t result; - for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - result.push_back(make_gr_block_sptr(*p)); - } - - return result; -} - -// FIXME: This prevents using more than one gr_runtime instance -void -runtime_sigint_handler(int signum) -{ - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "SIGINT received, calling stop() on all threads" << std::endl; - - if (s_runtime) - s_runtime->stop(); -} - -gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block, gr_runtime *owner) - : d_running(false), - d_top_block(top_block), - d_ffg(gr_make_flat_flowgraph()), - d_owner(owner) -{ - s_runtime = this; - top_block->set_runtime(d_owner); -} - -gr_runtime_impl::~gr_runtime_impl() -{ - s_runtime = 0; // don't call delete we don't own these - d_owner = 0; -} - -void -gr_runtime_impl::start() -{ - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "start: entered" << std::endl; - - if (d_running) - throw std::runtime_error("already running"); - - // Create new simple flow graph by flattening hierarchical block - d_ffg->clear(); - d_top_block->d_detail->flatten(d_ffg); - - // Validate new simple flow graph and wire it up - d_ffg->validate(); - d_ffg->setup_connections(); - - // Execute scheduler threads - start_threads(); -} - -void -gr_runtime_impl::start_threads() -{ - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "start_threads: entered" << std::endl; - - d_graphs = d_ffg->partition(); - for (std::vector::iterator p = d_graphs.begin(); - p != d_graphs.end(); p++) { - gr_scheduler_thread *thread = new gr_scheduler_thread(make_gr_block_vector(*p)); - d_threads.push_back(thread); - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "start_threads: starting " << thread << std::endl; - thread->start(); - } - - d_running = true; -} - -void -gr_runtime_impl::stop() -{ - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "stop: entered" << std::endl; - - for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "stop: stopping thread " << (*p) << std::endl; - (*p)->stop(); - } - - d_running = false; -} - -void -gr_runtime_impl::wait() -{ - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "wait: entered" << std::endl; - - void *dummy_status; // don't ever dereference this - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - - for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "wait: joining thread " << (*p) << std::endl; - (*p)->join(&dummy_status); // pthreads will self-delete, so pointer is now dead - (*p) = 0; // FIXME: switch to stl::list and actually remove from container - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "wait: join returned" << std::endl; - } - - d_threads.clear(); -} - - -// N.B. lock() and unlock() cannot be called from a flow graph thread or -// deadlock will occur when reconfiguration happens -void -gr_runtime_impl::lock() -{ - omni_mutex_lock lock(d_reconf); - d_lock_count++; - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "runtime: locked, count = " << d_lock_count << std::endl; -} - -void -gr_runtime_impl::unlock() -{ - omni_mutex_lock lock(d_reconf); - if (d_lock_count == 0) - throw std::runtime_error("unpaired unlock() call"); - - d_lock_count--; - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "runtime: unlocked, count = " << d_lock_count << std::endl; - - if (d_lock_count == 0) - restart(); -} - -void -gr_runtime_impl::restart() -{ - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "restart: entered" << std::endl; - - if (!d_running) - throw std::runtime_error("not running"); - - // Stop scheduler threads and wait for completion - stop(); - wait(); - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "restart: threads stopped" << std::endl; - - // Create new simple flow graph - gr_flat_flowgraph_sptr new_ffg = gr_make_flat_flowgraph(); - d_top_block->d_detail->flatten(new_ffg); - new_ffg->validate(); - new_ffg->merge_connections(d_ffg); - - if (GR_RUNTIME_IMPL_DEBUG) - std::cout << "restart: replacing old flow graph with new" << std::endl; - d_ffg = new_ffg; - - start_threads(); -} - -gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) : - omni_thread(NULL, PRIORITY_NORMAL), - d_sts(gr_make_single_threaded_scheduler(graph)) -{ -} - -gr_scheduler_thread::~gr_scheduler_thread() -{ -} - -void gr_scheduler_thread::start() -{ - start_undetached(); -} - -void * -gr_scheduler_thread::run_undetached(void *arg) -{ - // First code to run in new thread context - - // Mask off SIGINT in this thread to gaurantee mainline thread gets signal -#ifdef HAVE_SIGPROCMASK - sigset_t old_set; - sigset_t new_set; - sigemptyset(&new_set); - sigaddset(&new_set, SIGINT); - sigprocmask(SIG_BLOCK, &new_set, &old_set); -#endif - // Run the single-threaded scheduler - d_sts->run(); - return 0; -} - -void -gr_scheduler_thread::stop() -{ - d_sts->stop(); -} diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h b/gnuradio-core/src/lib/runtime/gr_runtime_impl.h deleted file mode 100644 index f6230018a..000000000 --- a/gnuradio-core/src/lib/runtime/gr_runtime_impl.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_RUNTIME_IMPL_H -#define INCLUDED_GR_RUNTIME_IMPL_H - -#include -#include -#include -#include - -// omnithread calls delete on itself after thread exits, so can't use shared ptr -class gr_scheduler_thread; -typedef std::vector gr_scheduler_thread_vector_t; -typedef gr_scheduler_thread_vector_t::iterator gr_scheduler_thread_viter_t; - -/*! - *\brief A single thread of execution for the scheduler - * - * This class implements a single thread that runs undetached, and - * invokes the single-threaded block scheduler. The runtime makes - * one of these for each distinct partition of a flowgraph and runs - * them in parallel. - * - */ -class gr_scheduler_thread : public omni_thread -{ -private: - gr_single_threaded_scheduler_sptr d_sts; - -public: - gr_scheduler_thread(gr_block_vector_t graph); - ~gr_scheduler_thread(); - - virtual void *run_undetached(void *arg); - void start(); - void stop(); -}; - -/*! - *\brief Implementation details of gr_runtime - * - * The actual implementation of gr_runtime. Separate class allows - * decoupling of changes from dependent classes. - * - */ -class gr_runtime_impl -{ -private: - gr_runtime_impl(gr_hier_block2_sptr top_block, gr_runtime *owner); - friend void runtime_sigint_handler(int signum); - friend class gr_runtime; - - bool d_running; - gr_hier_block2_sptr d_top_block; - gr_flat_flowgraph_sptr d_ffg; - std::vector d_graphs; - gr_scheduler_thread_vector_t d_threads; - gr_runtime *d_owner; - int d_lock_count; - omni_mutex d_reconf; - - void start(); - void start_threads(); - void stop(); - void wait(); - void restart(); - void lock(); - void unlock(); - -public: - ~gr_runtime_impl(); - -}; - -#endif /* INCLUDED_GR_RUNTIME_IMPL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_types.h b/gnuradio-core/src/lib/runtime/gr_runtime_types.h index 8af663cdf..74d2614a8 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_types.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_types.h @@ -38,7 +38,8 @@ class gr_buffer; class gr_buffer_reader; class gr_flowgraph; class gr_flat_flowgraph; -class gr_runtime; +class gr_top_block; +class gr_top_block_detail; typedef boost::shared_ptr gr_basic_block_sptr; typedef boost::shared_ptr gr_block_sptr; @@ -47,8 +48,8 @@ typedef boost::shared_ptr gr_hier_block2_sptr; typedef boost::shared_ptr gr_io_signature_sptr; typedef boost::shared_ptr gr_buffer_sptr; typedef boost::shared_ptr gr_buffer_reader_sptr; -typedef boost::shared_ptr gr_runtime_sptr; typedef boost::shared_ptr gr_flowgraph_sptr; typedef boost::shared_ptr gr_flat_flowgraph_sptr; +typedef boost::shared_ptr gr_top_block_sptr; #endif /* INCLUDED_GR_RUNTIME_TYPES_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc new file mode 100644 index 000000000..9cce5eaec --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc @@ -0,0 +1,75 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#ifdef HAVE_SIGNAL_H +#include +#endif + +#define GR_SCHEDULER_THREAD_DEBUG 0 + +gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) : + omni_thread(NULL, PRIORITY_NORMAL), + d_sts(gr_make_single_threaded_scheduler(graph)) +{ +} + +gr_scheduler_thread::~gr_scheduler_thread() +{ +} + +void gr_scheduler_thread::start() +{ + start_undetached(); +} + +void * +gr_scheduler_thread::run_undetached(void *arg) +{ + // First code to run in new thread context + + // Mask off SIGINT in this thread to gaurantee mainline thread gets signal +#ifdef HAVE_SIGPROCMASK + sigset_t old_set; + sigset_t new_set; + sigemptyset(&new_set); + sigaddset(&new_set, SIGINT); + sigprocmask(SIG_BLOCK, &new_set, &old_set); +#endif + // Run the single-threaded scheduler + d_sts->run(); + return 0; +} + +void +gr_scheduler_thread::stop() +{ + if (GR_SCHEDULER_THREAD_DEBUG) + std::cout << "gr_scheduler_thread::stop()" << std::endl; + d_sts->stop(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h new file mode 100644 index 000000000..c989f797c --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_SCHEDULER_THREAD_H +#define INCLUDED_GR_SCHEDULER_THREAD_H + +#include +#include +#include + +// omnithread calls delete on itself after thread exits, so can't use shared ptr +class gr_scheduler_thread; +typedef std::vector gr_scheduler_thread_vector_t; +typedef gr_scheduler_thread_vector_t::iterator gr_scheduler_thread_viter_t; + +/*! + *\brief A single thread of execution for the scheduler + * + * This class implements a single thread that runs undetached, and + * invokes the single-threaded block scheduler. The runtime makes + * one of these for each distinct partition of a flowgraph and runs + * them in parallel. + * + */ +class gr_scheduler_thread : public omni_thread +{ +private: + gr_single_threaded_scheduler_sptr d_sts; + +public: + gr_scheduler_thread(gr_block_vector_t graph); + ~gr_scheduler_thread(); + + virtual void *run_undetached(void *arg); + void start(); + void stop(); +}; + +#endif /* INCLUDED_GR_SCHEDULER_THREAD_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc new file mode 100644 index 000000000..407df8bba --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -0,0 +1,87 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +gr_top_block_sptr +gr_make_top_block(const std::string &name) +{ + return gr_top_block_sptr(new gr_top_block(name)); +} + +gr_top_block::gr_top_block(const std::string &name) + : gr_hier_block2(name, + gr_make_io_signature(0,0,0), + gr_make_io_signature(0,0,0)) + +{ + d_impl = new gr_top_block_impl(this); +} + +gr_top_block::~gr_top_block() +{ + delete d_impl; +} + +void +gr_top_block::start() +{ + d_impl->start(); +} + +void +gr_top_block::stop() +{ + d_impl->stop(); +} + +void +gr_top_block::wait() +{ + d_impl->wait(); +} + +void +gr_top_block::run() +{ + start(); + wait(); +} + +void +gr_top_block::lock() +{ + d_impl->lock(); +} + +void +gr_top_block::unlock() +{ + d_impl->unlock(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h new file mode 100644 index 000000000..16fd97074 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -0,0 +1,95 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TOP_BLOCK_H +#define INCLUDED_GR_TOP_BLOCK_H + +#include + +class gr_top_block_impl; + +gr_top_block_sptr gr_make_top_block(const std::string &name); + +/*! + *\brief Top-level hierarchical block representing a flowgraph + * + */ +class gr_top_block : public gr_hier_block2 +{ +private: + friend gr_top_block_sptr gr_make_top_block(const std::string &name); + + gr_top_block_impl *d_impl; + +protected: + gr_top_block(const std::string &name); + +public: + ~gr_top_block(); + + /*! + * Start the enclosed flowgraph. Creates an undetached scheduler thread for + * each flow graph partition. Returns to caller once created. + */ + void start(); + + /*! + * Stop the running flowgraph. Tells each created scheduler thread + * to exit, then returns to caller. + */ + void stop(); + + /*! + * Wait for a stopped flowgraph to complete. Joins each completed + * thread. + */ + void wait(); + + /*! + * Calls start(), then wait(). Used to run a flowgraph that will stop + * on its own, or to run a flowgraph indefinitely until SIGKILL is + * received(). + */ + void run(); + + /*! + * Lock a flowgraph in preparation for reconfiguration. When an equal + * number of calls to lock() and unlock() have occurred, the flowgraph + * will be restarted automatically. + * + * N.B. lock() and unlock() cannot be called from a flowgraph thread or + * deadlock will occur when reconfiguration happens. + */ + virtual void lock(); + + /*! + * Lock a flowgraph in preparation for reconfiguration. When an equal + * number of calls to lock() and unlock() have occurred, the flowgraph + * will be restarted automatically. + * + * N.B. lock() and unlock() cannot be called from a flowgraph thread or + * deadlock will occur when reconfiguration happens. + */ + virtual void unlock(); +}; + +#endif /* INCLUDED_GR_TOP_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i new file mode 100644 index 000000000..d310f2aea --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +%include + +class gr_top_block; +typedef boost::shared_ptr gr_top_block_sptr; +%template(gr_top_block_sptr) boost::shared_ptr; + +// Hack to have a Python shim implementation of gr.top_block +// that instantiates one of these and passes through calls +%rename(top_block_swig) gr_make_top_block; +gr_top_block_sptr gr_make_top_block(const std::string name); + +class gr_top_block : public gr_hier_block2 +{ +private: + gr_top_block(const std::string &name); + +public: + ~gr_top_block(); + + void start(); + void stop(); + void wait(); + void run(); + void lock(); + void unlock(); +}; + +%{ +class ensure_py_gil_state2 { + PyGILState_STATE d_gstate; +public: + ensure_py_gil_state2() { d_gstate = PyGILState_Ensure(); } + ~ensure_py_gil_state2() { PyGILState_Release(d_gstate); } +}; +%} + +%inline %{ +void top_block_run_unlocked(gr_top_block_sptr r) throw (std::runtime_error) +{ + ensure_py_gil_state2 _lock; + r->run(); +} + +void top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error) +{ + ensure_py_gil_state2 _lock; + r->wait(); +} +%} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc new file mode 100644 index 000000000..f0b67ddde --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -0,0 +1,210 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#include +#include + +#define GR_TOP_BLOCK_IMPL_DEBUG 0 + +static gr_top_block_impl *s_impl = 0; + +// Make a vector of gr_block from a vector of gr_basic_block +static +gr_block_vector_t +make_gr_block_vector(gr_basic_block_vector_t &blocks) +{ + gr_block_vector_t result; + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + result.push_back(make_gr_block_sptr(*p)); + } + + return result; +} + +// FIXME: This prevents using more than one gr_top_block instance +static void +runtime_sigint_handler(int signum) +{ + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "SIGINT received, calling stop()" << std::endl; + + if (s_impl) + s_impl->stop(); +} + +gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) + : d_running(false), + d_ffg(gr_make_flat_flowgraph()), + d_owner(owner), + d_lock_count(0) +{ + s_impl = this; +} + +gr_top_block_impl::~gr_top_block_impl() +{ + s_impl = 0; // don't call delete we don't own these + d_owner = 0; +} + +void +gr_top_block_impl::start() +{ + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "start: entered" << std::endl; + + if (d_running) + throw std::runtime_error("already running"); + + // Create new flat flow graph by flattening hierarchy + d_ffg->clear(); + d_owner->flatten(d_ffg); + + // Validate new simple flow graph and wire it up + d_ffg->validate(); + d_ffg->setup_connections(); + + // Execute scheduler threads + start_threads(); +} + +void +gr_top_block_impl::start_threads() +{ + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "start_threads: entered" << std::endl; + + d_graphs = d_ffg->partition(); + for (std::vector::iterator p = d_graphs.begin(); + p != d_graphs.end(); p++) { + gr_scheduler_thread *thread = new gr_scheduler_thread(make_gr_block_vector(*p)); + d_threads.push_back(thread); + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "start_threads: starting " << thread << std::endl; + thread->start(); + } + + d_running = true; +} + +void +gr_top_block_impl::stop() +{ + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "stop: entered" << std::endl; + + for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "stop: stopping thread " << (*p) << std::endl; + (*p)->stop(); + } + + d_running = false; +} + +void +gr_top_block_impl::wait() +{ + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "wait: entered" << std::endl; + + void *dummy_status; // don't ever dereference this + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); + + for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "wait: joining thread " << (*p) << std::endl; + (*p)->join(&dummy_status); // pthreads will self-delete, so pointer is now dead + (*p) = 0; // FIXME: switch to stl::list and actually remove from container + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "wait: join returned" << std::endl; + } + + d_threads.clear(); +} + +// N.B. lock() and unlock() cannot be called from a flow graph thread or +// deadlock will occur when reconfiguration happens +void +gr_top_block_impl::lock() +{ + omni_mutex_lock lock(d_reconf); + d_lock_count++; + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "runtime: locked, count = " << d_lock_count << std::endl; +} + +void +gr_top_block_impl::unlock() +{ + omni_mutex_lock lock(d_reconf); + if (d_lock_count == 0) + throw std::runtime_error("unpaired unlock() call"); + + d_lock_count--; + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "unlock: unlocked, count = " << d_lock_count << std::endl; + + if (d_lock_count == 0) { + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "unlock: restarting flowgraph" << std::endl; + restart(); + } +} + +void +gr_top_block_impl::restart() +{ + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "restart: entered" << std::endl; + + if (!d_running) + throw std::runtime_error("not running"); + + // Stop scheduler threads and wait for completion + stop(); + wait(); + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "restart: threads stopped" << std::endl; + + // Create new simple flow graph + gr_flat_flowgraph_sptr new_ffg = gr_make_flat_flowgraph(); + d_owner->flatten(new_ffg); + new_ffg->validate(); + new_ffg->merge_connections(d_ffg); + + if (GR_TOP_BLOCK_IMPL_DEBUG) + std::cout << "restart: replacing old flow graph with new" << std::endl; + d_ffg = new_ffg; + + start_threads(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h new file mode 100644 index 000000000..8052ce4fa --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TOP_BLOCK_IMPL_H +#define INCLUDED_GR_TOP_BLOCK_IMPL_H + +#include + +/*! + *\brief Implementation details of gr_top_block + * + * The actual implementation of gr_top_block. Separate class allows + * decoupling of changes from dependent classes. + * + */ +class gr_top_block_impl +{ +public: + gr_top_block_impl(gr_top_block *owner); + ~gr_top_block_impl(); + + // Create and start scheduler threads + void start(); + + // Signal scheduler threads to stop + void stop(); + + // Wait for scheduler threads to exit + void wait(); + + // Lock the top block to allow reconfiguration + void lock(); + + // Unlock the top block at end of reconfiguration + void unlock(); + +private: + + bool d_running; + gr_flat_flowgraph_sptr d_ffg; + gr_scheduler_thread_vector_t d_threads; + gr_top_block *d_owner; + int d_lock_count; + omni_mutex d_reconf; + + std::vector d_graphs; + + void start_threads(); + void restart(); +}; + +#endif /* INCLUDED_GR_TOP_BLOCK_IMPL_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc new file mode 100644 index 000000000..3322b6ac4 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc @@ -0,0 +1,110 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +void qa_gr_top_block::t0() +{ + gr_top_block_sptr tb = gr_make_top_block("top"); + + CPPUNIT_ASSERT(tb); +} + +void qa_gr_top_block::t1_run() +{ + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 1); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->run(); +} + +void qa_gr_top_block::t2_start_stop_wait() +{ + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 1000000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + + tb->start(); + tb->stop(); + tb->wait(); +} + +void qa_gr_top_block::t3_lock_unlock() +{ + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 1000000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + + tb->start(); + + tb->lock(); + tb->unlock(); + + tb->stop(); + tb->wait(); +} + +void qa_gr_top_block::t4_reconfigure() +{ + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 1); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + // Start infinite flowgraph + tb->connect(src, 0, dst, 0); + tb->start(); + + // Reconfigure with gr_head in the middle + tb->lock(); + tb->disconnect(src, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->unlock(); + + // Wait for flowgraph to end on its own + tb->wait(); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h new file mode 100644 index 000000000..9a243452d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_QA_GR_TOP_BLOCK_H +#define INCLUDED_QA_GR_TOP_BLOCK_H + +#include +#include +#include + +class qa_gr_top_block : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_gr_top_block); + + CPPUNIT_TEST(t0); + CPPUNIT_TEST(t1_run); + CPPUNIT_TEST(t2_start_stop_wait); + CPPUNIT_TEST(t3_lock_unlock); + // CPPUNIT_TEST(t4_reconfigure); triggers 'join never returns' bug + + CPPUNIT_TEST_SUITE_END(); + +private: + + void t0(); + void t1_run(); + void t2_start_stop_wait(); + void t3_lock_unlock(); + void t4_reconfigure(); +}; + +#endif /* INCLUDED_QA_GR_TOP_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 5c00a4fbe..ba0f14b93 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -46,6 +47,7 @@ qa_runtime::suite () s->addTest (qa_gr_io_signature::suite ()); s->addTest (qa_gr_block::suite ()); s->addTest (qa_gr_flowgraph::suite ()); + s->addTest (qa_gr_top_block::suite ()); s->addTest (qa_gr_hier_block2::suite ()); s->addTest (qa_gr_buffer::suite ()); diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index d162cff9b..20cf68a03 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include #include +#include %} %include @@ -54,7 +54,7 @@ %include %include %include -%include %include %include %include +%include -- cgit From 02cd43b565615593f90bd08eb4e718a6ee649661 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 28 Aug 2007 05:59:31 +0000 Subject: Kludged around hang in hier_block2. Merged -r6189:6191 from eb/fg into trunk. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6193 221aa14e-8319-0410-a670-987f0aec2ac5 --- .../src/lib/runtime/gr_scheduler_thread.cc | 6 +++++- .../lib/runtime/gr_single_threaded_scheduler.cc | 10 +++++++++- .../src/lib/runtime/gr_single_threaded_scheduler.h | 2 +- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 2 +- gnuradio-core/src/lib/runtime/qa_gr_top_block.cc | 23 ++++++++++++++++------ gnuradio-core/src/lib/runtime/qa_gr_top_block.h | 2 +- 6 files changed, 34 insertions(+), 11 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc index 9cce5eaec..16f36ac56 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc @@ -45,6 +45,9 @@ gr_scheduler_thread::~gr_scheduler_thread() void gr_scheduler_thread::start() { + if (GR_SCHEDULER_THREAD_DEBUG) + std::cout << "gr_scheduler_thread::start() " + << this << std::endl; start_undetached(); } @@ -70,6 +73,7 @@ void gr_scheduler_thread::stop() { if (GR_SCHEDULER_THREAD_DEBUG) - std::cout << "gr_scheduler_thread::stop()" << std::endl; + std::cout << "gr_scheduler_thread::stop() " + << this << std::endl; d_sts->stop(); } diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc index 6aaaf954b..b2fbdb73b 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc @@ -82,10 +82,18 @@ gr_single_threaded_scheduler::~gr_single_threaded_scheduler () void gr_single_threaded_scheduler::run () { - d_enabled = true; + // d_enabled = true; // KLUDGE main_loop (); } +void +gr_single_threaded_scheduler::stop () +{ + if (0) + std::cout << "gr_singled_threaded_scheduler::stop() " + << this << std::endl; + d_enabled = false; +} inline static unsigned int round_up (unsigned int n, unsigned int multiple) diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h index 139e50b13..060d3017d 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h @@ -40,7 +40,7 @@ class gr_single_threaded_scheduler { ~gr_single_threaded_scheduler (); void run (); - void stop () { d_enabled = false; } + void stop (); private: const std::vector d_blocks; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index f0b67ddde..679654077 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -167,7 +167,7 @@ void gr_top_block_impl::unlock() { omni_mutex_lock lock(d_reconf); - if (d_lock_count == 0) + if (d_lock_count <= 0) throw std::runtime_error("unpaired unlock() call"); d_lock_count--; diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc index 3322b6ac4..52677f0de 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc @@ -29,9 +29,14 @@ #include #include #include +#include + +#define VERBOSE 0 void qa_gr_top_block::t0() { + if (VERBOSE) std::cout << "qa_gr_top_block::t0()\n"; + gr_top_block_sptr tb = gr_make_top_block("top"); CPPUNIT_ASSERT(tb); @@ -39,10 +44,12 @@ void qa_gr_top_block::t0() void qa_gr_top_block::t1_run() { + if (VERBOSE) std::cout << "qa_gr_top_block::t1()\n"; + gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src = gr_make_null_source(sizeof(int)); - gr_block_sptr head = gr_make_head(sizeof(int), 1); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); gr_block_sptr dst = gr_make_null_sink(sizeof(int)); tb->connect(src, 0, head, 0); @@ -52,10 +59,12 @@ void qa_gr_top_block::t1_run() void qa_gr_top_block::t2_start_stop_wait() { + if (VERBOSE) std::cout << "qa_gr_top_block::t2()\n"; + gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src = gr_make_null_source(sizeof(int)); - gr_block_sptr head = gr_make_head(sizeof(int), 1000000); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); gr_block_sptr dst = gr_make_null_sink(sizeof(int)); tb->connect(src, 0, head, 0); @@ -68,14 +77,14 @@ void qa_gr_top_block::t2_start_stop_wait() void qa_gr_top_block::t3_lock_unlock() { + if (VERBOSE) std::cout << "qa_gr_top_block::t3()\n"; + gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src = gr_make_null_source(sizeof(int)); - gr_block_sptr head = gr_make_head(sizeof(int), 1000000); gr_block_sptr dst = gr_make_null_sink(sizeof(int)); - tb->connect(src, 0, head, 0); - tb->connect(head, 0, dst, 0); + tb->connect(src, 0, dst, 0); tb->start(); @@ -88,10 +97,12 @@ void qa_gr_top_block::t3_lock_unlock() void qa_gr_top_block::t4_reconfigure() { + if (VERBOSE) std::cout << "qa_gr_top_block::t4()\n"; + gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src = gr_make_null_source(sizeof(int)); - gr_block_sptr head = gr_make_head(sizeof(int), 1); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); gr_block_sptr dst = gr_make_null_sink(sizeof(int)); // Start infinite flowgraph diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h index 9a243452d..278b5ffb4 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h @@ -35,7 +35,7 @@ class qa_gr_top_block : public CppUnit::TestCase CPPUNIT_TEST(t1_run); CPPUNIT_TEST(t2_start_stop_wait); CPPUNIT_TEST(t3_lock_unlock); - // CPPUNIT_TEST(t4_reconfigure); triggers 'join never returns' bug + CPPUNIT_TEST(t4_reconfigure); // triggers 'join never returns' bug CPPUNIT_TEST_SUITE_END(); -- cgit From 9b7a98d56ffefa71fb9d0b14cf7d56740dc890c8 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 28 Aug 2007 06:12:16 +0000 Subject: Refactored flatten into const-correct functional form. Beauty reigns. Merged -r6191:6192 from eb/fg. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6194 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 8 +++++--- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 6 +++--- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 14 ++++++-------- 5 files changed, 17 insertions(+), 17 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index 890638bae..f531e76ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -77,8 +77,10 @@ gr_hier_block2::unlock() d_detail->unlock(); } -void -gr_hier_block2::flatten(gr_flat_flowgraph_sptr ffg) +gr_flat_flowgraph_sptr +gr_hier_block2::flatten() const { - d_detail->flatten(ffg); + gr_flat_flowgraph_sptr new_ffg = gr_make_flat_flowgraph(); + d_detail->flatten_aux(new_ffg); + return new_ffg; } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 75223d149..ba25b4b87 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -65,7 +65,7 @@ public: virtual void lock(); virtual void unlock(); - void flatten(gr_flat_flowgraph_sptr ffg); + gr_flat_flowgraph_sptr flatten() const; }; #endif /* INCLUDED_GR_HIER_BLOCK2_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 15c898c77..e1b11205a 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -204,7 +204,7 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) } gr_endpoint -gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) +gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) const { // Check if endpoint is a leaf node if (boost::dynamic_pointer_cast(endp.block())) @@ -225,7 +225,7 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) } void -gr_hier_block2_detail::flatten(gr_flat_flowgraph_sptr sfg) +gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "flattening " << d_owner->name() << std::endl; @@ -248,7 +248,7 @@ gr_hier_block2_detail::flatten(gr_flat_flowgraph_sptr sfg) for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(*p)); if (hier_block2) - hier_block2->d_detail->flatten(sfg); + hier_block2->d_detail->flatten_aux(sfg); } } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index ace22ea9a..b692d1080 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -50,9 +50,9 @@ private: void connect_output(int my_port, int port, gr_basic_block_sptr block); void disconnect_input(int my_port, int port, gr_basic_block_sptr block); void disconnect_output(int my_port, int port, gr_basic_block_sptr block); - void flatten(gr_flat_flowgraph_sptr sfg); + void flatten_aux(gr_flat_flowgraph_sptr sfg) const; gr_endpoint resolve_port(int port, bool is_input); - gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input); + gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input) const; void lock(); void unlock(); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 679654077..f25ab2b3e 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -63,7 +63,7 @@ runtime_sigint_handler(int signum) gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) : d_running(false), - d_ffg(gr_make_flat_flowgraph()), + d_ffg(), d_owner(owner), d_lock_count(0) { @@ -86,8 +86,7 @@ gr_top_block_impl::start() throw std::runtime_error("already running"); // Create new flat flow graph by flattening hierarchy - d_ffg->clear(); - d_owner->flatten(d_ffg); + d_ffg = d_owner->flatten(); // Validate new simple flow graph and wire it up d_ffg->validate(); @@ -196,11 +195,10 @@ gr_top_block_impl::restart() if (GR_TOP_BLOCK_IMPL_DEBUG) std::cout << "restart: threads stopped" << std::endl; - // Create new simple flow graph - gr_flat_flowgraph_sptr new_ffg = gr_make_flat_flowgraph(); - d_owner->flatten(new_ffg); - new_ffg->validate(); - new_ffg->merge_connections(d_ffg); + // Create new simple flow graph + gr_flat_flowgraph_sptr new_ffg = d_owner->flatten(); + new_ffg->validate(); // check consistency, sanity, etc + new_ffg->merge_connections(d_ffg); // reuse buffers, etc if (GR_TOP_BLOCK_IMPL_DEBUG) std::cout << "restart: replacing old flow graph with new" << std::endl; -- cgit From 29576322fe8ef81e1f5b7cbafe62f413ccc2c911 Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 29 Aug 2007 00:42:11 +0000 Subject: trial fix for ticket:137. Merged -r6196:6200 from eb/signal to trunk git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6201 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 21 +++++++++++ .../src/lib/runtime/gr_scheduler_thread.cc | 40 ++++++++++++++++++--- gnuradio-core/src/lib/runtime/gr_top_block.cc | 3 ++ gnuradio-core/src/lib/runtime/gr_top_block.h | 41 +++++++++++++--------- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 40 ++++++++++++++------- 5 files changed, 111 insertions(+), 34 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index ba25b4b87..51eb687ed 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -60,9 +60,30 @@ public: void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); + void disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); + + /*! + * Lock a flowgraph in preparation for reconfiguration. When an equal + * number of calls to lock() and unlock() have occurred, the flowgraph + * will be restarted automatically. + * + * N.B. lock() and unlock() cannot be called from a flowgraph thread + * (E.g., gr_block::work method) or deadlock will occur when + * reconfiguration happens. + */ virtual void lock(); + + /*! + * Lock a flowgraph in preparation for reconfiguration. When an equal + * number of calls to lock() and unlock() have occurred, the flowgraph + * will be restarted automatically. + * + * N.B. lock() and unlock() cannot be called from a flowgraph thread + * (E.g., gr_block::work method) or deadlock will occur when + * reconfiguration happens. + */ virtual void unlock(); gr_flat_flowgraph_sptr flatten() const; diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc index 16f36ac56..bc8f9b97e 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc @@ -54,15 +54,45 @@ void gr_scheduler_thread::start() void * gr_scheduler_thread::run_undetached(void *arg) { - // First code to run in new thread context + // This is the first code to run in the new thread context. - // Mask off SIGINT in this thread to gaurantee mainline thread gets signal -#ifdef HAVE_SIGPROCMASK + /* + * In general, on a *nix system, any thread of a process can receive + * any asynchronous signal. + * + * http://www.serpentine.com/blog/threads-faq/mixing-threads-and-signals-unix/ + * http://www.linuxjournal.com/article/2121 + * + * We really don't want to be handling asynchronous signals such + * as SIGINT and SIGHUP here. We mask them off in the signal + * processing threads so that they'll get handled by the mainline + * thread. We leave the synchronous signals SIGQUIT, SIGBUS, + * SIGILL, SIGSEGV etc alone + * + * FIXME? It might be better to mask them all off in the parent + * thread then dedicate a single thread to handling all signals + * using sigwait. + */ +#if defined(HAVE_PTHREAD_SIGMASK) || defined(HAVE_SIGPROCMASK) sigset_t old_set; sigset_t new_set; + int r; sigemptyset(&new_set); sigaddset(&new_set, SIGINT); - sigprocmask(SIG_BLOCK, &new_set, &old_set); + sigaddset(&new_set, SIGHUP); + sigaddset(&new_set, SIGPIPE); + sigaddset(&new_set, SIGALRM); + sigaddset(&new_set, SIGCHLD); + +#ifdef HAVE_PTHREAD_SIGMASK + r = pthread_sigmask(SIG_BLOCK, &new_set, &old_set); + if (r != 0) + perror("pthread_sigmask"); +#else + r = sigprocmask(SIG_BLOCK, &new_set, &old_set); + if (r != 0) + perror("sigprocmask"); +#endif #endif // Run the single-threaded scheduler d_sts->run(); @@ -72,7 +102,7 @@ gr_scheduler_thread::run_undetached(void *arg) void gr_scheduler_thread::stop() { - if (GR_SCHEDULER_THREAD_DEBUG) + if (0 && GR_SCHEDULER_THREAD_DEBUG) // FIXME not safe to call from signal handler std::cout << "gr_scheduler_thread::stop() " << this << std::endl; d_sts->stop(); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 407df8bba..91248d347 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -46,6 +46,9 @@ gr_top_block::gr_top_block(const std::string &name) gr_top_block::~gr_top_block() { + stop(); + wait(); + delete d_impl; } diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 16fd97074..d74903841 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -47,37 +47,43 @@ public: ~gr_top_block(); /*! - * Start the enclosed flowgraph. Creates an undetached scheduler thread for - * each flow graph partition. Returns to caller once created. + * \brief The simple interface to running a flowgraph. + * + * Calls start() then wait(). Used to run a flowgraph that will stop + * on its own, or to run a flowgraph indefinitely until SIGINT is + * received. + */ + void run(); + + /*! + * Start the contained flowgraph. Creates one or more threads to + * execute the flow graph. Returns to the caller once the threads + * are created. */ void start(); /*! - * Stop the running flowgraph. Tells each created scheduler thread - * to exit, then returns to caller. + * Stop the running flowgraph. Notifies each thread created by the + * scheduler to shutdown, then returns to caller. */ void stop(); /*! - * Wait for a stopped flowgraph to complete. Joins each completed - * thread. + * Wait for a flowgraph to complete. Flowgraphs complete when + * either (1) all blocks indicate that they are done (typically only + * when using gr.file_source, or gr.head, or (2) after stop() has been + * called to request shutdown. */ void wait(); - /*! - * Calls start(), then wait(). Used to run a flowgraph that will stop - * on its own, or to run a flowgraph indefinitely until SIGKILL is - * received(). - */ - void run(); - /*! * Lock a flowgraph in preparation for reconfiguration. When an equal * number of calls to lock() and unlock() have occurred, the flowgraph * will be restarted automatically. * - * N.B. lock() and unlock() cannot be called from a flowgraph thread or - * deadlock will occur when reconfiguration happens. + * N.B. lock() and unlock() cannot be called from a flowgraph thread + * (E.g., gr_block::work method) or deadlock will occur when + * reconfiguration happens. */ virtual void lock(); @@ -86,8 +92,9 @@ public: * number of calls to lock() and unlock() have occurred, the flowgraph * will be restarted automatically. * - * N.B. lock() and unlock() cannot be called from a flowgraph thread or - * deadlock will occur when reconfiguration happens. + * N.B. lock() and unlock() cannot be called from a flowgraph thread + * (E.g., gr_block::work method) or deadlock will occur when + * reconfiguration happens. */ virtual void unlock(); }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index f25ab2b3e..340e81afd 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -32,15 +32,19 @@ #include #include +#include #define GR_TOP_BLOCK_IMPL_DEBUG 0 static gr_top_block_impl *s_impl = 0; -// Make a vector of gr_block from a vector of gr_basic_block -static -gr_block_vector_t -make_gr_block_vector(gr_basic_block_vector_t &blocks) +/*! + * Make a vector of gr_block from a vector of gr_basic_block + * + * Pass-by-value to avoid problem with possible asynchronous modification + */ +static gr_block_vector_t +make_gr_block_vector(gr_basic_block_vector_t blocks) { gr_block_vector_t result; for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { @@ -51,22 +55,30 @@ make_gr_block_vector(gr_basic_block_vector_t &blocks) } // FIXME: This prevents using more than one gr_top_block instance + static void runtime_sigint_handler(int signum) { - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "SIGINT received, calling stop()" << std::endl; + if (GR_TOP_BLOCK_IMPL_DEBUG){ + char *msg = "SIGINT received, calling stop()\n"; + ::write(1, msg, strlen(msg)); // write is OK to call from signal handler + } if (s_impl) s_impl->stop(); } +// ---------------------------------------------------------------- + gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) : d_running(false), d_ffg(), d_owner(owner), d_lock_count(0) { + if (s_impl) + throw std::logic_error("gr_top_block_impl: multiple simultaneous gr_top_block's"); + s_impl = this; } @@ -115,18 +127,22 @@ gr_top_block_impl::start_threads() d_running = true; } +/* + * N.B. as currently implemented, it is possible that this may be + * invoked by the SIGINT handler which is fragile as hell... + */ void gr_top_block_impl::stop() { - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "stop: entered" << std::endl; + if (GR_TOP_BLOCK_IMPL_DEBUG){ + char *msg = "stop: entered\n"; + ::write(1, msg, strlen(msg)); + } for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "stop: stopping thread " << (*p) << std::endl; - (*p)->stop(); + if (*p) + (*p)->stop(); } - d_running = false; } -- cgit From 0786370660817056e2ecb6b9793894678445a1a8 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Wed, 29 Aug 2007 19:03:41 +0000 Subject: Fixes ticket:172 and ticket:174 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6207 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 4 +- gnuradio-core/src/lib/runtime/gr_flowgraph.cc | 71 ++++++++++--- .../src/lib/runtime/gr_hier_block2_detail.cc | 114 +++++++++++++++------ gnuradio-core/src/lib/runtime/gr_top_block.i | 3 +- 4 files changed, 141 insertions(+), 51 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index d7f3ffb51..0a73d716d 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -128,7 +128,7 @@ gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) { gr_block_sptr grblock = make_gr_block_sptr(block); if (!grblock) - throw std::runtime_error("found non-gr_block"); + throw std::runtime_error("connect_block_inputs found non-gr_block"); // Get its detail and edges that feed into it gr_block_detail_sptr detail = grblock->detail(); @@ -143,7 +143,7 @@ gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) gr_basic_block_sptr src_block = e->src().block(); gr_block_sptr src_grblock = make_gr_block_sptr(src_block); if (!src_grblock) - throw std::runtime_error("found non-gr_block"); + throw std::runtime_error("connect_block_inputs found non-gr_block"); gr_buffer_sptr src_buffer = src_grblock->detail()->output(src_port); if (GR_FLAT_FLOWGRAPH_DEBUG) diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc index 8e96dba75..f4879f085 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc @@ -27,7 +27,7 @@ #include #include #include -#include +#include #define GR_FLOWGRAPH_DEBUG 0 @@ -70,7 +70,9 @@ gr_flowgraph::disconnect(const gr_endpoint &src, const gr_endpoint &dst) } } - throw std::invalid_argument("edge to disconnect not found"); + std::stringstream msg; + msg << "cannot disconnect edge " << gr_edge(src, dst) << ", not found"; + throw std::invalid_argument(msg.str()); } void @@ -93,8 +95,13 @@ gr_flowgraph::validate() noutputs = used_ports.size(); check_contiguity(*p, used_ports, false); // outputs - if (!((*p)->check_topology(ninputs, noutputs))) - throw std::runtime_error("check topology failed"); + if (!((*p)->check_topology(ninputs, noutputs))) { + std::stringstream msg; + msg << "check topology failed on " << (*p) + << " using ninputs=" << ninputs + << ", noutputs=" << noutputs; + throw std::runtime_error(msg.str()); + } } } @@ -109,10 +116,22 @@ gr_flowgraph::clear() void gr_flowgraph::check_valid_port(gr_io_signature_sptr sig, int port) { - if (port < 0) - throw std::invalid_argument("negative port number"); - if (sig->max_streams() >= 0 && port >= sig->max_streams()) - throw std::invalid_argument("port number exceeds max"); + std::stringstream msg; + + if (port < 0) { + msg << "negative port number " << port << " is invalid"; + throw std::invalid_argument(msg.str()); + } + + int max = sig->max_streams(); + if (max >= 0 && port >= max) { + msg << "port number " << port << " exceeds max of "; + if (max == 0) + msg << "(none)"; + else + msg << max-1; + throw std::invalid_argument(msg.str()); + } } void @@ -120,8 +139,11 @@ gr_flowgraph::check_dst_not_used(const gr_endpoint &dst) { // A destination is in use if it is already on the edge list for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) - if (p->dst() == dst) - throw std::invalid_argument("dst already in use"); + if (p->dst() == dst) { + std::stringstream msg; + msg << "destination already in use by edge " << (*p); + throw std::invalid_argument(msg.str()); + } } void @@ -130,8 +152,12 @@ gr_flowgraph::check_type_match(const gr_endpoint &src, const gr_endpoint &dst) int src_size = src.block()->output_signature()->sizeof_stream_item(src.port()); int dst_size = dst.block()->input_signature()->sizeof_stream_item(dst.port()); - if (src_size != dst_size) - throw std::invalid_argument("itemsize mismatch between src and dst"); + if (src_size != dst_size) { + std::stringstream msg; + msg << "itemsize mismatch: " << src << " using " << src_size + << ", " << dst << " using " << dst_size; + throw std::invalid_argument(msg.str()); + } } gr_basic_block_vector_t @@ -197,6 +223,8 @@ gr_flowgraph::check_contiguity(gr_basic_block_sptr block, const std::vector &used_ports, bool check_inputs) { + std::stringstream msg; + gr_io_signature_sptr sig = check_inputs ? block->input_signature() : block->output_signature(); @@ -206,14 +234,23 @@ gr_flowgraph::check_contiguity(gr_basic_block_sptr block, if (nports == 0) { if (min_ports == 0) return; - else - throw std::runtime_error("insufficient ports"); + else { + msg << block << ": insufficient connected " + << (check_inputs ? "input ports " : "output ports ") + << "(" << min_ports+1 << " needed, " << nports+1 << " connected)"; + throw std::runtime_error(msg.str()); + } } if (used_ports[nports-1]+1 != nports) { - for (int i = 0; i < nports; i++) - if (used_ports[i] != i) - throw std::runtime_error("missing input assignment"); + for (int i = 0; i < nports; i++) { + if (used_ports[i] != i) { + msg << block << ": missing connection " + << (check_inputs ? "to input port " : "from output port ") + << i; + throw std::runtime_error(msg.str()); + } + } } } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index e1b11205a..1412a284c 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -26,7 +26,7 @@ #include #include #include -#include +#include #define GR_HIER_BLOCK2_DETAIL_DEBUG 0 @@ -48,12 +48,14 @@ void gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { + std::stringstream msg; + if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "connecting: " << gr_endpoint(src, src_port) << " -> " << gr_endpoint(dst, dst_port) << std::endl; if (src.get() == dst.get()) - throw std::invalid_argument("src and destination blocks cannot be the same"); + throw std::invalid_argument("connect: src and destination blocks cannot be the same"); gr_hier_block2_sptr src_block(boost::dynamic_pointer_cast(src)); gr_hier_block2_sptr dst_block(boost::dynamic_pointer_cast(dst)); @@ -74,15 +76,21 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, int max_port; if (src.get() == d_owner) { max_port = src->input_signature()->max_streams(); - if ((max_port != -1 && (src_port >= max_port)) || src_port < 0) - throw std::invalid_argument("source port out of range"); + if ((max_port != -1 && (src_port >= max_port)) || src_port < 0) { + msg << "source port " << src_port << " out of range for " << src; + throw std::invalid_argument(msg.str()); + } + return connect_input(src_port, dst_port, dst); } if (dst.get() == d_owner) { max_port = dst->output_signature()->max_streams(); - if ((max_port != -1 && (dst_port >= max_port)) || dst_port < 0) - throw std::invalid_argument("source port out of range"); + if ((max_port != -1 && (dst_port >= max_port)) || dst_port < 0) { + msg << "destination port " << dst_port << " out of range for " << dst; + throw std::invalid_argument(msg.str()); + } + return connect_output(dst_port, src_port, src); } @@ -101,7 +109,7 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, << " -> " << gr_endpoint(dst, dst_port) << std::endl; if (src.get() == dst.get()) - throw std::invalid_argument("src and destination blocks cannot be the same"); + throw std::invalid_argument("disconnect: source and destination blocks cannot be the same"); gr_hier_block2_sptr src_block(boost::dynamic_pointer_cast(src)); gr_hier_block2_sptr dst_block(boost::dynamic_pointer_cast(dst)); @@ -128,14 +136,22 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, d_fg->disconnect(src, src_port, dst, dst_port); } +// FIXME: ticket:161 will be implemented here void gr_hier_block2_detail::connect_input(int my_port, int port, gr_basic_block_sptr block) { - if (my_port < 0 || my_port >= (signed)d_inputs.size()) - throw std::invalid_argument("input port number out of range"); + std::stringstream msg; + + if (my_port < 0 || my_port >= (signed)d_inputs.size()) { + msg << "input port " << my_port << " out of range for " << block; + throw std::invalid_argument(msg.str()); + } - if (d_inputs[my_port].block()) - throw std::invalid_argument("input port in use"); + if (d_inputs[my_port].block()) { + msg << "external input port " << my_port << " already wired to " + << d_inputs[my_port]; + throw std::invalid_argument(msg.str()); + } d_inputs[my_port] = gr_endpoint(block, port); } @@ -143,11 +159,18 @@ gr_hier_block2_detail::connect_input(int my_port, int port, gr_basic_block_sptr void gr_hier_block2_detail::connect_output(int my_port, int port, gr_basic_block_sptr block) { - if (my_port < 0 || my_port >= (signed)d_outputs.size()) - throw std::invalid_argument("output port number out of range"); + std::stringstream msg; - if (d_outputs[my_port].block()) - throw std::invalid_argument("output port in use"); + if (my_port < 0 || my_port >= (signed)d_outputs.size()) { + msg << "output port " << my_port << " out of range for " << block; + throw std::invalid_argument(msg.str()); + } + + if (d_outputs[my_port].block()) { + msg << "external output port " << my_port << " already connected from " + << d_outputs[my_port]; + throw std::invalid_argument(msg.str()); + } d_outputs[my_port] = gr_endpoint(block, port); } @@ -155,11 +178,18 @@ gr_hier_block2_detail::connect_output(int my_port, int port, gr_basic_block_sptr void gr_hier_block2_detail::disconnect_input(int my_port, int port, gr_basic_block_sptr block) { - if (my_port < 0 || my_port >= (signed)d_inputs.size()) - throw std::invalid_argument("input port number out of range"); + std::stringstream msg; + + if (my_port < 0 || my_port >= (signed)d_inputs.size()) { + msg << "input port number " << my_port << " out of range for " << block; + throw std::invalid_argument(msg.str()); + } - if (d_inputs[my_port].block() != block) - throw std::invalid_argument("block not assigned to given input, can't disconnect"); + if (d_inputs[my_port].block() != block) { + msg << "block " << block << " not assigned to input " + << my_port << ", can't disconnect"; + throw std::invalid_argument(msg.str()); + } d_inputs[my_port] = gr_endpoint(); } @@ -167,11 +197,18 @@ gr_hier_block2_detail::disconnect_input(int my_port, int port, gr_basic_block_sp void gr_hier_block2_detail::disconnect_output(int my_port, int port, gr_basic_block_sptr block) { - if (my_port < 0 || my_port >= (signed)d_outputs.size()) - throw std::invalid_argument("input port number out of range"); + std::stringstream msg; - if (d_outputs[my_port].block() != block) - throw std::invalid_argument("block not assigned to given output, can't disconnect"); + if (my_port < 0 || my_port >= (signed)d_outputs.size()) { + msg << "output port number " << my_port << " out of range for " << block; + throw std::invalid_argument(msg.str()); + } + + if (d_outputs[my_port].block() != block) { + msg << "block " << block << " not assigned to output " + << my_port << ", can't disconnect"; + throw std::invalid_argument(msg.str()); + } d_outputs[my_port] = gr_endpoint(); } @@ -179,6 +216,8 @@ gr_hier_block2_detail::disconnect_output(int my_port, int port, gr_basic_block_s gr_endpoint gr_hier_block2_detail::resolve_port(int port, bool is_input) { + std::stringstream msg; + if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "Resolving port " << port << " as an " << (is_input ? "input" : "output") @@ -187,18 +226,28 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) gr_endpoint result; if (is_input) { - if (port < 0 || port >= (signed)d_inputs.size()) - throw std::runtime_error("input port number out of range"); + if (port < 0 || port >= (signed)d_inputs.size()) { + msg << "resolve_port: input " << port << " is out of range"; + throw std::runtime_error(msg.str()); + } + result = resolve_endpoint(d_inputs[port], true); } else { - if (port < 0 || port >= (signed)d_outputs.size()) - throw std::runtime_error("output port number out of range"); + if (port < 0 || port >= (signed)d_outputs.size()) { + msg << "resolve_port: output " << port << " is out of range"; + throw std::runtime_error(msg.str()); + } + result = resolve_endpoint(d_outputs[port], false); } - if (!result.block()) - throw std::runtime_error("unable to resolve port"); + if (!result.block()) { + msg << "unable to resolve " + << (is_input ? "input port " : "output port ") + << port; + throw std::runtime_error(msg.str()); + } return result; } @@ -206,6 +255,8 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) gr_endpoint gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) const { + std::stringstream msg; + // Check if endpoint is a leaf node if (boost::dynamic_pointer_cast(endp.block())) return endp; @@ -220,8 +271,9 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) return hier_block2->d_detail->resolve_port(endp.port(), is_input); } - // Shouldn't ever get here - throw std::runtime_error("block is not a valid gr_block or gr_hier_block2!"); + msg << "unable to resolve" << (is_input ? " input " : " output ") + << "endpoint " << endp; + throw std::runtime_error(msg.str()); } void diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index d310f2aea..63ceec8b2 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -29,7 +29,8 @@ typedef boost::shared_ptr gr_top_block_sptr; // Hack to have a Python shim implementation of gr.top_block // that instantiates one of these and passes through calls %rename(top_block_swig) gr_make_top_block; -gr_top_block_sptr gr_make_top_block(const std::string name); +gr_top_block_sptr gr_make_top_block(const std::string name) + throw (std::logic_error); class gr_top_block : public gr_hier_block2 { -- cgit From 2a88d301ecdc95266e8f84fe36be646f78a9895a Mon Sep 17 00:00:00 2001 From: jcorgan Date: Wed, 29 Aug 2007 19:16:10 +0000 Subject: Clean up shared pointer casting. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6208 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 4 ++++ gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 51eb687ed..7ecc0d770 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -89,4 +89,8 @@ public: gr_flat_flowgraph_sptr flatten() const; }; +inline gr_hier_block2_sptr make_hier_block2_sptr(gr_basic_block_sptr block) { + return boost::dynamic_pointer_cast(block); +} + #endif /* INCLUDED_GR_HIER_BLOCK2_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 1412a284c..76d23cab0 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -57,8 +57,8 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, if (src.get() == dst.get()) throw std::invalid_argument("connect: src and destination blocks cannot be the same"); - gr_hier_block2_sptr src_block(boost::dynamic_pointer_cast(src)); - gr_hier_block2_sptr dst_block(boost::dynamic_pointer_cast(dst)); + gr_hier_block2_sptr src_block(make_hier_block2_sptr(src)); + gr_hier_block2_sptr dst_block(make_hier_block2_sptr(dst)); if (src_block && src.get() != d_owner) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) @@ -111,8 +111,8 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, if (src.get() == dst.get()) throw std::invalid_argument("disconnect: source and destination blocks cannot be the same"); - gr_hier_block2_sptr src_block(boost::dynamic_pointer_cast(src)); - gr_hier_block2_sptr dst_block(boost::dynamic_pointer_cast(dst)); + gr_hier_block2_sptr src_block(make_hier_block2_sptr(src)); + gr_hier_block2_sptr dst_block(make_hier_block2_sptr(dst)); if (src_block && src.get() != d_owner) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) @@ -258,11 +258,11 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) std::stringstream msg; // Check if endpoint is a leaf node - if (boost::dynamic_pointer_cast(endp.block())) + if (make_gr_block_sptr(endp.block())) return endp; // Check if endpoint is a hierarchical block - gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(endp.block())); + gr_hier_block2_sptr hier_block2(make_hier_block2_sptr(endp.block())); if (hier_block2) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "Resolving endpoint " << endp << " as an " @@ -298,7 +298,7 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const // Recurse hierarchical children for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - gr_hier_block2_sptr hier_block2(boost::dynamic_pointer_cast(*p)); + gr_hier_block2_sptr hier_block2(make_hier_block2_sptr(*p)); if (hier_block2) hier_block2->d_detail->flatten_aux(sfg); } -- cgit From 6006b92a287fa5a23bcb7905f6f854d9c9dd4462 Mon Sep 17 00:00:00 2001 From: michaelld Date: Thu, 13 Sep 2007 20:36:23 +0000 Subject: Made changes, such that: * trunk now passes "make distcheck" on OSX * verified that 'realtime' scheduling now works on systems with 'pthread_setschedparam' but not 'sched_setscheduler' (e.g. darwin); the latter has priority if both are installed. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6427 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_realtime.cc | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.cc b/gnuradio-core/src/lib/runtime/gr_realtime.cc index 878411df2..35d0ef381 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_realtime.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -58,6 +58,33 @@ gr_enable_realtime_scheduling() return RT_OK; } +#elif defined(HAVE_PTHREAD_SETSCHEDPARAM) + +#include + +gr_rt_status_t +gr_enable_realtime_scheduling() +{ + int policy = SCHED_FIFO; + int pri = (sched_get_priority_max (policy) + + sched_get_priority_min (policy)) / 2; + pthread_t this_thread = pthread_self (); // this process + struct sched_param param; + memset (¶m, 0, sizeof (param)); + param.sched_priority = pri; + int result = pthread_setschedparam (this_thread, policy, ¶m); + if (result != 0) { + if (errno == EPERM) + return RT_NO_PRIVS; + else { + perror ("pthread_setschedparam: failed to set real time priority"); + return RT_OTHER_ERROR; + } + } + //printf("SCHED_FIFO enabled with priority = %d\n", pri); + return RT_OK; +} + // #elif // could try negative niceness #else -- cgit From e692e71305ecd71d3681fe37f3d76f350d67e276 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 18 Sep 2007 18:59:00 +0000 Subject: Merge r6461:6464 from jcorgan/t162-staging into trunk. * Final gr.top_block and gr.hier_block2 implementation inside gnuradio-core/src/lib/runtime * Implementation of gr.hier_block2 versions of all the old-style blocks in blks. These live in blks2. * Addition of gr.hier_block2 based versions of gr-wxgui blocks * Conversion of all the example code in gnuradio-examples to use this new code * Conversion of all the gr-utils scripts to use the new code The OFDM examples and related hierarchical blocks have not yet been converted. Code in the rest of the tree that is outside the core and example components has also not yet been converted. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6466 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 18 +++++++ gnuradio-core/src/lib/runtime/gr_hier_block2.h | 24 ++------- gnuradio-core/src/lib/runtime/gr_hier_block2.i | 34 +++++++------ .../src/lib/runtime/gr_hier_block2_detail.cc | 55 +++++++++++++++++++- .../src/lib/runtime/gr_hier_block2_detail.h | 58 +++++++++++----------- gnuradio-core/src/lib/runtime/gr_top_block.cc | 6 +++ gnuradio-core/src/lib/runtime/gr_top_block.h | 5 ++ gnuradio-core/src/lib/runtime/gr_top_block.i | 1 + gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 3 ++ 9 files changed, 140 insertions(+), 64 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index f531e76ad..23f274da7 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -51,6 +51,12 @@ gr_hier_block2::~gr_hier_block2() delete d_detail; } +void +gr_hier_block2::connect(gr_basic_block_sptr block) +{ + d_detail->connect(block); +} + void gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) @@ -58,6 +64,12 @@ gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, d_detail->connect(src, src_port, dst, dst_port); } +void +gr_hier_block2::disconnect(gr_basic_block_sptr block) +{ + d_detail->disconnect(block); +} + void gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) @@ -65,6 +77,12 @@ gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, d_detail->disconnect(src, src_port, dst, dst_port); } +void +gr_hier_block2::disconnect_all() +{ + d_detail->disconnect_all(); +} + void gr_hier_block2::lock() { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 7ecc0d770..6124e4d51 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -58,32 +58,18 @@ protected: public: virtual ~gr_hier_block2(); + void connect(gr_basic_block_sptr block); + void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); + void disconnect(gr_basic_block_sptr block); + void disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); - /*! - * Lock a flowgraph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flowgraph - * will be restarted automatically. - * - * N.B. lock() and unlock() cannot be called from a flowgraph thread - * (E.g., gr_block::work method) or deadlock will occur when - * reconfiguration happens. - */ + void disconnect_all(); virtual void lock(); - - /*! - * Lock a flowgraph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flowgraph - * will be restarted automatically. - * - * N.B. lock() and unlock() cannot be called from a flowgraph thread - * (E.g., gr_block::work method) or deadlock will occur when - * reconfiguration happens. - */ virtual void unlock(); gr_flat_flowgraph_sptr flatten() const; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index b3882a6a8..5278eefce 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -36,20 +36,24 @@ gr_hier_block2_sptr gr_make_hier_block2(const std::string name, class gr_hier_block2 : public gr_basic_block { private: - gr_hier_block2(const std::string name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - + gr_hier_block2(const std::string name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + public: - ~gr_hier_block2 (); - - // Add a named block to the container - void connect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port) - throw (std::invalid_argument); - void disconnect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port) - throw (std::invalid_argument); - void lock(); - void unlock(); + ~gr_hier_block2 (); + + void connect(gr_basic_block_sptr block) + throw (std::invalid_argument); + void connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) + throw (std::invalid_argument); + void disconnect(gr_basic_block_sptr block) + throw (std::invalid_argument); + void disconnect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port) + throw (std::invalid_argument); + void disconnect_all(); + void lock(); + void unlock(); }; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 76d23cab0..26a28fabd 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -44,6 +44,27 @@ gr_hier_block2_detail::~gr_hier_block2_detail() d_owner = 0; // Don't use delete, we didn't allocate } +void +gr_hier_block2_detail::connect(gr_basic_block_sptr block) +{ + std::stringstream msg; + + // Check if duplicate + if (std::find(d_blocks.begin(), d_blocks.end(), block) != d_blocks.end()) { + msg << "Block " << block << " already connected."; + throw std::invalid_argument(msg.str()); + } + + // Check if has inputs or outputs + if (block->input_signature()->max_streams() != 0 || + block->output_signature()->max_streams() != 0) { + msg << "Block " << block << " must not have any input or output ports"; + throw std::invalid_argument(msg.str()); + } + + d_blocks.push_back(block); +} + void gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) @@ -100,6 +121,21 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, // TODO: connects to NC } +void +gr_hier_block2_detail::disconnect(gr_basic_block_sptr block) +{ + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + if (*p == block) { + d_blocks.erase(p); + return; + } + } + + std::stringstream msg; + msg << "cannot disconnect block " << block << ", not found"; + throw std::invalid_argument(msg.str()); +} + void gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) @@ -252,6 +288,15 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) return result; } +void +gr_hier_block2_detail::disconnect_all() +{ + d_fg->clear(); + d_blocks.clear(); + d_inputs.clear(); + d_outputs.clear(); +} + gr_endpoint gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) const { @@ -294,7 +339,15 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const sfg->connect(src_endp, dst_endp); } - gr_basic_block_vector_t blocks = d_fg->calc_used_blocks(); + // Construct unique list of blocks used either in edges or + // by themselves. I hate STL. + gr_basic_block_vector_t blocks, tmp = d_fg->calc_used_blocks(); + std::insert_iterator inserter(blocks, blocks.begin()); + std::vector::const_iterator p; // Because flatten_aux is const + for (p = d_blocks.begin(); p != d_blocks.end(); p++) + tmp.push_back(*p); + sort(tmp.begin(), tmp.end()); + unique_copy(tmp.begin(), tmp.end(), inserter); // Recurse hierarchical children for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index b692d1080..d31ae93e7 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -27,37 +27,37 @@ class gr_hier_block2_detail : boost::noncopyable { -private: - friend class gr_hier_block2; - friend class gr_runtime_impl; - - // Constructor--it's private, only friends can instantiate - gr_hier_block2_detail(gr_hier_block2 *owner); - - // Private implementation data - gr_hier_block2 *d_owner; - gr_hier_block2_detail *d_parent_detail; - gr_flowgraph_sptr d_fg; - gr_endpoint_vector_t d_inputs; - gr_endpoint_vector_t d_outputs; +public: + gr_hier_block2_detail(gr_hier_block2 *owner); + ~gr_hier_block2_detail(); - // Private implementation methods - void connect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port); - void disconnect(gr_basic_block_sptr, int src_port, - gr_basic_block_sptr, int dst_port); - void connect_input(int my_port, int port, gr_basic_block_sptr block); - void connect_output(int my_port, int port, gr_basic_block_sptr block); - void disconnect_input(int my_port, int port, gr_basic_block_sptr block); - void disconnect_output(int my_port, int port, gr_basic_block_sptr block); - void flatten_aux(gr_flat_flowgraph_sptr sfg) const; - gr_endpoint resolve_port(int port, bool is_input); - gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input) const; - void lock(); - void unlock(); + void connect(gr_basic_block_sptr block); + void connect(gr_basic_block_sptr src, int src_port, + gr_basic_block_sptr dst, int dst_port); + void disconnect(gr_basic_block_sptr block); + void disconnect(gr_basic_block_sptr, int src_port, + gr_basic_block_sptr, int dst_port); + void disconnect_all(); + void lock(); + void unlock(); + void flatten_aux(gr_flat_flowgraph_sptr sfg) const; -public: - ~gr_hier_block2_detail(); +private: + + // Private implementation data + gr_hier_block2 *d_owner; + gr_hier_block2_detail *d_parent_detail; + gr_flowgraph_sptr d_fg; + gr_endpoint_vector_t d_inputs; + gr_endpoint_vector_t d_outputs; + gr_basic_block_vector_t d_blocks; + + void connect_input(int my_port, int port, gr_basic_block_sptr block); + void connect_output(int my_port, int port, gr_basic_block_sptr block); + void disconnect_input(int my_port, int port, gr_basic_block_sptr block); + void disconnect_output(int my_port, int port, gr_basic_block_sptr block); + gr_endpoint resolve_port(int port, bool is_input); + gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input) const; }; #endif /* INCLUDED_GR_HIER_BLOCK2_DETAIL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 91248d347..10e377205 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -88,3 +88,9 @@ gr_top_block::unlock() { d_impl->unlock(); } + +bool +gr_top_block::is_running() +{ + return d_impl->is_running(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index d74903841..57c36ad3b 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -97,6 +97,11 @@ public: * reconfiguration happens. */ virtual void unlock(); + + /*! + * Returns true if flowgraph is running + */ + bool is_running(); }; #endif /* INCLUDED_GR_TOP_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 63ceec8b2..78c2e0b95 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -46,6 +46,7 @@ public: void run(); void lock(); void unlock(); + bool is_running(); }; %{ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 8052ce4fa..00cb7f979 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -53,6 +53,9 @@ public: // Unlock the top block at end of reconfiguration void unlock(); + // Return true if flowgraph is running + bool is_running() const { return d_running; } + private: bool d_running; -- cgit From 0b0f2e10fa76e6adebf669f8a7ef1c7d15d8c5d2 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 2 Oct 2007 19:30:33 +0000 Subject: renamed test macro for consistency git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6574 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_complex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_complex.h b/gnuradio-core/src/lib/runtime/gr_complex.h index f705d95dc..32e996eef 100644 --- a/gnuradio-core/src/lib/runtime/gr_complex.h +++ b/gnuradio-core/src/lib/runtime/gr_complex.h @@ -38,7 +38,7 @@ inline bool is_complex (short x) { return false;} // this doesn't really belong here, but there are worse places for it... -#define ASSERT_COMPLEXES_EQUAL(expected,actual,delta) \ +#define CPPUNIT_ASSERT_COMPLEXES_EQUAL(expected,actual,delta) \ CPPUNIT_ASSERT_DOUBLES_EQUAL (expected.real(), actual.real(), delta); \ CPPUNIT_ASSERT_DOUBLES_EQUAL (expected.imag(), actual.imag(), delta); -- cgit From a5e16a6c596984438c53fbf17d0f812616320aa3 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 16 Oct 2007 17:56:14 +0000 Subject: Add missing include for ::write git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6634 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_top_block.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 10e377205..b2523afc9 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -24,6 +24,7 @@ #include "config.h" #endif +#include #include #include #include -- cgit From 6b1dcc7d74acf86d755de4668ad7b136ed3748be Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 2 Nov 2007 03:02:56 +0000 Subject: Merged r6780:6781 from jcorgan/t196. Fixes ticket:196. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6782 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_top_block.i | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 78c2e0b95..4eb9db636 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -49,25 +49,18 @@ public: bool is_running(); }; -%{ -class ensure_py_gil_state2 { - PyGILState_STATE d_gstate; -public: - ensure_py_gil_state2() { d_gstate = PyGILState_Ensure(); } - ~ensure_py_gil_state2() { PyGILState_Release(d_gstate); } -}; -%} - %inline %{ void top_block_run_unlocked(gr_top_block_sptr r) throw (std::runtime_error) { - ensure_py_gil_state2 _lock; + Py_BEGIN_ALLOW_THREADS; // release global interpreter lock r->run(); + Py_END_ALLOW_THREADS; // acquire global interpreter lock } void top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error) { - ensure_py_gil_state2 _lock; + Py_BEGIN_ALLOW_THREADS; // release global interpreter lock r->wait(); + Py_END_ALLOW_THREADS; // acquire global interpreter lock } %} -- cgit From e01b98864f8dadc486e8f0c57ad69205944391a2 Mon Sep 17 00:00:00 2001 From: eb Date: Thu, 29 Nov 2007 01:07:00 +0000 Subject: fixes ticket:211 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7053 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 340e81afd..ffdcbdb7a 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -92,7 +92,7 @@ void gr_top_block_impl::start() { if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "start: entered" << std::endl; + std::cout << "start: entered " << this << std::endl; if (d_running) throw std::runtime_error("already running"); @@ -143,7 +143,6 @@ gr_top_block_impl::stop() if (*p) (*p)->stop(); } - d_running = false; } void @@ -165,6 +164,7 @@ gr_top_block_impl::wait() } d_threads.clear(); + d_running = false; } // N.B. lock() and unlock() cannot be called from a flow graph thread or -- cgit From cda71d951ef0cb2126719fed029d459b23a02fe9 Mon Sep 17 00:00:00 2001 From: eb Date: Thu, 24 Jan 2008 16:29:09 +0000 Subject: Doc fixes from Firas. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7504 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_dispatcher.h | 1 + gnuradio-core/src/lib/runtime/gr_error_handler.h | 1 + gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 1 + gnuradio-core/src/lib/runtime/gr_flowgraph.h | 1 + gnuradio-core/src/lib/runtime/gr_hier_block2.h | 2 ++ gnuradio-core/src/lib/runtime/gr_io_signature.h | 1 + gnuradio-core/src/lib/runtime/gr_local_sighandler.h | 1 + gnuradio-core/src/lib/runtime/gr_message.h | 3 ++- gnuradio-core/src/lib/runtime/gr_msg_handler.h | 1 + gnuradio-core/src/lib/runtime/gr_msg_queue.h | 1 + gnuradio-core/src/lib/runtime/gr_realtime.h | 1 + gnuradio-core/src/lib/runtime/gr_scheduler_thread.h | 1 + gnuradio-core/src/lib/runtime/gr_select_handler.h | 1 + gnuradio-core/src/lib/runtime/gr_sync_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 2 +- gnuradio-core/src/lib/runtime/gr_sync_interpolator.h | 2 +- gnuradio-core/src/lib/runtime/gr_timer.h | 1 + gnuradio-core/src/lib/runtime/gr_top_block.h | 1 + gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 1 + gnuradio-core/src/lib/runtime/gr_vmcircbuf.h | 1 + gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h | 1 + gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h | 1 + gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h | 1 + gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h | 1 + 26 files changed, 28 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index b2b8b42a3..8dc965da7 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -29,7 +29,7 @@ /*! * \brief The abstract base class for all signal processing blocks. - * \ingroup block + * \ingroup base * * Basic blocks are the bare abstraction of an entity that has a name * and a set of inputs and outputs. These are never instantiated diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index ce58ca9ac..79237ee83 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -27,7 +27,7 @@ /*! * \brief The abstract base class for all 'terminal' processing blocks. - * \ingroup block + * \ingroup base * * A signal processing flow is constructed by creating a tree of * hierarchical blocks, which at any level may also contain terminal nodes diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.h b/gnuradio-core/src/lib/runtime/gr_dispatcher.h index acfc428a2..34f825102 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.h +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.h @@ -34,6 +34,7 @@ gr_dispatcher_sptr gr_make_dispatcher(); /*! * \brief invoke callbacks based on select. + * \ingroup internal * * \sa gr_select_handler */ diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.h b/gnuradio-core/src/lib/runtime/gr_error_handler.h index eb69fccb5..530a2c23c 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.h @@ -48,6 +48,7 @@ /*! * \brief abstract error handler + * \ingroup base */ class gr_error_handler { public: diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h index 0f4928064..10c5d6416 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h @@ -36,6 +36,7 @@ gr_flat_flowgraph_sptr gr_make_flat_flowgraph(); /*! *\brief Class specializing gr_flat_flowgraph that has all nodes * as gr_blocks, with no hierarchy + * \ingroup base * */ class gr_flat_flowgraph : public gr_flowgraph diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flowgraph.h index 131e41bb9..c97a50782 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.h @@ -28,6 +28,7 @@ /*! *\brief Class representing a specific input or output graph endpoint + * \ingroup internal * */ class gr_endpoint diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 6124e4d51..d04acb970 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -26,6 +26,7 @@ /*! * \brief public constructor for gr_hier_block2 + */ gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, @@ -35,6 +36,7 @@ class gr_hier_block2_detail; /*! * \brief gr_hier_block2 - Hierarchical container class for gr_block's + * \ingroup internal * */ class gr_hier_block2 : public gr_basic_block diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index aa839ad0c..bf71dea57 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -28,6 +28,7 @@ /*! * \brief Create an i/o signature * + * \ingroup internal * \param min_streams specify minimum number of streams (>= 0) * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) * \param sizeof_stream_item specify the size of the items in each stream diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h index c753f0ff5..6b60cf09a 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h @@ -32,6 +32,7 @@ /*! * \brief Get and set signal handler. * + * \ingroup internal * Constructor installs new handler, destructor reinstalls * original value. */ diff --git a/gnuradio-core/src/lib/runtime/gr_message.h b/gnuradio-core/src/lib/runtime/gr_message.h index e3c52a581..179f7d9bc 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.h +++ b/gnuradio-core/src/lib/runtime/gr_message.h @@ -38,8 +38,9 @@ gr_message_sptr gr_make_message_from_string(const std::string s, long type = 0, double arg1 = 0, double arg2 = 0); /*! - * \brief Message. + * \brief Message class. * + * \ingroup misc * The ideas and method names for adjustable message length were * lifted from the click modular router "Packet" class. */ diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.h b/gnuradio-core/src/lib/runtime/gr_msg_handler.h index 443611841..774dce73e 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.h @@ -29,6 +29,7 @@ typedef boost::shared_ptr gr_msg_handler_sptr; /*! * \brief abstract class of message handlers + * \ingroup base */ class gr_msg_handler { public: diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.h b/gnuradio-core/src/lib/runtime/gr_msg_queue.h index fc4c2407f..38556b3ca 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.h @@ -32,6 +32,7 @@ gr_msg_queue_sptr gr_make_msg_queue(unsigned int limit=0); /*! * \brief thread-safe message queue + * \ingroup misc */ class gr_msg_queue : public gr_msg_handler { omni_mutex d_mutex; diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.h b/gnuradio-core/src/lib/runtime/gr_realtime.h index 49a52a0d5..cf0423aaa 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.h +++ b/gnuradio-core/src/lib/runtime/gr_realtime.h @@ -32,6 +32,7 @@ typedef enum { /*! * \brief If possible, enable high-priority "real time" scheduling. + * \ingroup misc */ gr_rt_status_t gr_enable_realtime_scheduling(); diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h index c989f797c..89daba403 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h @@ -35,6 +35,7 @@ typedef gr_scheduler_thread_vector_t::iterator gr_scheduler_thread_viter_t; /*! *\brief A single thread of execution for the scheduler * + * \ingroup internal * This class implements a single thread that runs undetached, and * invokes the single-threaded block scheduler. The runtime makes * one of these for each distinct partition of a flowgraph and runs diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.h b/gnuradio-core/src/lib/runtime/gr_select_handler.h index cc883dc90..c3808995b 100644 --- a/gnuradio-core/src/lib/runtime/gr_select_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.h @@ -31,6 +31,7 @@ typedef boost::shared_ptr gr_select_handler_sptr; /*! * \brief Abstract handler for select based notification. + * \ingroup base * * \sa gr_dispatcher */ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index dcc7e2e73..c7f7d4df3 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -27,7 +27,7 @@ /*! * \brief synchronous 1:1 input to output with history - * \ingroup block + * \ingroup internal * * Override work to provide the signal processing implementation. */ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h index 4666ece8e..1482ecc00 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -27,7 +27,7 @@ /*! * \brief synchronous N:1 input to output with history - * \ingroup block + * \ingroup internal * * Override work to provide the signal processing implementation. */ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index 46851de2d..b5dfed70c 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -27,7 +27,7 @@ /*! * \brief synchronous 1:N input to output with history - * \ingroup block + * \ingroup internal * * Override work to provide the signal processing implementation. */ diff --git a/gnuradio-core/src/lib/runtime/gr_timer.h b/gnuradio-core/src/lib/runtime/gr_timer.h index 2e1106037..ff14e315d 100644 --- a/gnuradio-core/src/lib/runtime/gr_timer.h +++ b/gnuradio-core/src/lib/runtime/gr_timer.h @@ -33,6 +33,7 @@ typedef void (*gr_timer_hook)(gr_timer *, void *); /*! * \brief create a timeout. * + * \ingroup misc * gr_timer_hook is called when timer fires. */ gr_timer_sptr gr_make_timer (gr_timer_hook, void *); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 57c36ad3b..28814a9a0 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -31,6 +31,7 @@ gr_top_block_sptr gr_make_top_block(const std::string &name); /*! *\brief Top-level hierarchical block representing a flowgraph + * \ingroup internal * */ class gr_top_block : public gr_hier_block2 diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 00cb7f979..1868cffd6 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -28,6 +28,7 @@ /*! *\brief Implementation details of gr_top_block * + * \ingroup internal * The actual implementation of gr_top_block. Separate class allows * decoupling of changes from dependent classes. * diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h index c224b7852..0d4f45832 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h @@ -27,6 +27,7 @@ /*! * \brief abstract class to implement doubly mapped virtual memory circular buffers + * \ingroup base */ class gr_vmcircbuf { protected: diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h index c866e80e8..2bb7bb16f 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h @@ -30,6 +30,7 @@ #endif /*! * \brief concrete class to implement circular buffers with mmap and shm_open + * \ingroup base */ class gr_vmcircbuf_createfilemapping : public gr_vmcircbuf { diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h index 1444a68d7..7e628fa59 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h @@ -27,6 +27,7 @@ /*! * \brief concrete class to implement circular buffers with mmap and shm_open + * \ingroup base */ class gr_vmcircbuf_mmap_shm_open : public gr_vmcircbuf { public: diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h index 5c84dd69a..da91d2f02 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h @@ -27,6 +27,7 @@ /*! * \brief concrete class to implement circular buffers with mmap and shm_open + * \ingroup base */ class gr_vmcircbuf_mmap_tmpfile : public gr_vmcircbuf { public: diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h index d5f739ae4..ffc74918e 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h @@ -27,6 +27,7 @@ /*! * \brief concrete class to implement circular buffers with mmap and shm_open + * \ingroup base */ class gr_vmcircbuf_sysv_shm : public gr_vmcircbuf { public: -- cgit From 00e5a82e769411988244fe6e3eb3fdbb30562169 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 5 Feb 2008 16:54:24 +0000 Subject: Fixes abort issue in gr.top_block exception handling, improve some exception messages. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7565 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_top_block.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 4eb9db636..f48dea74e 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -40,12 +40,12 @@ private: public: ~gr_top_block(); - void start(); + void start() throw (std::runtime_error); void stop(); void wait(); void run(); void lock(); - void unlock(); + void unlock() throw (std::runtime_error); bool is_running(); }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index ffdcbdb7a..7a993a759 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -77,7 +77,7 @@ gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) d_lock_count(0) { if (s_impl) - throw std::logic_error("gr_top_block_impl: multiple simultaneous gr_top_block's"); + throw std::logic_error("gr_top_block_impl: multiple simultaneous gr_top_blocks not allowed"); s_impl = this; } @@ -95,7 +95,7 @@ gr_top_block_impl::start() std::cout << "start: entered " << this << std::endl; if (d_running) - throw std::runtime_error("already running"); + throw std::runtime_error("top block already running or wait() not called after previous stop()"); // Create new flat flow graph by flattening hierarchy d_ffg = d_owner->flatten(); @@ -203,7 +203,7 @@ gr_top_block_impl::restart() std::cout << "restart: entered" << std::endl; if (!d_running) - throw std::runtime_error("not running"); + throw std::runtime_error("top block is not running"); // Stop scheduler threads and wait for completion stop(); -- cgit From 42d9c6f495503d3d9d2db47a9979036c9233f976 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 8 Feb 2008 23:32:10 +0000 Subject: Merged r7478:7608 from michaelld/t186 into trunk. Adds ability to compile GNU Radio modules individually, using already installed dependent libraries and include files. New functionality is enabled using --with-* on configure command line; existing build options should remain unchanged. Nice work by Michael Dickens, still needs documentation update on wiki. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7617 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 4b51f7f4d..f6b744e48 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2003,2004,2007 Free Software Foundation, Inc. +# Copyright 2003,2004,2007,2008 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -21,7 +21,7 @@ include $(top_srcdir)/Makefile.common -INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) +INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) noinst_LTLIBRARIES = libruntime.la libruntime-qa.la -- cgit From d3efda7e842a62943f4292760fe48d424a5b1c53 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 16 Feb 2008 18:10:29 +0000 Subject: Improve hierarchical block documentation. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7718 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 55 ++++++++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_top_block.h | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index d04acb970..5e67a9010 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -60,20 +60,75 @@ protected: public: virtual ~gr_hier_block2(); + /*! + * \brief Add a stand-alone (possibly hierarchical) block to internal graph + * + * This adds a gr-block or hierarchical block to the internal graph + * without wiring it to anything else. + */ void connect(gr_basic_block_sptr block); + /*! + * \brief Add gr-blocks or hierarchical blocks to internal graph and wire together + * + * This adds (if not done earlier by another connect) a pair of gr-blocks or + * hierarchical blocks to the internal flowgraph, and wires the specified output + * port to the specified input port. + */ void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); + /*! + * \brief Remove a gr-block or hierarchical block from the internal flowgraph. + * + * This removes a gr-block or hierarchical block from the internal flowgraph, + * disconnecting it from other blocks as needed. + * + */ void disconnect(gr_basic_block_sptr block); + /*! + * \brief Disconnect a pair of gr-blocks or hierarchical blocks in internal + * flowgraph. + * + * This disconnects the specified input port from the specified output port + * of a pair of gr-blocks or hierarchical blocks. + */ void disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); + /*! + * \brief Disconnect all connections in the internal flowgraph. + * + * This call removes all output port to input port connections in the internal + * flowgraph. + */ void disconnect_all(); + + /*! + * Lock a flowgraph in preparation for reconfiguration. When an equal + * number of calls to lock() and unlock() have occurred, the flowgraph + * will be restarted automatically. + * + * N.B. lock() and unlock() cannot be called from a flowgraph thread + * (E.g., gr_block::work method) or deadlock will occur when + * reconfiguration happens. + */ virtual void lock(); + + /*! + * Unlock a flowgraph in preparation for reconfiguration. When an equal + * number of calls to lock() and unlock() have occurred, the flowgraph + * will be restarted automatically. + * + * N.B. lock() and unlock() cannot be called from a flowgraph thread + * (E.g., gr_block::work method) or deadlock will occur when + * reconfiguration happens. + */ virtual void unlock(); + // This is a public method for ease of code organization, but should be + // ignored by the user. gr_flat_flowgraph_sptr flatten() const; }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 28814a9a0..0209546fe 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -89,7 +89,7 @@ public: virtual void lock(); /*! - * Lock a flowgraph in preparation for reconfiguration. When an equal + * Unlock a flowgraph in preparation for reconfiguration. When an equal * number of calls to lock() and unlock() have occurred, the flowgraph * will be restarted automatically. * -- cgit From 776da31eb84e146a8adf1e3ca7e017c1d9992ce3 Mon Sep 17 00:00:00 2001 From: michaelld Date: Thu, 21 Feb 2008 19:16:45 +0000 Subject: Merged build_config branch into trunk: 1) Modified top-level run_tests.sh script: a) to execute code for setting or changing the library search path in Darwin (DYLD_LIBRARY_PATH) or Windows (PATH) on those host OSs only, not on other host OSs. b) Added local (to the component making check) library paths to those same search paths, since libtool doesn't do it (unlike in Linux). 2) In all AM Makefiles -except those dealing with USRP firmware-, changes INCLUDES to AM_CPPFLAGS since the former is deprecated. 3) Changed AM_CPPFLAGS to FW_INCLUDES for commands .c.rel in USRP firmware. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7769 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index f6b744e48..d84128cbd 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -21,7 +21,7 @@ include $(top_srcdir)/Makefile.common -INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) +AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) noinst_LTLIBRARIES = libruntime.la libruntime-qa.la -- cgit From b0245c71f07edd7921f0b70d9050781b5cb0c4b2 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sun, 24 Feb 2008 01:54:50 +0000 Subject: Fix topology checking code in gr_flowgraph. Thanks to Dan Halperin. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7802 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_flowgraph.cc | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc index f4879f085..359570347 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc @@ -124,7 +124,7 @@ gr_flowgraph::check_valid_port(gr_io_signature_sptr sig, int port) } int max = sig->max_streams(); - if (max >= 0 && port >= max) { + if (max != gr_io_signature::IO_INFINITE && port >= max) { msg << "port number " << port << " exceeds max of "; if (max == 0) msg << "(none)"; @@ -230,16 +230,23 @@ gr_flowgraph::check_contiguity(gr_basic_block_sptr block, int nports = used_ports.size(); int min_ports = sig->min_streams(); + int max_ports = sig->max_streams(); - if (nports == 0) { - if (min_ports == 0) - return; - else { - msg << block << ": insufficient connected " - << (check_inputs ? "input ports " : "output ports ") - << "(" << min_ports+1 << " needed, " << nports+1 << " connected)"; - throw std::runtime_error(msg.str()); - } + if (nports == 0 && min_ports == 0) + return; + + if (nports < min_ports) { + msg << block << ": insufficient connected " + << (check_inputs ? "input ports " : "output ports ") + << "(" << min_ports << " needed, " << nports << " connected)"; + throw std::runtime_error(msg.str()); + } + + if (nports > max_ports && max_ports != gr_io_signature::IO_INFINITE) { + msg << block << ": too many connected " + << (check_inputs ? "input ports " : "output ports ") + << "(" << max_ports << " allowed, " << nports << " connected)"; + throw std::runtime_error(msg.str()); } if (used_ports[nports-1]+1 != nports) { -- cgit From 2206859b4d8de54249aa3d5cbabd2e157a1f08a3 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Wed, 19 Mar 2008 16:46:40 +0000 Subject: Fixes ticket:193 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8050 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 7a993a759..aa9368e4c 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -33,6 +33,7 @@ #include #include #include +#include #define GR_TOP_BLOCK_IMPL_DEBUG 0 -- cgit From b92c457af141ed992671d14bf0a1b269b4946f8d Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 24 Apr 2008 20:32:58 +0000 Subject: Merged changeset r8231:8270 from jcorgan/merge-fix into trunk. Fixes flowgraph reconfiguration bug reported by Tim O'Shea and Mark Schneider. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8271 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 116 +++++++++++++++------ gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 5 +- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 12 ++- 3 files changed, 95 insertions(+), 38 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 0a73d716d..aa1aa8353 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -62,7 +62,7 @@ gr_flat_flowgraph::setup_connections() } gr_block_detail_sptr -gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block, gr_block_detail_sptr old_detail) +gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block) { int ninputs = calc_used_ports(block, true).size(); int noutputs = calc_used_ports(block, false).size(); @@ -71,21 +71,10 @@ gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block, gr_block_det if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Creating block detail for " << block << std::endl; - // Re-use or allocate output buffers for (int i = 0; i < noutputs; i++) { - gr_buffer_sptr buffer; - - if (!old_detail || i >= old_detail->noutputs()) { - if (GR_FLAT_FLOWGRAPH_DEBUG) - std::cout << "Allocating new buffer for output " << i << std::endl; - buffer = allocate_buffer(block, i); - } - else { - if (GR_FLAT_FLOWGRAPH_DEBUG) - std::cout << "Reusing old buffer for output " << i << std::endl; - buffer = old_detail->output(i); - } - + gr_buffer_sptr buffer = allocate_buffer(block, i); + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "Allocated buffer for output " << block << ":" << i << std::endl; detail->set_output(i, buffer); } @@ -156,35 +145,66 @@ gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) void gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) { - std::map old_details; - - // Allocate or reuse output buffers + // Allocate block details if needed. Only new blocks that aren't pruned out + // by flattening will need one; existing blocks still in the new flowgraph will + // already have one. for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { gr_block_sptr block = make_gr_block_sptr(*p); - - gr_block_detail_sptr old_detail = block->detail(); - block->set_detail(allocate_block_detail(block, old_detail)); - - // Save old detail for use in next step - old_details[block] = old_detail; + + if (!block->detail()) { + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "merge: allocating new detail for block " << (*p) << std::endl; + block->set_detail(allocate_block_detail(block)); + } + else + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "merge: reusing original detail for block " << (*p) << std::endl; } + // Calculate the old edges that will be going away, and clear the buffer readers + // on the RHS. + for (gr_edge_viter_t old_edge = old_ffg->d_edges.begin(); old_edge != old_ffg->d_edges.end(); old_edge++) { + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "merge: testing old edge " << (*old_edge) << "..."; + + gr_edge_viter_t new_edge; + for (new_edge = d_edges.begin(); new_edge != d_edges.end(); new_edge++) + if (new_edge->src() == old_edge->src() && + new_edge->dst() == old_edge->dst()) + break; + + if (new_edge == d_edges.end()) { // not found in new edge list + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "not in new edge list" << std::endl; + // zero the buffer reader on RHS of old edge + gr_block_sptr block(make_gr_block_sptr(old_edge->dst().block())); + int port = old_edge->dst().port(); + block->detail()->set_input(port, gr_buffer_reader_sptr()); + } + else { + if (GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << "found in new edge list" << std::endl; + } + } + + // Now connect inputs to outputs, reusing old buffer readers if they exist for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { gr_block_sptr block = make_gr_block_sptr(*p); if (GR_FLAT_FLOWGRAPH_DEBUG) - std::cout << "merge: testing " << (*p) << "..."; + std::cout << "merge: merging " << (*p) << "..."; if (old_ffg->has_block_p(*p)) { // Block exists in old flow graph if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "used in old flow graph" << std::endl; gr_block_detail_sptr detail = block->detail(); - + // Iterate through the inputs and see what needs to be done - for (int i = 0; i < detail->ninputs(); i++) { + int ninputs = calc_used_ports(block, true).size(); // Might be different now + for (int i = 0; i < ninputs; i++) { if (GR_FLAT_FLOWGRAPH_DEBUG) - std::cout << "Checking input " << i << "..."; + std::cout << "Checking input " << block << ":" << i << "..."; gr_edge edge = calc_upstream_edge(*p, i); // Fish out old buffer reader and see if it matches correct buffer from edge list @@ -192,16 +212,13 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) gr_block_detail_sptr src_detail = src_block->detail(); gr_buffer_sptr src_buffer = src_detail->output(edge.src().port()); gr_buffer_reader_sptr old_reader; - gr_block_detail_sptr old_detail = old_details[block]; - if (old_detail && i < old_detail->ninputs()) - old_reader = old_detail->input(i); + if (i < detail->ninputs()) // Don't exceed what the original detail has + old_reader = detail->input(i); // If there's a match, use it if (old_reader && (src_buffer == old_reader->buffer())) { if (GR_FLAT_FLOWGRAPH_DEBUG) - std::cout << "matched" << std::endl; - detail->set_input(i, old_reader); - + std::cout << "matched, reusing" << std::endl; } else { if (GR_FLAT_FLOWGRAPH_DEBUG) @@ -218,6 +235,37 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) std::cout << "new block" << std::endl; connect_block_inputs(block); } + + // Now deal with the fact that the block details might have changed numbers of + // inputs and outputs vs. in the old flowgraph. } } +void gr_flat_flowgraph::dump() +{ + for (gr_edge_viter_t e = d_edges.begin(); e != d_edges.end(); e++) + std::cout << " edge: " << (*e) << std::endl; + + for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { + std::cout << " block: " << (*p) << std::endl; + gr_block_detail_sptr detail = make_gr_block_sptr(*p)->detail(); + std::cout << " detail @" << detail << ":" << std::endl; + + int ni = detail->ninputs(); + int no = detail->noutputs(); + for (int i = 0; i < no; i++) { + gr_buffer_sptr buffer = detail->output(i); + std::cout << " output " << i << ": " << buffer + << " space=" << buffer->space_available() << std::endl; + } + + for (int i = 0; i < ni; i++) { + gr_buffer_reader_sptr reader = detail->input(i); + std::cout << " reader " << i << ": " << reader + << " reading from buffer=" << reader->buffer() + << " avail=" << reader->items_available() << " items" + << std::endl; + } + } + +} diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h index 10c5d6416..184ee4514 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h @@ -53,12 +53,13 @@ public: // Merge applicable connections from existing flat flowgraph void merge_connections(gr_flat_flowgraph_sptr sfg); + void dump(); + private: gr_flat_flowgraph(); static const unsigned int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE; - gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block, - gr_block_detail_sptr old_detail=gr_block_detail_sptr()); + gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block); gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port); void connect_block_inputs(gr_basic_block_sptr block); }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index aa9368e4c..51755a65d 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -215,10 +215,18 @@ gr_top_block_impl::restart() // Create new simple flow graph gr_flat_flowgraph_sptr new_ffg = d_owner->flatten(); new_ffg->validate(); // check consistency, sanity, etc + + if (GR_TOP_BLOCK_IMPL_DEBUG) { + std::cout << std::endl << "*** Existing flat flowgraph @" << d_ffg << ":" << std::endl; + d_ffg->dump(); + } new_ffg->merge_connections(d_ffg); // reuse buffers, etc - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "restart: replacing old flow graph with new" << std::endl; + if (GR_TOP_BLOCK_IMPL_DEBUG) { + std::cout << std::endl << "*** New flat flowgraph after merge @" << new_ffg << ":" << std::endl; + new_ffg->dump(); + } + d_ffg = new_ffg; start_threads(); -- cgit From 38ea3a576a20820e574c6cb37607aeafe07f34b4 Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 30 Apr 2008 02:24:06 +0000 Subject: Tweaks for gcc 4.3 based on patch from Marek Mahut . git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8292 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_dispatcher.cc | 1 + gnuradio-core/src/lib/runtime/gr_error_handler.cc | 1 + gnuradio-core/src/lib/runtime/gr_local_sighandler.cc | 1 + gnuradio-core/src/lib/runtime/gr_message.cc | 1 + gnuradio-core/src/lib/runtime/gr_preferences.cc | 1 + gnuradio-core/src/lib/runtime/gr_realtime.cc | 1 + gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc | 1 + gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc | 1 + gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc | 1 - 9 files changed, 8 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.cc b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc index 1b0a1d7a3..e165361fc 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.cc +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef HAVE_SELECT # ifdef HAVE_SYS_SELECT_H diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.cc b/gnuradio-core/src/lib/runtime/gr_error_handler.cc index 4b4cdacef..6dbb0a5d2 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.cc @@ -48,6 +48,7 @@ #include #include #include +#include #ifdef HAVE_IO_H #include diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc index c6448f872..adad55791 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc @@ -27,6 +27,7 @@ #include #include #include +#include gr_local_sighandler::gr_local_sighandler (int signum, diff --git a/gnuradio-core/src/lib/runtime/gr_message.cc b/gnuradio-core/src/lib/runtime/gr_message.cc index f14ed9d9c..6bef71ed5 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.cc +++ b/gnuradio-core/src/lib/runtime/gr_message.cc @@ -25,6 +25,7 @@ #endif #include #include +#include static long s_ncurrently_allocated = 0; diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index 16c9bcafe..e0be2db62 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef MKDIR_TAKES_ONE_ARG diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.cc b/gnuradio-core/src/lib/runtime/gr_realtime.cc index 35d0ef381..d3cda0eaa 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_realtime.cc @@ -61,6 +61,7 @@ gr_enable_realtime_scheduling() #elif defined(HAVE_PTHREAD_SETSCHEDPARAM) #include +#include gr_rt_status_t gr_enable_realtime_scheduling() diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc index bc8f9b97e..07bd60500 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc @@ -26,6 +26,7 @@ #include #include +#include #ifdef HAVE_SIGNAL_H #include diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc index a70229610..abcf5b2a6 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include // all the factories we know about diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc index 173b3f732..faae4b396 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc @@ -41,7 +41,6 @@ #include #include - gr_vmcircbuf_mmap_tmpfile::gr_vmcircbuf_mmap_tmpfile (int size) : gr_vmcircbuf (size) { -- cgit From c7fc4e073aca82bc4cae529459448e0bc98b650e Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 20 May 2008 18:56:10 +0000 Subject: Expose flowgraph debugging dump as gr.top_block.dump(). May or may not be suitable for ticket:245 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8466 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_top_block.cc | 6 ++++++ gnuradio-core/src/lib/runtime/gr_top_block.h | 5 +++++ gnuradio-core/src/lib/runtime/gr_top_block.i | 1 + gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 7 +++++++ gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 3 +++ 5 files changed, 22 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index b2523afc9..5cb0ccdea 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -90,6 +90,12 @@ gr_top_block::unlock() d_impl->unlock(); } +void +gr_top_block::dump() +{ + d_impl->dump(); +} + bool gr_top_block::is_running() { diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 0209546fe..637a38468 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -99,6 +99,11 @@ public: */ virtual void unlock(); + /*! + * Displays flattened flowgraph edges and block connectivity + */ + void dump(); + /*! * Returns true if flowgraph is running */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index f48dea74e..d2e8e3b41 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -47,6 +47,7 @@ public: void lock(); void unlock() throw (std::runtime_error); bool is_running(); + void dump(); }; %inline %{ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 51755a65d..359665a77 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -231,3 +231,10 @@ gr_top_block_impl::restart() start_threads(); } + +void +gr_top_block_impl::dump() +{ + if (d_ffg) + d_ffg->dump(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 1868cffd6..abdfa9964 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -54,6 +54,9 @@ public: // Unlock the top block at end of reconfiguration void unlock(); + // Dump the flowgraph to stdout + void dump(); + // Return true if flowgraph is running bool is_running() const { return d_running; } -- cgit From bb5a5a24766e50059ff0756e2877d49c09f3ed9f Mon Sep 17 00:00:00 2001 From: eb Date: Mon, 23 Jun 2008 18:26:50 +0000 Subject: merged refactoring of gr_top_block_impl into abstract base class gr_top_block_impl and concrete class gr_top_block_impl_sts from eb/mp-sched r8447:8660. No change in functionality or behavior. Paves the way for development of multiprocessor aware scheduler. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8665 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 2 + gnuradio-core/src/lib/runtime/gr_top_block.cc | 3 +- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 114 +++--------------- gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 38 +++--- .../src/lib/runtime/gr_top_block_impl_sts.cc | 130 +++++++++++++++++++++ .../src/lib/runtime/gr_top_block_impl_sts.h | 55 +++++++++ 6 files changed, 225 insertions(+), 117 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index d84128cbd..0463581c7 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -55,6 +55,7 @@ libruntime_la_SOURCES = \ gr_sync_interpolator.cc \ gr_top_block.cc \ gr_top_block_impl.cc \ + gr_top_block_impl_sts.cc \ gr_tmp_path.cc \ gr_vmcircbuf.cc \ gr_vmcircbuf_mmap_shm_open.cc \ @@ -102,6 +103,7 @@ grinclude_HEADERS = \ gr_sync_interpolator.h \ gr_top_block.h \ gr_top_block_impl.h \ + gr_top_block_impl_sts.h \ gr_timer.h \ gr_tmp_path.h \ gr_types.h \ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 5cb0ccdea..473ea5883 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -42,7 +43,7 @@ gr_top_block::gr_top_block(const std::string &name) gr_make_io_signature(0,0,0)) { - d_impl = new gr_top_block_impl(this); + d_impl = new gr_top_block_impl_sts(this); } gr_top_block::~gr_top_block() diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 359665a77..857e9fa2d 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -37,55 +37,16 @@ #define GR_TOP_BLOCK_IMPL_DEBUG 0 -static gr_top_block_impl *s_impl = 0; - -/*! - * Make a vector of gr_block from a vector of gr_basic_block - * - * Pass-by-value to avoid problem with possible asynchronous modification - */ -static gr_block_vector_t -make_gr_block_vector(gr_basic_block_vector_t blocks) -{ - gr_block_vector_t result; - for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - result.push_back(make_gr_block_sptr(*p)); - } - - return result; -} - -// FIXME: This prevents using more than one gr_top_block instance - -static void -runtime_sigint_handler(int signum) -{ - if (GR_TOP_BLOCK_IMPL_DEBUG){ - char *msg = "SIGINT received, calling stop()\n"; - ::write(1, msg, strlen(msg)); // write is OK to call from signal handler - } - - if (s_impl) - s_impl->stop(); -} - -// ---------------------------------------------------------------- - gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) - : d_running(false), + : d_owner(owner), + d_running(false), d_ffg(), - d_owner(owner), d_lock_count(0) { - if (s_impl) - throw std::logic_error("gr_top_block_impl: multiple simultaneous gr_top_blocks not allowed"); - - s_impl = this; } gr_top_block_impl::~gr_top_block_impl() { - s_impl = 0; // don't call delete we don't own these d_owner = 0; } @@ -109,64 +70,6 @@ gr_top_block_impl::start() start_threads(); } -void -gr_top_block_impl::start_threads() -{ - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "start_threads: entered" << std::endl; - - d_graphs = d_ffg->partition(); - for (std::vector::iterator p = d_graphs.begin(); - p != d_graphs.end(); p++) { - gr_scheduler_thread *thread = new gr_scheduler_thread(make_gr_block_vector(*p)); - d_threads.push_back(thread); - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "start_threads: starting " << thread << std::endl; - thread->start(); - } - - d_running = true; -} - -/* - * N.B. as currently implemented, it is possible that this may be - * invoked by the SIGINT handler which is fragile as hell... - */ -void -gr_top_block_impl::stop() -{ - if (GR_TOP_BLOCK_IMPL_DEBUG){ - char *msg = "stop: entered\n"; - ::write(1, msg, strlen(msg)); - } - - for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { - if (*p) - (*p)->stop(); - } -} - -void -gr_top_block_impl::wait() -{ - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "wait: entered" << std::endl; - - void *dummy_status; // don't ever dereference this - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - - for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "wait: joining thread " << (*p) << std::endl; - (*p)->join(&dummy_status); // pthreads will self-delete, so pointer is now dead - (*p) = 0; // FIXME: switch to stl::list and actually remove from container - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "wait: join returned" << std::endl; - } - - d_threads.clear(); - d_running = false; -} // N.B. lock() and unlock() cannot be called from a flow graph thread or // deadlock will occur when reconfiguration happens @@ -238,3 +141,14 @@ gr_top_block_impl::dump() if (d_ffg) d_ffg->dump(); } + +gr_block_vector_t +gr_top_block_impl::make_gr_block_vector(gr_basic_block_vector_t blocks) +{ + gr_block_vector_t result; + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + result.push_back(make_gr_block_sptr(*p)); + } + + return result; +} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index abdfa9964..003afec93 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,9 +26,9 @@ #include /*! - *\brief Implementation details of gr_top_block - * + *\brief Abstract implementation details of gr_top_block * \ingroup internal + * * The actual implementation of gr_top_block. Separate class allows * decoupling of changes from dependent classes. * @@ -37,22 +37,22 @@ class gr_top_block_impl { public: gr_top_block_impl(gr_top_block *owner); - ~gr_top_block_impl(); + virtual ~gr_top_block_impl(); // Create and start scheduler threads - void start(); + virtual void start(); // Signal scheduler threads to stop - void stop(); + virtual void stop() = 0; // Wait for scheduler threads to exit - void wait(); + virtual void wait() = 0; // Lock the top block to allow reconfiguration - void lock(); + virtual void lock(); // Unlock the top block at end of reconfiguration - void unlock(); + virtual void unlock(); // Dump the flowgraph to stdout void dump(); @@ -60,19 +60,25 @@ public: // Return true if flowgraph is running bool is_running() const { return d_running; } -private: +protected: + gr_top_block *d_owner; bool d_running; gr_flat_flowgraph_sptr d_ffg; - gr_scheduler_thread_vector_t d_threads; - gr_top_block *d_owner; + + omni_mutex d_reconf; // protects d_lock_count int d_lock_count; - omni_mutex d_reconf; - std::vector d_graphs; + virtual void start_threads() = 0; + virtual void restart(); + +/*! + * Make a vector of gr_block from a vector of gr_basic_block + * + * Pass-by-value to avoid problem with possible asynchronous modification + */ + static gr_block_vector_t make_gr_block_vector(gr_basic_block_vector_t blocks); - void start_threads(); - void restart(); }; #endif /* INCLUDED_GR_TOP_BLOCK_IMPL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc new file mode 100644 index 000000000..39289ce5b --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc @@ -0,0 +1,130 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define GR_TOP_BLOCK_IMPL_STS_DEBUG 0 + +static gr_top_block_impl *s_impl = 0; + + +// FIXME: This prevents using more than one gr_top_block instance + +static void +runtime_sigint_handler(int signum) +{ + if (GR_TOP_BLOCK_IMPL_STS_DEBUG){ + char *msg = "SIGINT received, calling stop()\n"; + ::write(1, msg, strlen(msg)); // write is OK to call from signal handler + } + + if (s_impl) + s_impl->stop(); +} + +// ---------------------------------------------------------------- + +gr_top_block_impl_sts::gr_top_block_impl_sts(gr_top_block *owner) + : gr_top_block_impl(owner) +{ + if (s_impl) + throw std::logic_error("gr_top_block_impl_sts: multiple simultaneous gr_top_blocks not allowed"); + + s_impl = this; +} + +gr_top_block_impl_sts::~gr_top_block_impl_sts() +{ + s_impl = 0; // don't call delete we don't own these +} + +void +gr_top_block_impl_sts::start_threads() +{ + if (GR_TOP_BLOCK_IMPL_STS_DEBUG) + std::cout << "start_threads: entered" << std::endl; + + d_graphs = d_ffg->partition(); + for (std::vector::iterator p = d_graphs.begin(); + p != d_graphs.end(); p++) { + gr_scheduler_thread *thread = new gr_scheduler_thread(make_gr_block_vector(*p)); + d_threads.push_back(thread); + if (GR_TOP_BLOCK_IMPL_STS_DEBUG) + std::cout << "start_threads: starting " << thread << std::endl; + thread->start(); + } + + d_running = true; +} + +/* + * N.B. as currently implemented, it is possible that this may be + * invoked by the SIGINT handler which is fragile as hell... + */ +void +gr_top_block_impl_sts::stop() +{ + if (GR_TOP_BLOCK_IMPL_STS_DEBUG){ + char *msg = "stop: entered\n"; + ::write(1, msg, strlen(msg)); + } + + for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { + if (*p) + (*p)->stop(); + } +} + +void +gr_top_block_impl_sts::wait() +{ + if (GR_TOP_BLOCK_IMPL_STS_DEBUG) + std::cout << "wait: entered" << std::endl; + + void *dummy_status; // don't ever dereference this + gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); + + for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { + if (GR_TOP_BLOCK_IMPL_STS_DEBUG) + std::cout << "wait: joining thread " << (*p) << std::endl; + (*p)->join(&dummy_status); // omnithreads will self-delete, so pointer is now dead + (*p) = 0; // FIXME: switch to stl::list and actually remove from container + if (GR_TOP_BLOCK_IMPL_STS_DEBUG) + std::cout << "wait: join returned" << std::endl; + } + + d_threads.clear(); + d_running = false; +} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.h new file mode 100644 index 000000000..ec2e51cf2 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TOP_BLOCK_IMPL_STS_H +#define INCLUDED_GR_TOP_BLOCK_IMPL_STS_H + +#include +#include + +/*! + *\brief Implementation details of gr_top_block + * \ingroup internal + * + * Concrete implementation of gr_top_block using gr_single_threaded_scheduler. + */ +class gr_top_block_impl_sts : public gr_top_block_impl +{ +public: + gr_top_block_impl_sts(gr_top_block *owner); + ~gr_top_block_impl_sts(); + + // Signal scheduler threads to stop + void stop(); + + // Wait for scheduler threads to exit + void wait(); + +private: + + gr_scheduler_thread_vector_t d_threads; + std::vector d_graphs; + + void start_threads(); +}; + +#endif /* INCLUDED_GR_TOP_BLOCK_IMPL_STS_H */ -- cgit From 4d5e702b2a7d511f22b8e5dcce7da5ce77a2d322 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 24 Jun 2008 20:48:39 +0000 Subject: removed is_running method from gr_top_block git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8689 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_top_block.cc | 6 ------ gnuradio-core/src/lib/runtime/gr_top_block.h | 7 +------ gnuradio-core/src/lib/runtime/gr_top_block.i | 3 +-- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 13 ++++++++++--- gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 10 ++++------ gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc | 2 -- 6 files changed, 16 insertions(+), 25 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 473ea5883..339f3cb89 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -96,9 +96,3 @@ gr_top_block::dump() { d_impl->dump(); } - -bool -gr_top_block::is_running() -{ - return d_impl->is_running(); -} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 637a38468..b47ec019c 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -103,11 +103,6 @@ public: * Displays flattened flowgraph edges and block connectivity */ void dump(); - - /*! - * Returns true if flowgraph is running - */ - bool is_running(); }; #endif /* INCLUDED_GR_TOP_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index d2e8e3b41..670e5b5e5 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -46,7 +46,6 @@ public: void run(); void lock(); void unlock() throw (std::runtime_error); - bool is_running(); void dump(); }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 857e9fa2d..591437938 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -57,7 +57,10 @@ gr_top_block_impl::start() std::cout << "start: entered " << this << std::endl; if (d_running) - throw std::runtime_error("top block already running or wait() not called after previous stop()"); + throw std::runtime_error("top_block::start: top block already running or wait() not called after previous stop()"); + + if (d_lock_count > 0) + throw std::runtime_error("top_block::start: can't call start with flow graph locked"); // Create new flat flow graph by flattening hierarchy d_ffg = d_owner->flatten(); @@ -68,6 +71,7 @@ gr_top_block_impl::start() // Execute scheduler threads start_threads(); + d_running = true; } @@ -86,8 +90,10 @@ void gr_top_block_impl::unlock() { omni_mutex_lock lock(d_reconf); - if (d_lock_count <= 0) + if (d_lock_count <= 0){ + d_lock_count = 0; // fix it, then complain throw std::runtime_error("unpaired unlock() call"); + } d_lock_count--; if (GR_TOP_BLOCK_IMPL_DEBUG) @@ -107,7 +113,7 @@ gr_top_block_impl::restart() std::cout << "restart: entered" << std::endl; if (!d_running) - throw std::runtime_error("top block is not running"); + return; // nothing to do // Stop scheduler threads and wait for completion stop(); @@ -133,6 +139,7 @@ gr_top_block_impl::restart() d_ffg = new_ffg; start_threads(); + d_running = true; } void diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 003afec93..869f788ef 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -49,16 +49,13 @@ public: virtual void wait() = 0; // Lock the top block to allow reconfiguration - virtual void lock(); + void lock(); // Unlock the top block at end of reconfiguration - virtual void unlock(); + void unlock(); // Dump the flowgraph to stdout void dump(); - - // Return true if flowgraph is running - bool is_running() const { return d_running; } protected: @@ -70,7 +67,6 @@ protected: int d_lock_count; virtual void start_threads() = 0; - virtual void restart(); /*! * Make a vector of gr_block from a vector of gr_basic_block @@ -79,6 +75,8 @@ protected: */ static gr_block_vector_t make_gr_block_vector(gr_basic_block_vector_t blocks); +private: + void restart(); }; #endif /* INCLUDED_GR_TOP_BLOCK_IMPL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc index 39289ce5b..b3e9da627 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc @@ -85,8 +85,6 @@ gr_top_block_impl_sts::start_threads() std::cout << "start_threads: starting " << thread << std::endl; thread->start(); } - - d_running = true; } /* -- cgit From 7d8ec624a0b832f695d7f91eb7cf4f6359502142 Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 9 Jul 2008 16:02:37 +0000 Subject: fix for ticket:250 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8835 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_sync_interpolator.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc index f61e59ea1..d130a5be1 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -50,7 +50,7 @@ gr_sync_interpolator::fixed_rate_noutput_to_ninput(int noutput_items) } int -gr_sync_interpolator::fixed_rate_ninput_to_noutout(int ninput_items) +gr_sync_interpolator::fixed_rate_ninput_to_noutput(int ninput_items) { return std::max(0, ninput_items - (int)history() + 1) * interpolation(); } diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index b5dfed70c..87e718cca 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -60,7 +60,7 @@ class gr_sync_interpolator : public gr_sync_block // derived classes should override work - int fixed_rate_ninput_to_noutout(int ninput); + int fixed_rate_ninput_to_noutput(int ninput); int fixed_rate_noutput_to_ninput(int noutput); }; -- cgit From 395e1fa650428899dee0f123cb7bf432732280c5 Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 9 Jul 2008 18:59:37 +0000 Subject: Merged jcorgan/ptrfix -r8827:8843 into the trunk. Fix that allows C++ classes derived from gr_hier_block2 to use the new self() method to get a magic object that can be passed to connect or disconnect to refer to their own inputs and outputs. Note that the constructor wrapper of all classes derived from gr_hier_block2 (and thus gr_top_block too) MUST USE the new gnuradio::get_initial_sptr function to get the initial shared pointer. gnuradio::get_initial_sptr works on all block types, and should be used in all new code. See qa_gr_hier_block2_derived.{h,cc} for an example. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8844 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 4 + gnuradio-core/src/lib/runtime/gr_basic_block.h | 3 +- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 21 ++++-- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 22 +++++- .../src/lib/runtime/gr_hier_block2_detail.cc | 12 +-- gnuradio-core/src/lib/runtime/gr_sptr_magic.cc | 81 ++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_sptr_magic.h | 51 +++++++++++++ gnuradio-core/src/lib/runtime/gr_top_block.cc | 2 +- gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc | 25 +++++-- gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h | 3 +- .../src/lib/runtime/qa_gr_hier_block2_derived.cc | 87 ++++++++++++++++++++++ .../src/lib/runtime/qa_gr_hier_block2_derived.h | 41 ++++++++++ gnuradio-core/src/lib/runtime/qa_runtime.cc | 2 + 13 files changed, 329 insertions(+), 25 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/gr_sptr_magic.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_sptr_magic.h create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 0463581c7..550031b94 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -50,6 +50,7 @@ libruntime_la_SOURCES = \ gr_realtime.cc \ gr_scheduler_thread.cc \ gr_single_threaded_scheduler.cc \ + gr_sptr_magic.cc \ gr_sync_block.cc \ gr_sync_decimator.cc \ gr_sync_interpolator.cc \ @@ -67,6 +68,7 @@ libruntime_la_SOURCES = \ libruntime_qa_la_SOURCES = \ qa_gr_block.cc \ qa_gr_hier_block2.cc \ + qa_gr_hier_block2_derived.cc \ qa_gr_buffer.cc \ qa_gr_flowgraph.cc \ qa_gr_top_block.cc \ @@ -98,6 +100,7 @@ grinclude_HEADERS = \ gr_scheduler_thread.h \ gr_select_handler.h \ gr_single_threaded_scheduler.h \ + gr_sptr_magic.h \ gr_sync_block.h \ gr_sync_decimator.h \ gr_sync_interpolator.h \ @@ -117,6 +120,7 @@ noinst_HEADERS = \ qa_gr_block.h \ qa_gr_flowgraph.h \ qa_gr_hier_block2.h \ + qa_gr_hier_block2_derived.h \ qa_gr_buffer.h \ qa_gr_io_signature.h \ qa_gr_top_block.h \ diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 8dc965da7..7dda1201f 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,6 +24,7 @@ #define INCLUDED_GR_BASIC_BLOCK_H #include +#include #include #include diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index 23f274da7..e3a25e1a8 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2007 Free Software Foundation, Inc. + * Copyright 2006,2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -31,11 +31,13 @@ #define GR_HIER_BLOCK2_DEBUG 0 -gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature) + +gr_hier_block2_sptr +gr_make_hier_block2(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature) { - return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); + return gnuradio::get_initial_sptr(new gr_hier_block2(name, input_signature, output_signature)); } gr_hier_block2::gr_hier_block2(const std::string &name, @@ -44,6 +46,8 @@ gr_hier_block2::gr_hier_block2(const std::string &name, : gr_basic_block(name, input_signature, output_signature), d_detail(new gr_hier_block2_detail(this)) { + // This bit of magic ensures that self() works in the constructors of derived classes. + gnuradio::detail::sptr_magic::create_and_stash_initial_sptr(this); } gr_hier_block2::~gr_hier_block2() @@ -51,6 +55,13 @@ gr_hier_block2::~gr_hier_block2() delete d_detail; } +gr_hier_block2::opaque_self +gr_hier_block2::self() +{ + return shared_from_this(); +} + + void gr_hier_block2::connect(gr_basic_block_sptr block) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 5e67a9010..ece8b21ca 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2007 Free Software Foundation, Inc. + * Copyright 2006,2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -51,7 +51,7 @@ private: * \brief Private implementation details of gr_hier_block2 */ gr_hier_block2_detail *d_detail; - + protected: gr_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, @@ -60,6 +60,22 @@ protected: public: virtual ~gr_hier_block2(); + /*! + * \brief typedef for object returned from self(). + * + * This type is only guaranteed to be passable to connect and disconnect. + * No other assumptions should be made about it. + */ + typedef gr_basic_block_sptr opaque_self; + + /*! + * \brief Return an object, representing the current block, which can be passed to connect. + * + * The returned object may only be used as an argument to connect or disconnect. + * Any other use of self() results in unspecified (erroneous) behavior. + */ + opaque_self self(); + /*! * \brief Add a stand-alone (possibly hierarchical) block to internal graph * @@ -132,7 +148,7 @@ public: gr_flat_flowgraph_sptr flatten() const; }; -inline gr_hier_block2_sptr make_hier_block2_sptr(gr_basic_block_sptr block) { +inline gr_hier_block2_sptr cast_to_hier_block2_sptr(gr_basic_block_sptr block) { return boost::dynamic_pointer_cast(block); } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 26a28fabd..32cac2ea8 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -78,8 +78,8 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, if (src.get() == dst.get()) throw std::invalid_argument("connect: src and destination blocks cannot be the same"); - gr_hier_block2_sptr src_block(make_hier_block2_sptr(src)); - gr_hier_block2_sptr dst_block(make_hier_block2_sptr(dst)); + gr_hier_block2_sptr src_block(cast_to_hier_block2_sptr(src)); + gr_hier_block2_sptr dst_block(cast_to_hier_block2_sptr(dst)); if (src_block && src.get() != d_owner) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) @@ -147,8 +147,8 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, if (src.get() == dst.get()) throw std::invalid_argument("disconnect: source and destination blocks cannot be the same"); - gr_hier_block2_sptr src_block(make_hier_block2_sptr(src)); - gr_hier_block2_sptr dst_block(make_hier_block2_sptr(dst)); + gr_hier_block2_sptr src_block(cast_to_hier_block2_sptr(src)); + gr_hier_block2_sptr dst_block(cast_to_hier_block2_sptr(dst)); if (src_block && src.get() != d_owner) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) @@ -307,7 +307,7 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) return endp; // Check if endpoint is a hierarchical block - gr_hier_block2_sptr hier_block2(make_hier_block2_sptr(endp.block())); + gr_hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(endp.block())); if (hier_block2) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "Resolving endpoint " << endp << " as an " @@ -351,7 +351,7 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const // Recurse hierarchical children for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - gr_hier_block2_sptr hier_block2(make_hier_block2_sptr(*p)); + gr_hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(*p)); if (hier_block2) hier_block2->d_detail->flatten_aux(sfg); } diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc new file mode 100644 index 000000000..dc0b232a7 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc @@ -0,0 +1,81 @@ +/* -*- 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 +#endif +#include +#include +#include +#include + + +#if 0 + #include + typedef boost::mutex mutex; + typedef boost::mutex::scoped_lock scoped_lock; +#else + #include + typedef omni_mutex mutex; + typedef omni_mutex_lock scoped_lock; +#endif + +namespace gnuradio { + + static mutex s_mutex; + typedef std::map sptr_map; + static sptr_map s_map; + + void + detail::sptr_magic::create_and_stash_initial_sptr(gr_hier_block2 *p) + { + gr_basic_block_sptr sptr(p); + scoped_lock l(); + s_map.insert(sptr_map::value_type(static_cast(p), sptr)); + } + + + gr_basic_block_sptr + detail::sptr_magic::fetch_initial_sptr(gr_basic_block *p) + { + /* + * If p isn't a subclass of gr_hier_block2, just create the + * shared ptr and return it. + */ + gr_hier_block2 *hb2 = dynamic_cast(p); + if (!hb2){ + return gr_basic_block_sptr(p); + } + + /* + * p is a subclass of gr_hier_block2, thus we've already created the shared pointer + * and stashed it away. Fish it out and return it. + */ + scoped_lock l(); + sptr_map::iterator pos = s_map.find(static_cast(p)); + if (pos == s_map.end()) + throw std::invalid_argument("gr_sptr_magic: invalid pointer!"); + + gr_basic_block_sptr sptr = pos->second; + s_map.erase(pos); + return sptr; + } +}; + diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.h b/gnuradio-core/src/lib/runtime/gr_sptr_magic.h new file mode 100644 index 000000000..872374ab6 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.h @@ -0,0 +1,51 @@ +/* -*- 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_SPTR_MAGIC_H +#define INCLUDED_GR_SPTR_MAGIC_H + +#include + +class gr_basic_block; +class gr_hier_block2; + +namespace gnuradio { + + namespace detail { + + class sptr_magic { + public: + static boost::shared_ptr fetch_initial_sptr(gr_basic_block *p); + static void create_and_stash_initial_sptr(gr_hier_block2 *p); + }; + }; + + /* + * \brief New! Improved! Standard method to get/create the boost::shared_ptr for a block. + */ + template + boost::shared_ptr + get_initial_sptr(T *p) + { + return boost::dynamic_pointer_cast(detail::sptr_magic::fetch_initial_sptr(p)); + } +}; + +#endif /* INCLUDED_GR_SPTR_MAGIC_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 339f3cb89..3c8e28f70 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -34,7 +34,7 @@ gr_top_block_sptr gr_make_top_block(const std::string &name) { - return gr_top_block_sptr(new gr_top_block(name)); + return gnuradio::get_initial_sptr(new gr_top_block(name)); } gr_top_block::gr_top_block(const std::string &name) diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc index 07b9d5ecf..2cf1a8d10 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -33,14 +33,25 @@ void qa_gr_hier_block2::test_make() { gr_hier_block2_sptr src1(gr_make_hier_block2("test", - gr_make_io_signature(1, 1, sizeof(int)), - gr_make_io_signature(1, 1, sizeof(int)))); + gr_make_io_signature(1, 2, 1 * sizeof(int)), + gr_make_io_signature(3, 4, 2 * sizeof(int)))); CPPUNIT_ASSERT(src1); CPPUNIT_ASSERT_EQUAL(std::string("test"), src1->name()); - CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->max_streams()); - CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->min_streams()); - CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->max_streams()); - CPPUNIT_ASSERT_EQUAL((int) sizeof(int), + + CPPUNIT_ASSERT_EQUAL(1 * (int) sizeof(int), + src1->input_signature()->sizeof_stream_item(0)); + + CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->min_streams()); + CPPUNIT_ASSERT_EQUAL(2, src1->input_signature()->max_streams()); + + + CPPUNIT_ASSERT_EQUAL(2 * (int) sizeof(int), src1->output_signature()->sizeof_stream_item(0)); + + CPPUNIT_ASSERT_EQUAL(3, src1->output_signature()->min_streams()); + CPPUNIT_ASSERT_EQUAL(4, src1->output_signature()->max_streams()); + } + + diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h index a07ed7bf8..3870b9f0f 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h @@ -32,12 +32,11 @@ class qa_gr_hier_block2 : public CppUnit::TestCase CPPUNIT_TEST_SUITE(qa_gr_hier_block2); CPPUNIT_TEST(test_make); - + CPPUNIT_TEST_SUITE_END(); private: void test_make(); - void test_derived(); }; #endif /* INCLUDED_QA_GR_HIER_BLOCK2_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc new file mode 100644 index 000000000..fe5f3a751 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc @@ -0,0 +1,87 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +// Declare a test C++ hierarchical block + +class gr_derived_block; +typedef boost::shared_ptr gr_derived_block_sptr; +gr_derived_block_sptr gr_make_derived_block(); + +class gr_derived_block : public gr_hier_block2 +{ +private: + friend gr_derived_block_sptr gr_make_derived_block(); + gr_derived_block(); + +public: + ~gr_derived_block(); +}; + + +gr_derived_block_sptr +gr_make_derived_block() +{ + return gnuradio::get_initial_sptr(new gr_derived_block()); +} + +gr_derived_block::gr_derived_block() + : gr_hier_block2("gr_derived_block", + gr_make_io_signature(1, 1, sizeof(int)), // Input signature + gr_make_io_signature(1, 1, sizeof(int))) // Output signature +{ + gr_block_sptr copy(gr_make_kludge_copy(sizeof(int))); + + connect(self(), 0, copy, 0); + connect(copy, 0, self(), 0); +} + +gr_derived_block::~gr_derived_block() +{ +} + +void qa_gr_hier_block2_derived::test_1() +{ + gr_top_block_sptr tb(gr_make_top_block("test")); + + gr_block_sptr src(gr_make_null_source(sizeof(int))); + gr_block_sptr head(gr_make_head(sizeof(int), 1000)); + gr_derived_block_sptr blk(gr_make_derived_block()); + gr_block_sptr dst(gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, blk, 0); + tb->connect(blk, 0, dst, 0); + + tb->run(); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h new file mode 100644 index 000000000..5a27b1b2d --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h @@ -0,0 +1,41 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_QA_GR_HIER_BLOCK2_DERIVED_H +#define INCLUDED_QA_GR_HIER_BLOCK2_DERIVED_H + +#include +#include +#include + +// Declare a QA test case +class qa_gr_hier_block2_derived : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_gr_hier_block2_derived); + CPPUNIT_TEST(test_1); + CPPUNIT_TEST_SUITE_END(); + +private: + void test_1(); +}; + +#endif /* INCLUDED_QA_GR_HIER_BLOCK2_DERIVED_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index ba0f14b93..31e3a82d6 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -36,6 +36,7 @@ #include #include #include +#include #include CppUnit::TestSuite * @@ -49,6 +50,7 @@ qa_runtime::suite () s->addTest (qa_gr_flowgraph::suite ()); s->addTest (qa_gr_top_block::suite ()); s->addTest (qa_gr_hier_block2::suite ()); + s->addTest (qa_gr_hier_block2_derived::suite ()); s->addTest (qa_gr_buffer::suite ()); return s; -- cgit From 6898c0abce827366e8985ba1d3f6805056eebc05 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 12 Aug 2008 17:01:37 +0000 Subject: Make gr_basic_block sort deterministic (Martin Dvh) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9251 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 7dda1201f..78297d3f0 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -98,6 +98,11 @@ public: virtual bool check_topology(int ninputs, int noutputs) { return true; } }; +inline bool operator<(gr_basic_block_sptr lhs, gr_basic_block_sptr rhs) +{ + return lhs->unique_id() < rhs->unique_id(); +} + typedef std::vector gr_basic_block_vector_t; typedef std::vector::iterator gr_basic_block_viter_t; -- cgit From 5b09804605cd41bbc3fdcb917eda3f69a7598af9 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 12 Aug 2008 17:38:29 +0000 Subject: Refactored unique vector functionality into template. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9253 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_flowgraph.cc | 55 ++++++++++++--------------- 1 file changed, 24 insertions(+), 31 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc index 359570347..27f6257cc 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc @@ -48,6 +48,20 @@ gr_flowgraph::~gr_flowgraph() { } +// FIXME: move to libgruel as a utility function +template +static +std::vector +unique_vector(std::vector v) +{ + std::vector result; + std::insert_iterator > inserter(result, result.begin()); + + sort(v.begin(), v.end()); + unique_copy(v.begin(), v.end(), inserter); + return result; +} + void gr_flowgraph::connect(const gr_endpoint &src, const gr_endpoint &dst) { @@ -163,8 +177,7 @@ gr_flowgraph::check_type_match(const gr_endpoint &src, const gr_endpoint &dst) gr_basic_block_vector_t gr_flowgraph::calc_used_blocks() { - gr_basic_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); + gr_basic_block_vector_t tmp; // Collect all blocks in the edge list for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { @@ -172,17 +185,13 @@ gr_flowgraph::calc_used_blocks() tmp.push_back(p->dst().block()); } - // Return vector of unique blocks - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; + return unique_vector(tmp); } std::vector gr_flowgraph::calc_used_ports(gr_basic_block_sptr block, bool check_inputs) { - std::vector tmp, result; - std::insert_iterator > inserter(result, result.begin()); + std::vector tmp; // Collect all seen ports gr_edge_vector_t edges = calc_connections(block, check_inputs); @@ -193,10 +202,7 @@ gr_flowgraph::calc_used_ports(gr_basic_block_sptr block, bool check_inputs) tmp.push_back(p->src().port()); } - // Return vector of unique values - std::sort(tmp.begin(), tmp.end()); - std::unique_copy(tmp.begin(), tmp.end(), inserter); - return result; + return unique_vector(tmp); } gr_edge_vector_t @@ -264,33 +270,25 @@ gr_flowgraph::check_contiguity(gr_basic_block_sptr block, gr_basic_block_vector_t gr_flowgraph::calc_downstream_blocks(gr_basic_block_sptr block, int port) { - gr_basic_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); + gr_basic_block_vector_t tmp; for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) if (p->src() == gr_endpoint(block, port)) tmp.push_back(p->dst().block()); - // Remove duplicates - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; + return unique_vector(tmp); } gr_basic_block_vector_t gr_flowgraph::calc_downstream_blocks(gr_basic_block_sptr block) { - gr_basic_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); + gr_basic_block_vector_t tmp; for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) if (p->src().block() == block) tmp.push_back(p->dst().block()); - // Remove duplicates - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; + return unique_vector(tmp); } gr_edge_vector_t @@ -386,22 +384,17 @@ gr_flowgraph::reachable_dfs_visit(gr_basic_block_sptr block, gr_basic_block_vect gr_basic_block_vector_t gr_flowgraph::calc_adjacent_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) { - gr_basic_block_vector_t tmp, result; - std::insert_iterator inserter(result, result.begin()); + gr_basic_block_vector_t tmp; // Find any blocks that are inputs or outputs for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { - if (p->src().block() == block) tmp.push_back(p->dst().block()); if (p->dst().block() == block) tmp.push_back(p->src().block()); } - // Remove duplicates - sort(tmp.begin(), tmp.end()); - unique_copy(tmp.begin(), tmp.end(), inserter); - return result; + return unique_vector(tmp); } gr_basic_block_vector_t -- cgit From 2c8ea58e4d76f54c98d71d3fcc64bc29da490908 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 19 Aug 2008 23:09:56 +0000 Subject: Merged features/mp-sched -r8915:9335 into the trunk. The trunk now contains the SMP aware scheduler. This changeset introduces a dependency on boost 1.35 or later. See source:gnuradio/trunk/README.building-boost for additional info. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9336 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 20 +- gnuradio-core/src/lib/runtime/gr_block.cc | 8 + gnuradio-core/src/lib/runtime/gr_block.h | 6 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 11 +- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 329 +++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block_executor.h | 69 +++++ gnuradio-core/src/lib/runtime/gr_buffer.cc | 31 +- gnuradio-core/src/lib/runtime/gr_buffer.h | 71 ++++- gnuradio-core/src/lib/runtime/gr_buffer.i | 8 +- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 48 ++- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 9 +- gnuradio-core/src/lib/runtime/gr_flowgraph.h | 4 +- .../src/lib/runtime/gr_hier_block2_detail.cc | 2 +- gnuradio-core/src/lib/runtime/gr_scheduler.cc | 33 +++ gnuradio-core/src/lib/runtime/gr_scheduler.h | 64 ++++ gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc | 87 ++++++ gnuradio-core/src/lib/runtime/gr_scheduler_sts.h | 62 ++++ .../src/lib/runtime/gr_scheduler_thread.cc | 110 ------- .../src/lib/runtime/gr_scheduler_thread.h | 59 ---- gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc | 95 ++++++ gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h | 60 ++++ .../lib/runtime/gr_single_threaded_scheduler.cc | 12 +- gnuradio-core/src/lib/runtime/gr_top_block.cc | 3 +- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 135 +++++---- gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 32 +- .../src/lib/runtime/gr_top_block_impl_sts.cc | 128 -------- .../src/lib/runtime/gr_top_block_impl_sts.h | 55 ---- gnuradio-core/src/lib/runtime/gr_tpb_detail.cc | 67 +++++ gnuradio-core/src/lib/runtime/gr_tpb_detail.h | 81 +++++ .../src/lib/runtime/gr_tpb_thread_body.cc | 76 +++++ gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h | 45 +++ gnuradio-core/src/lib/runtime/qa_gr_buffer.cc | 14 +- 32 files changed, 1336 insertions(+), 498 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/gr_block_executor.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_block_executor.h create mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler.h create mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler_sts.h delete mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler_thread.h create mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h delete mode 100644 gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.h create mode 100644 gnuradio-core/src/lib/runtime/gr_tpb_detail.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_tpb_detail.h create mode 100644 gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 550031b94..b21b32412 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -21,7 +21,7 @@ include $(top_srcdir)/Makefile.common -AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) +AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES) noinst_LTLIBRARIES = libruntime.la libruntime-qa.la @@ -35,6 +35,7 @@ libruntime_la_SOURCES = \ gr_flat_flowgraph.cc \ gr_block.cc \ gr_block_detail.cc \ + gr_block_executor.cc \ gr_hier_block2.cc \ gr_hier_block2_detail.cc \ gr_buffer.cc \ @@ -48,16 +49,19 @@ libruntime_la_SOURCES = \ gr_pagesize.cc \ gr_preferences.cc \ gr_realtime.cc \ - gr_scheduler_thread.cc \ + gr_scheduler.cc \ + gr_scheduler_sts.cc \ + gr_scheduler_tpb.cc \ gr_single_threaded_scheduler.cc \ gr_sptr_magic.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_top_block_impl_sts.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 \ @@ -82,6 +86,7 @@ grinclude_HEADERS = \ gr_flat_flowgraph.h \ gr_block.h \ gr_block_detail.h \ + gr_block_executor.h \ gr_hier_block2.h \ gr_hier_block2_detail.h \ gr_buffer.h \ @@ -97,7 +102,9 @@ grinclude_HEADERS = \ gr_preferences.h \ gr_realtime.h \ gr_runtime_types.h \ - gr_scheduler_thread.h \ + gr_scheduler.h \ + gr_scheduler_sts.h \ + gr_scheduler_tpb.h \ gr_select_handler.h \ gr_single_threaded_scheduler.h \ gr_sptr_magic.h \ @@ -106,7 +113,8 @@ grinclude_HEADERS = \ gr_sync_interpolator.h \ gr_top_block.h \ gr_top_block_impl.h \ - gr_top_block_impl_sts.h \ + gr_tpb_detail.h \ + gr_tpb_thread_body.h \ gr_timer.h \ gr_tmp_path.h \ gr_types.h \ diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 0a8fb92c2..7c2e9901b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -110,3 +110,11 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) { throw std::runtime_error("Unimplemented"); } + +std::ostream& +operator << (std::ostream& os, const gr_block *m) +{ + os << "name() << " (" << m->unique_id() << ")>"; + return os; +} + diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 79237ee83..437b610b4 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -214,9 +214,13 @@ class gr_block : public gr_basic_block { typedef std::vector gr_block_vector_t; typedef std::vector::iterator gr_block_viter_t; -inline gr_block_sptr make_gr_block_sptr(gr_basic_block_sptr p) +inline gr_block_sptr cast_to_block_sptr(gr_basic_block_sptr p) { return boost::dynamic_pointer_cast(p); } + +std::ostream& +operator << (std::ostream& os, const gr_block *m); + #endif /* INCLUDED_GR_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index a3b7731c0..2856c402c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -24,6 +24,7 @@ #define INCLUDED_GR_BLOCK_DETAIL_H #include +#include #include /*! @@ -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 (); @@ -73,8 +73,14 @@ class gr_block_detail { */ void consume_each (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); + + gr_tpb_detail d_tpb; // used by thread-per-block scheduler + // ---------------------------------------------------------------------------- private: @@ -84,8 +90,11 @@ class gr_block_detail { std::vector 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); }; diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc new file mode 100644 index 000000000..fd3a916d4 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -0,0 +1,329 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// must be defined to either 0 or 1 +#define ENABLE_LOGGING 0 + +#if (ENABLE_LOGGING) +#define LOG(x) do { x; } while(0) +#else +#define LOG(x) do {;} while(0) +#endif + +static int which_scheduler = 0; + +inline static unsigned int +round_up (unsigned int n, unsigned int multiple) +{ + return ((n + multiple - 1) / multiple) * multiple; +} + +inline static unsigned int +round_down (unsigned int n, unsigned int multiple) +{ + return (n / multiple) * multiple; +} + +// +// Return minimum available write space in all our downstream buffers +// or -1 if we're output blocked and the output we're blocked +// on is done. +// +static int +min_available_space (gr_block_detail *d, int output_multiple) +{ + int min_space = std::numeric_limits::max(); + + for (int i = 0; i < d->noutputs (); i++){ + gr_buffer::scoped_lock guard(*d->output(i)->mutex()); +#if 0 + int n = round_down(d->output(i)->space_available(), output_multiple); +#else + int n = round_down(std::min(d->output(i)->space_available(), + d->output(i)->bufsize()/2), + output_multiple); +#endif + if (n == 0){ // We're blocked on output. + if (d->output(i)->done()){ // Downstream is done, therefore we're done. + return -1; + } + return 0; + } + min_space = std::min (min_space, n); + } + return min_space; +} + + + +gr_block_executor::gr_block_executor (gr_block_sptr block) + : d_block(block), d_log(0) +{ + if (ENABLE_LOGGING){ + char name[100]; + snprintf(name, sizeof(name), "sst-%03d.log", which_scheduler++); + d_log = new std::ofstream(name); + std::unitbuf(*d_log); // make it unbuffered... + *d_log << "gr_block_executor: " + << d_block << std::endl; + } + + d_block->start(); // enable any drivers, etc. +} + +gr_block_executor::~gr_block_executor () +{ + if (ENABLE_LOGGING) + delete d_log; + + d_block->stop(); // stop any drivers, etc. +} + +gr_block_executor::state +gr_block_executor::run_one_iteration() +{ + int noutput_items; + int max_items_avail; + + gr_block *m = d_block.get(); + gr_block_detail *d = m->detail().get(); + + LOG(*d_log << std::endl << m); + + if (d->done()){ + assert(0); + return DONE; + } + + if (d->source_p ()){ + d_ninput_items_required.resize (0); + d_ninput_items.resize (0); + d_input_items.resize (0); + d_input_done.resize(0); + d_output_items.resize (d->noutputs ()); + + // determine the minimum available output space + noutput_items = min_available_space (d, m->output_multiple ()); + LOG(*d_log << " source\n noutput_items = " << noutput_items << std::endl); + if (noutput_items == -1) // we're done + goto were_done; + + if (noutput_items == 0){ // we're output blocked + LOG(*d_log << " BLKD_OUT\n"); + return BLKD_OUT; + } + + goto setup_call_to_work; // jump to common code + } + + else if (d->sink_p ()){ + d_ninput_items_required.resize (d->ninputs ()); + d_ninput_items.resize (d->ninputs ()); + d_input_items.resize (d->ninputs ()); + d_input_done.resize(d->ninputs()); + d_output_items.resize (0); + LOG(*d_log << " sink\n"); + + max_items_avail = 0; + for (int i = 0; i < d->ninputs (); i++){ + { + /* + * Acquire the mutex and grab local copies of items_available and done. + */ + gr_buffer::scoped_lock guard(*d->input(i)->mutex()); + d_ninput_items[i] = d->input(i)->items_available(); + d_input_done[i] = d->input(i)->done(); + } + + LOG(*d_log << " d_ninput_items[" << i << "] = " << d_ninput_items[i] << std::endl); + LOG(*d_log << " d_input_done[" << i << "] = " << d_input_done[i] << std::endl); + + if (d_ninput_items[i] < m->output_multiple() && d_input_done[i]) + goto were_done; + + max_items_avail = std::max (max_items_avail, d_ninput_items[i]); + } + + // take a swag at how much output we can sink + noutput_items = (int) (max_items_avail * m->relative_rate ()); + noutput_items = round_down (noutput_items, m->output_multiple ()); + LOG(*d_log << " max_items_avail = " << max_items_avail << std::endl); + LOG(*d_log << " noutput_items = " << noutput_items << std::endl); + + if (noutput_items == 0){ // we're blocked on input + LOG(*d_log << " BLKD_IN\n"); + return BLKD_IN; + } + + goto try_again; // Jump to code shared with regular case. + } + + else { + // do the regular thing + d_ninput_items_required.resize (d->ninputs ()); + d_ninput_items.resize (d->ninputs ()); + d_input_items.resize (d->ninputs ()); + d_input_done.resize(d->ninputs()); + d_output_items.resize (d->noutputs ()); + + max_items_avail = 0; + for (int i = 0; i < d->ninputs (); i++){ + { + /* + * Acquire the mutex and grab local copies of items_available and done. + */ + gr_buffer::scoped_lock guard(*d->input(i)->mutex()); + d_ninput_items[i] = d->input(i)->items_available (); + d_input_done[i] = d->input(i)->done(); + } + max_items_avail = std::max (max_items_avail, d_ninput_items[i]); + } + + // determine the minimum available output space + noutput_items = min_available_space (d, m->output_multiple ()); + if (ENABLE_LOGGING){ + *d_log << " regular "; + if (m->relative_rate() >= 1.0) + *d_log << "1:" << m->relative_rate() << std::endl; + else + *d_log << 1.0/m->relative_rate() << ":1\n"; + *d_log << " max_items_avail = " << max_items_avail << std::endl; + *d_log << " noutput_items = " << noutput_items << std::endl; + } + if (noutput_items == -1) // we're done + goto were_done; + + if (noutput_items == 0){ // we're output blocked + LOG(*d_log << " BLKD_OUT\n"); + return BLKD_OUT; + } + + try_again: + if (m->fixed_rate()){ + // try to work it forward starting with max_items_avail. + // We want to try to consume all the input we've got. + int reqd_noutput_items = m->fixed_rate_ninput_to_noutput(max_items_avail); + reqd_noutput_items = round_up(reqd_noutput_items, m->output_multiple()); + if (reqd_noutput_items > 0 && reqd_noutput_items <= noutput_items) + noutput_items = reqd_noutput_items; + } + + // ask the block how much input they need to produce noutput_items + m->forecast (noutput_items, d_ninput_items_required); + + // See if we've got sufficient input available + + int i; + for (i = 0; i < d->ninputs (); i++) + if (d_ninput_items_required[i] > d_ninput_items[i]) // not enough + break; + + if (i < d->ninputs ()){ // not enough input on input[i] + // if we can, try reducing the size of our output request + if (noutput_items > m->output_multiple ()){ + noutput_items /= 2; + noutput_items = round_up (noutput_items, m->output_multiple ()); + goto try_again; + } + + // We're blocked on input + LOG(*d_log << " BLKD_IN\n"); + if (d_input_done[i]) // If the upstream block is done, we're done + goto were_done; + + // Is it possible to ever fulfill this request? + if (d_ninput_items_required[i] > d->input(i)->max_possible_items_available ()){ + // Nope, never going to happen... + std::cerr << "\nsched: name() + << " (" << m->unique_id() << ")>" + << " is requesting more input data\n" + << " than we can provide.\n" + << " ninput_items_required = " + << d_ninput_items_required[i] << "\n" + << " max_possible_items_available = " + << d->input(i)->max_possible_items_available() << "\n" + << " If this is a filter, consider reducing the number of taps.\n"; + goto were_done; + } + + return BLKD_IN; + } + + // We've got enough data on each input to produce noutput_items. + // Finish setting up the call to work. + + for (int i = 0; i < d->ninputs (); i++) + d_input_items[i] = d->input(i)->read_pointer(); + + setup_call_to_work: + + for (int i = 0; i < d->noutputs (); i++) + d_output_items[i] = d->output(i)->write_pointer(); + + // Do the actual work of the block + int n = m->general_work (noutput_items, d_ninput_items, + d_input_items, d_output_items); + LOG(*d_log << " general_work: noutput_items = " << noutput_items + << " result = " << n << std::endl); + + if (n == -1) // block is done + goto were_done; + + d->produce_each (n); // advance write pointers + if (n > 0) + return READY; + + // We didn't produce any output even though we called general_work. + // We have (most likely) consumed some input. + + // 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; + } + + // Have the caller try again... + return READY_NO_OUTPUT; + } + assert (0); + + were_done: + LOG(*d_log << " were_done\n"); + d->set_done (true); + return DONE; +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h new file mode 100644 index 000000000..41b5ede7c --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_BLOCK_EXECUTOR_H +#define INCLUDED_GR_BLOCK_EXECUTOR_H + +#include +#include + +//class gr_block_executor; +//typedef boost::shared_ptr gr_block_executor_sptr; + + +/*! + * \brief Manage the execution of a single block. + * \ingroup internal + */ + +class gr_block_executor { +protected: + gr_block_sptr d_block; // The block we're trying to run + std::ofstream *d_log; + + // These are allocated here so we don't have to on each iteration + + gr_vector_int d_ninput_items_required; + gr_vector_int d_ninput_items; + gr_vector_const_void_star d_input_items; + std::vector d_input_done; + gr_vector_void_star d_output_items; + + public: + gr_block_executor(gr_block_sptr block); + ~gr_block_executor (); + + enum state { + READY, // We made progress; everything's cool. + READY_NO_OUTPUT, // We consumed some input, but produced no output. + 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. + */ + state run_one_iteration(); +}; + +#endif /* INCLUDED_GR_BLOCK_EXECUTOR_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 77f0c7c43..31a471ea7 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -77,10 +77,10 @@ minimum_buffer_items (long type_size, long page_size) } -gr_buffer::gr_buffer (int nitems, size_t sizeof_item) +gr_buffer::gr_buffer (int nitems, size_t sizeof_item, gr_block_sptr link) : d_base (0), d_bufsize (0), d_vmcircbuf (0), - d_sizeof_item (sizeof_item), d_write_index (0), - d_done (false) + d_sizeof_item (sizeof_item), d_link(link), + d_write_index (0), d_done (false) { if (!allocate_buffer (nitems, sizeof_item)) throw std::bad_alloc (); @@ -89,9 +89,9 @@ gr_buffer::gr_buffer (int nitems, size_t sizeof_item) } gr_buffer_sptr -gr_make_buffer (int nitems, size_t sizeof_item) +gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr link) { - return gr_buffer_sptr (new gr_buffer (nitems, sizeof_item)); + return gr_buffer_sptr (new gr_buffer (nitems, sizeof_item, link)); } gr_buffer::~gr_buffer () @@ -146,7 +146,7 @@ gr_buffer::allocate_buffer (int nitems, size_t sizeof_item) int -gr_buffer::space_available () const +gr_buffer::space_available () { if (d_readers.empty ()) return d_bufsize - 1; // See comment below @@ -175,18 +175,27 @@ gr_buffer::write_pointer () void gr_buffer::update_write_pointer (int nitems) { + scoped_lock guard(*mutex()); d_write_index = index_add (d_write_index, nitems); } +void +gr_buffer::set_done (bool done) +{ + scoped_lock guard(*mutex()); + d_done = done; +} + gr_buffer_reader_sptr -gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload) +gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link) { if (nzero_preload < 0) throw std::invalid_argument("gr_buffer_add_reader: nzero_preload must be >= 0"); gr_buffer_reader_sptr r (new gr_buffer_reader (buf, buf->index_sub(buf->d_write_index, - nzero_preload))); + nzero_preload), + link)); buf->d_readers.push_back (r.get ()); return r; @@ -214,8 +223,9 @@ gr_buffer_ncurrently_allocated () // ---------------------------------------------------------------------------- -gr_buffer_reader::gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index) - : d_buffer (buffer), d_read_index (read_index) +gr_buffer_reader::gr_buffer_reader(gr_buffer_sptr buffer, unsigned int read_index, + gr_block_sptr link) + : d_buffer(buffer), d_read_index(read_index), d_link(link) { s_buffer_reader_count++; } @@ -241,6 +251,7 @@ gr_buffer_reader::read_pointer () void gr_buffer_reader::update_read_pointer (int nitems) { + scoped_lock guard(*mutex()); d_read_index = d_buffer->index_add (d_read_index, nitems); } diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index cf578c89d..75063cc6a 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -24,6 +24,8 @@ #define INCLUDED_GR_BUFFER_H #include +#include +#include class gr_vmcircbuf; @@ -33,8 +35,12 @@ class gr_vmcircbuf; * The total size of the buffer will be rounded up to a system * dependent boundary. This is typically the system page size, but * under MS windows is 64KB. + * + * \param nitems is the minimum number of items the buffer will hold. + * \param sizeof_item is the size of an item in bytes. + * \param link is the block that writes to this buffer. */ -gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item); +gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr link=gr_block_sptr()); /*! @@ -43,12 +49,20 @@ gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item); */ class gr_buffer { public: + + typedef boost::unique_lock scoped_lock; + virtual ~gr_buffer (); /*! * \brief return number of items worth of space available for writing */ - int space_available () const; + int space_available (); + + /*! + * \brief return size of this buffer in items + */ + int bufsize() const { return d_bufsize; } /*! * \brief return pointer to write buffer. @@ -63,17 +77,26 @@ class gr_buffer { */ void update_write_pointer (int nitems); - - void set_done (bool done) { d_done = done; } + void set_done (bool done); bool done () const { return d_done; } + /*! + * \brief Return the block that writes to this buffer. + */ + gr_block_sptr link() { return gr_block_sptr(d_link); } + + size_t nreaders() const { return d_readers.size(); } + gr_buffer_reader* reader(size_t index) { return d_readers[index]; } + + boost::mutex *mutex() { return &d_mutex; } + // ------------------------------------------------------------------------- private: friend class gr_buffer_reader; - friend gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item); - friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload); + friend gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr link); + friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link); protected: char *d_base; // base address of buffer @@ -81,8 +104,14 @@ class gr_buffer { private: gr_vmcircbuf *d_vmcircbuf; size_t d_sizeof_item; // in bytes - unsigned int d_write_index; // in items [0,d_bufsize) std::vector d_readers; + boost::weak_ptr d_link; // block that writes to this buffer + + // + // The mutex protects d_write_index, d_done and the d_read_index's in the buffer readers. + // + boost::mutex d_mutex; + unsigned int d_write_index; // in items [0,d_bufsize) bool d_done; unsigned @@ -116,11 +145,15 @@ class gr_buffer { * * Allocate a buffer that holds at least \p nitems of size \p sizeof_item. * + * \param nitems is the minimum number of items the buffer will hold. + * \param sizeof_item is the size of an item in bytes. + * \param link is the block that writes to this buffer. + * * The total size of the buffer will be rounded up to a system * dependent boundary. This is typically the system page size, but * under MS windows is 64KB. */ - gr_buffer (int nitems, size_t sizeof_item); + gr_buffer (int nitems, size_t sizeof_item, gr_block_sptr link); /*! * \brief disassociate \p reader from this buffer @@ -132,8 +165,10 @@ class gr_buffer { /*! * \brief create a new gr_buffer_reader and attach it to buffer \p buf * \param nzero_preload -- number of zero items to "preload" into buffer. + * \param link is the block that reads from the buffer using this gr_buffer_reader. */ -gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload); +gr_buffer_reader_sptr +gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link=gr_block_sptr()); //! returns # of gr_buffers currently allocated long gr_buffer_ncurrently_allocated (); @@ -147,8 +182,10 @@ long gr_buffer_ncurrently_allocated (); */ class gr_buffer_reader { - public: + + typedef gr_buffer::scoped_lock scoped_lock; + ~gr_buffer_reader (); /*! @@ -183,19 +220,29 @@ class gr_buffer_reader { void set_done (bool done) { d_buffer->set_done (done); } bool done () const { return d_buffer->done (); } + boost::mutex *mutex() { return d_buffer->mutex(); } + + + /*! + * \brief Return the block that reads via this reader. + */ + gr_block_sptr link() { return gr_block_sptr(d_link); } + // ------------------------------------------------------------------------- private: friend class gr_buffer; - friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload); + friend gr_buffer_reader_sptr + gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link); gr_buffer_sptr d_buffer; unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) + boost::weak_ptr d_link; // block that reads via this buffer reader //! constructor is private. Use gr_buffer::add_reader to create instances - gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index); + gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index, gr_block_sptr link); }; //! returns # of gr_buffer_readers currently allocated diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.i b/gnuradio-core/src/lib/runtime/gr_buffer.i index 38e1d945d..4c1c5afae 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.i +++ b/gnuradio-core/src/lib/runtime/gr_buffer.i @@ -26,14 +26,14 @@ typedef boost::shared_ptr gr_buffer_sptr; %rename(buffer) gr_make_buffer; %ignore gr_buffer; -gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item); +gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr link); class gr_buffer { public: ~gr_buffer (); private: - gr_buffer (int nitems, size_t sizeof_item); + gr_buffer (int nitems, size_t sizeof_item, gr_block_sptr link); }; @@ -43,7 +43,7 @@ typedef boost::shared_ptr gr_buffer_reader_sptr; %ignore gr_buffer_reader; %rename(buffer_add_reader) gr_buffer_add_reader; -gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload); +gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link); class gr_buffer_reader { public: @@ -51,7 +51,7 @@ class gr_buffer_reader { private: friend class gr_buffer; - gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index); + gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index, gr_block_sptr link); }; diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index aa1aa8353..031eb6dfd 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -33,6 +33,11 @@ #define GR_FLAT_FLOWGRAPH_DEBUG 0 +// 32Kbyte buffer size between blocks +#define GR_FIXED_BUFFER_SIZE (32*(1L<<10)) + +static const unsigned int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE; + gr_flat_flowgraph_sptr gr_make_flat_flowgraph() { @@ -54,7 +59,7 @@ gr_flat_flowgraph::setup_connections() // Assign block details to blocks for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) - make_gr_block_sptr(*p)->set_detail(allocate_block_detail(*p)); + cast_to_block_sptr(*p)->set_detail(allocate_block_detail(*p)); // Connect inputs to outputs for each block for(gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) @@ -84,11 +89,15 @@ gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block) gr_buffer_sptr gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) { - gr_block_sptr grblock = make_gr_block_sptr(block); + gr_block_sptr grblock = cast_to_block_sptr(block); if (!grblock) throw std::runtime_error("allocate_buffer found non-gr_block"); int item_size = block->output_signature()->sizeof_stream_item(port); - int nitems = s_fixed_buffer_size/item_size; + + // *2 because we're now only filling them 1/2 way in order to + // increase the available parallelism when using the TPB scheduler. + // (We're double buffering, where we used to single buffer) + int nitems = s_fixed_buffer_size * 2 / item_size; // Make sure there are at least twice the output_multiple no. of items if (nitems < 2*grblock->output_multiple()) // Note: this means output_multiple() @@ -99,7 +108,7 @@ gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - gr_block_sptr dgrblock = make_gr_block_sptr(*p); + gr_block_sptr dgrblock = cast_to_block_sptr(*p); if (!dgrblock) throw std::runtime_error("allocate_buffer found non-gr_block"); @@ -109,13 +118,13 @@ gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) nitems = std::max(nitems, static_cast(2*(decimation*multiple+history))); } - return gr_make_buffer(nitems, item_size); + return gr_make_buffer(nitems, item_size, grblock); } void gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) { - gr_block_sptr grblock = make_gr_block_sptr(block); + gr_block_sptr grblock = cast_to_block_sptr(block); if (!grblock) throw std::runtime_error("connect_block_inputs found non-gr_block"); @@ -130,7 +139,7 @@ gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) int dst_port = e->dst().port(); int src_port = e->src().port(); gr_basic_block_sptr src_block = e->src().block(); - gr_block_sptr src_grblock = make_gr_block_sptr(src_block); + gr_block_sptr src_grblock = cast_to_block_sptr(src_block); if (!src_grblock) throw std::runtime_error("connect_block_inputs found non-gr_block"); gr_buffer_sptr src_buffer = src_grblock->detail()->output(src_port); @@ -138,7 +147,7 @@ gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Setting input " << dst_port << " from edge " << (*e) << std::endl; - detail->set_input(dst_port, gr_buffer_add_reader(src_buffer, grblock->history()-1)); + detail->set_input(dst_port, gr_buffer_add_reader(src_buffer, grblock->history()-1, grblock)); } } @@ -149,7 +158,7 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) // by flattening will need one; existing blocks still in the new flowgraph will // already have one. for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { - gr_block_sptr block = make_gr_block_sptr(*p); + gr_block_sptr block = cast_to_block_sptr(*p); if (!block->detail()) { if (GR_FLAT_FLOWGRAPH_DEBUG) @@ -177,7 +186,7 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "not in new edge list" << std::endl; // zero the buffer reader on RHS of old edge - gr_block_sptr block(make_gr_block_sptr(old_edge->dst().block())); + gr_block_sptr block(cast_to_block_sptr(old_edge->dst().block())); int port = old_edge->dst().port(); block->detail()->set_input(port, gr_buffer_reader_sptr()); } @@ -189,7 +198,7 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) // Now connect inputs to outputs, reusing old buffer readers if they exist for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { - gr_block_sptr block = make_gr_block_sptr(*p); + gr_block_sptr block = cast_to_block_sptr(*p); if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "merge: merging " << (*p) << "..."; @@ -208,7 +217,7 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) gr_edge edge = calc_upstream_edge(*p, i); // Fish out old buffer reader and see if it matches correct buffer from edge list - gr_block_sptr src_block = make_gr_block_sptr(edge.src().block()); + gr_block_sptr src_block = cast_to_block_sptr(edge.src().block()); gr_block_detail_sptr src_detail = src_block->detail(); gr_buffer_sptr src_buffer = src_detail->output(edge.src().port()); gr_buffer_reader_sptr old_reader; @@ -225,7 +234,7 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) std::cout << "needs a new reader" << std::endl; // Create new buffer reader and assign - detail->set_input(i, gr_buffer_add_reader(src_buffer, block->history()-1)); + detail->set_input(i, gr_buffer_add_reader(src_buffer, block->history()-1, block)); } } } @@ -248,7 +257,7 @@ void gr_flat_flowgraph::dump() for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { std::cout << " block: " << (*p) << std::endl; - gr_block_detail_sptr detail = make_gr_block_sptr(*p)->detail(); + gr_block_detail_sptr detail = cast_to_block_sptr(*p)->detail(); std::cout << " detail @" << detail << ":" << std::endl; int ni = detail->ninputs(); @@ -269,3 +278,14 @@ void gr_flat_flowgraph::dump() } } + +gr_block_vector_t +gr_flat_flowgraph::make_block_vector(gr_basic_block_vector_t &blocks) +{ + gr_block_vector_t result; + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { + result.push_back(cast_to_block_sptr(*p)); + } + + return result; +} diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h index 184ee4514..673c4df16 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h @@ -26,9 +26,6 @@ #include #include -// 32Kbyte buffer size between blocks -#define GR_FIXED_BUFFER_SIZE (32*(1L<<10)) - // Create a shared pointer to a heap allocated gr_flat_flowgraph // (types defined in gr_runtime_types.h) gr_flat_flowgraph_sptr gr_make_flat_flowgraph(); @@ -55,10 +52,14 @@ public: void dump(); + /*! + * Make a vector of gr_block from a vector of gr_basic_block + */ + static gr_block_vector_t make_block_vector(gr_basic_block_vector_t &blocks); + private: gr_flat_flowgraph(); - static const unsigned int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE; gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block); gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port); void connect_block_inputs(gr_basic_block_sptr block); diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flowgraph.h index c97a50782..fc407e72b 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.h @@ -122,6 +122,9 @@ public: // 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 partition(); @@ -149,7 +152,6 @@ private: 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); diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 32cac2ea8..a026851d2 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -303,7 +303,7 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) std::stringstream msg; // Check if endpoint is a leaf node - if (make_gr_block_sptr(endp.block())) + if (cast_to_block_sptr(endp.block())) return endp; // Check if endpoint is a hierarchical block diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_scheduler.cc new file mode 100644 index 000000000..e4d8b3dd9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_scheduler.cc @@ -0,0 +1,33 @@ +/* -*- 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 +#endif +#include + +gr_scheduler::gr_scheduler(gr_flat_flowgraph_sptr ffg) +{ +} + +gr_scheduler::~gr_scheduler() +{ +} diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler.h b/gnuradio-core/src/lib/runtime/gr_scheduler.h new file mode 100644 index 000000000..13bc1ff14 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_scheduler.h @@ -0,0 +1,64 @@ +/* -*- 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_H +#define INCLUDED_GR_SCHEDULER_H + +#include +#include +#include + + +class gr_scheduler; +typedef boost::shared_ptr gr_scheduler_sptr; + + +/*! + * \brief Abstract scheduler that takes a flattened flow graph and runs it. + * + * Preconditions: details, buffers and buffer readers have been assigned. + */ +class gr_scheduler : boost::noncopyable +{ + +public: + /*! + * \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(gr_flat_flowgraph_sptr ffg); + + virtual ~gr_scheduler(); + + /*! + * \brief Tell the scheduler to stop executing. + */ + virtual void stop() = 0; + + /*! + * \brief Block until the graph is done. + */ + virtual void wait() = 0; +}; + +#endif /* INCLUDED_GR_SCHEDULER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc new file mode 100644 index 000000000..fefc0dc70 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc @@ -0,0 +1,87 @@ +/* -*- 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 +#endif +#include +#include +#include + +class sts_container +{ + gr_block_vector_t d_blocks; + +public: + + sts_container(gr_block_vector_t blocks) + : d_blocks(blocks) {} + + void operator()() + { + gr_make_single_threaded_scheduler(d_blocks)->run(); + } +}; + + +gr_scheduler_sptr +gr_scheduler_sts::make(gr_flat_flowgraph_sptr ffg) +{ + return gr_scheduler_sptr(new gr_scheduler_sts(ffg)); +} + +gr_scheduler_sts::gr_scheduler_sts(gr_flat_flowgraph_sptr ffg) + : gr_scheduler(ffg) +{ + // Split the flattened flow graph into discrete partitions, each + // of which is topologically sorted. + + std::vector graphs = ffg->partition(); + + // For each partition, create a thread to evaluate it using + // an instance of the gr_single_threaded_scheduler + + for (std::vector::iterator p = graphs.begin(); + p != graphs.end(); p++) { + + gr_block_vector_t blocks = gr_flat_flowgraph::make_block_vector(*p); + d_threads.create_thread( + gruel::thread_body_wrapper(sts_container(blocks), + "single-threaded-scheduler")); + } +} + +gr_scheduler_sts::~gr_scheduler_sts() +{ + stop(); +} + +void +gr_scheduler_sts::stop() +{ + d_threads.interrupt_all(); +} + +void +gr_scheduler_sts::wait() +{ + d_threads.join_all(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h new file mode 100644 index 000000000..4cf835156 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h @@ -0,0 +1,62 @@ +/* -*- 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_STS_H +#define INCLUDED_GR_SCHEDULER_STS_H + +#include +#include + +/*! + * \brief Concrete scheduler that uses the single_threaded_scheduler + */ +class gr_scheduler_sts : public gr_scheduler +{ + gruel::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_sts(gr_flat_flowgraph_sptr ffg); + +public: + static gr_scheduler_sptr make(gr_flat_flowgraph_sptr ffg); + + ~gr_scheduler_sts(); + + /*! + * \brief Tell the scheduler to stop executing. + */ + void stop(); + + /*! + * \brief Block until the graph is done. + */ + void wait(); +}; + + + + +#endif /* INCLUDED_GR_SCHEDULER_STS_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc deleted file mode 100644 index 07bd60500..000000000 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifdef HAVE_SIGNAL_H -#include -#endif - -#define GR_SCHEDULER_THREAD_DEBUG 0 - -gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) : - omni_thread(NULL, PRIORITY_NORMAL), - d_sts(gr_make_single_threaded_scheduler(graph)) -{ -} - -gr_scheduler_thread::~gr_scheduler_thread() -{ -} - -void gr_scheduler_thread::start() -{ - if (GR_SCHEDULER_THREAD_DEBUG) - std::cout << "gr_scheduler_thread::start() " - << this << std::endl; - start_undetached(); -} - -void * -gr_scheduler_thread::run_undetached(void *arg) -{ - // This is the first code to run in the new thread context. - - /* - * In general, on a *nix system, any thread of a process can receive - * any asynchronous signal. - * - * http://www.serpentine.com/blog/threads-faq/mixing-threads-and-signals-unix/ - * http://www.linuxjournal.com/article/2121 - * - * We really don't want to be handling asynchronous signals such - * as SIGINT and SIGHUP here. We mask them off in the signal - * processing threads so that they'll get handled by the mainline - * thread. We leave the synchronous signals SIGQUIT, SIGBUS, - * SIGILL, SIGSEGV etc alone - * - * FIXME? It might be better to mask them all off in the parent - * thread then dedicate a single thread to handling all signals - * using sigwait. - */ -#if defined(HAVE_PTHREAD_SIGMASK) || defined(HAVE_SIGPROCMASK) - sigset_t old_set; - sigset_t new_set; - int r; - sigemptyset(&new_set); - sigaddset(&new_set, SIGINT); - sigaddset(&new_set, SIGHUP); - sigaddset(&new_set, SIGPIPE); - sigaddset(&new_set, SIGALRM); - sigaddset(&new_set, SIGCHLD); - -#ifdef HAVE_PTHREAD_SIGMASK - r = pthread_sigmask(SIG_BLOCK, &new_set, &old_set); - if (r != 0) - perror("pthread_sigmask"); -#else - r = sigprocmask(SIG_BLOCK, &new_set, &old_set); - if (r != 0) - perror("sigprocmask"); -#endif -#endif - // Run the single-threaded scheduler - d_sts->run(); - return 0; -} - -void -gr_scheduler_thread::stop() -{ - if (0 && GR_SCHEDULER_THREAD_DEBUG) // FIXME not safe to call from signal handler - std::cout << "gr_scheduler_thread::stop() " - << this << std::endl; - d_sts->stop(); -} diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h b/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h deleted file mode 100644 index 89daba403..000000000 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_SCHEDULER_THREAD_H -#define INCLUDED_GR_SCHEDULER_THREAD_H - -#include -#include -#include - -// omnithread calls delete on itself after thread exits, so can't use shared ptr -class gr_scheduler_thread; -typedef std::vector gr_scheduler_thread_vector_t; -typedef gr_scheduler_thread_vector_t::iterator gr_scheduler_thread_viter_t; - -/*! - *\brief A single thread of execution for the scheduler - * - * \ingroup internal - * This class implements a single thread that runs undetached, and - * invokes the single-threaded block scheduler. The runtime makes - * one of these for each distinct partition of a flowgraph and runs - * them in parallel. - * - */ -class gr_scheduler_thread : public omni_thread -{ -private: - gr_single_threaded_scheduler_sptr d_sts; - -public: - gr_scheduler_thread(gr_block_vector_t graph); - ~gr_scheduler_thread(); - - virtual void *run_undetached(void *arg); - void start(); - void stop(); -}; - -#endif /* INCLUDED_GR_SCHEDULER_THREAD_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc new file mode 100644 index 000000000..af0338570 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc @@ -0,0 +1,95 @@ +/* -*- 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 +#endif +#include +#include +#include +#include + +/* + * 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); + + // Ensure that the done flag is clear on all blocks + + for (size_t i = 0; i < blocks.size(); i++){ + blocks[i]->detail()->set_done(false); + } + + // 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(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(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h new file mode 100644 index 000000000..16a0c0204 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h @@ -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 +#include + +/*! + * \brief Concrete scheduler that uses a kernel thread-per-block + */ +class gr_scheduler_tpb : public gr_scheduler +{ + gruel::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 */ diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc index b2fbdb73b..7f1b40641 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -44,14 +45,6 @@ static int which_scheduler = 0; - -std::ostream& -operator << (std::ostream& os, const gr_block *m) -{ - os << "name() << " (" << m->unique_id() << ")>"; - return os; -} - gr_single_threaded_scheduler_sptr gr_make_single_threaded_scheduler (const std::vector &blocks) { @@ -162,6 +155,9 @@ gr_single_threaded_scheduler::main_loop () nalive = d_blocks.size (); while (d_enabled && nalive > 0){ + if (boost::this_thread::interruption_requested()) + break; + gr_block *m = d_blocks[bi].get (); gr_block_detail *d = m->detail().get (); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 3c8e28f70..09e46dfbb 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -43,7 +42,7 @@ gr_top_block::gr_top_block(const std::string &name) gr_make_io_signature(0,0,0)) { - d_impl = new gr_top_block_impl_sts(this); + d_impl = new gr_top_block_impl(this); } gr_top_block::~gr_top_block() diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 591437938..50d480d00 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -27,21 +27,58 @@ #include #include #include -#include -#include +#include +#include #include #include #include #include +#include #define GR_TOP_BLOCK_IMPL_DEBUG 0 + +typedef gr_scheduler_sptr (*scheduler_maker)(gr_flat_flowgraph_sptr ffg); + +static struct scheduler_table { + const char *name; + scheduler_maker f; +} scheduler_table[] = { + { "TPB", gr_scheduler_tpb::make }, // first entry is default + { "STS", gr_scheduler_sts::make } +}; + +static gr_scheduler_sptr +make_scheduler(gr_flat_flowgraph_sptr ffg) +{ + static scheduler_maker factory = 0; + + if (factory == 0){ + char *v = getenv("GR_SCHEDULER"); + if (!v) + factory = scheduler_table[0].f; // use default + else { + for (size_t i = 0; i < sizeof(scheduler_table)/sizeof(scheduler_table[0]); i++){ + if (strcmp(v, scheduler_table[i].name) == 0){ + factory = scheduler_table[i].f; + break; + } + } + if (factory == 0){ + std::cerr << "warning: Invalid GR_SCHEDULER environment variable value \"" + << v << "\". Using \"" << scheduler_table[0].name << "\"\n"; + factory = scheduler_table[0].f; + } + } + } + return factory(ffg); +} + + gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) - : d_owner(owner), - d_running(false), - d_ffg(), - d_lock_count(0) + : d_owner(owner), d_ffg(), + d_state(IDLE), d_lock_count(0) { } @@ -53,14 +90,13 @@ gr_top_block_impl::~gr_top_block_impl() void gr_top_block_impl::start() { - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "start: entered " << this << std::endl; + gr_lock_guard l(d_mutex); - if (d_running) + if (d_state != IDLE) throw std::runtime_error("top_block::start: top block already running or wait() not called after previous stop()"); if (d_lock_count > 0) - throw std::runtime_error("top_block::start: can't call start with flow graph locked"); + throw std::runtime_error("top_block::start: can't start with flow graph locked"); // Create new flat flow graph by flattening hierarchy d_ffg = d_owner->flatten(); @@ -69,77 +105,71 @@ gr_top_block_impl::start() d_ffg->validate(); d_ffg->setup_connections(); - // Execute scheduler threads - start_threads(); - d_running = true; + d_scheduler = make_scheduler(d_ffg); + d_state = RUNNING; } +void +gr_top_block_impl::stop() +{ + if (d_scheduler) + d_scheduler->stop(); +} + + +void +gr_top_block_impl::wait() +{ + if (d_scheduler) + d_scheduler->wait(); + + d_state = IDLE; +} // N.B. lock() and unlock() cannot be called from a flow graph thread or // deadlock will occur when reconfiguration happens void gr_top_block_impl::lock() { - omni_mutex_lock lock(d_reconf); + gr_lock_guard lock(d_mutex); d_lock_count++; - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "runtime: locked, count = " << d_lock_count << std::endl; } void gr_top_block_impl::unlock() { - omni_mutex_lock lock(d_reconf); + gr_lock_guard lock(d_mutex); + if (d_lock_count <= 0){ d_lock_count = 0; // fix it, then complain throw std::runtime_error("unpaired unlock() call"); } d_lock_count--; - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "unlock: unlocked, count = " << d_lock_count << std::endl; + if (d_lock_count > 0 || d_state == IDLE) // nothing to do + return; - if (d_lock_count == 0) { - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "unlock: restarting flowgraph" << std::endl; - restart(); - } + restart(); } +/* + * restart is called with d_mutex held + */ void gr_top_block_impl::restart() { - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "restart: entered" << std::endl; - - if (!d_running) - return; // nothing to do - - // Stop scheduler threads and wait for completion - stop(); + stop(); // Stop scheduler and wait for completion wait(); - if (GR_TOP_BLOCK_IMPL_DEBUG) - std::cout << "restart: threads stopped" << std::endl; // Create new simple flow graph gr_flat_flowgraph_sptr new_ffg = d_owner->flatten(); new_ffg->validate(); // check consistency, sanity, etc - - if (GR_TOP_BLOCK_IMPL_DEBUG) { - std::cout << std::endl << "*** Existing flat flowgraph @" << d_ffg << ":" << std::endl; - d_ffg->dump(); - } new_ffg->merge_connections(d_ffg); // reuse buffers, etc - - if (GR_TOP_BLOCK_IMPL_DEBUG) { - std::cout << std::endl << "*** New flat flowgraph after merge @" << new_ffg << ":" << std::endl; - new_ffg->dump(); - } - d_ffg = new_ffg; - start_threads(); - d_running = true; + // Create a new scheduler to execute it + d_scheduler = make_scheduler(d_ffg); + d_state = RUNNING; } void @@ -148,14 +178,3 @@ gr_top_block_impl::dump() if (d_ffg) d_ffg->dump(); } - -gr_block_vector_t -gr_top_block_impl::make_gr_block_vector(gr_basic_block_vector_t blocks) -{ - gr_block_vector_t result; - for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { - result.push_back(make_gr_block_sptr(*p)); - } - - return result; -} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 869f788ef..35fb44ef9 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -23,7 +23,11 @@ #ifndef INCLUDED_GR_TOP_BLOCK_IMPL_H #define INCLUDED_GR_TOP_BLOCK_IMPL_H -#include +#include +#include + +typedef boost::mutex gr_mutex; // FIXME move these elsewhere +typedef boost::lock_guard gr_lock_guard; /*! *\brief Abstract implementation details of gr_top_block @@ -37,16 +41,16 @@ class gr_top_block_impl { public: gr_top_block_impl(gr_top_block *owner); - virtual ~gr_top_block_impl(); + ~gr_top_block_impl(); // Create and start scheduler threads - virtual void start(); + void start(); // Signal scheduler threads to stop - virtual void stop() = 0; + void stop(); // Wait for scheduler threads to exit - virtual void wait() = 0; + void wait(); // Lock the top block to allow reconfiguration void lock(); @@ -59,22 +63,16 @@ public: protected: + enum tb_state { IDLE, RUNNING }; + gr_top_block *d_owner; - bool d_running; gr_flat_flowgraph_sptr d_ffg; + gr_scheduler_sptr d_scheduler; - omni_mutex d_reconf; // protects d_lock_count + gr_mutex d_mutex; // protects d_state and d_lock_count + tb_state d_state; int d_lock_count; - - virtual void start_threads() = 0; - -/*! - * Make a vector of gr_block from a vector of gr_basic_block - * - * Pass-by-value to avoid problem with possible asynchronous modification - */ - static gr_block_vector_t make_gr_block_vector(gr_basic_block_vector_t blocks); - + private: void restart(); }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc deleted file mode 100644 index b3e9da627..000000000 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define GR_TOP_BLOCK_IMPL_STS_DEBUG 0 - -static gr_top_block_impl *s_impl = 0; - - -// FIXME: This prevents using more than one gr_top_block instance - -static void -runtime_sigint_handler(int signum) -{ - if (GR_TOP_BLOCK_IMPL_STS_DEBUG){ - char *msg = "SIGINT received, calling stop()\n"; - ::write(1, msg, strlen(msg)); // write is OK to call from signal handler - } - - if (s_impl) - s_impl->stop(); -} - -// ---------------------------------------------------------------- - -gr_top_block_impl_sts::gr_top_block_impl_sts(gr_top_block *owner) - : gr_top_block_impl(owner) -{ - if (s_impl) - throw std::logic_error("gr_top_block_impl_sts: multiple simultaneous gr_top_blocks not allowed"); - - s_impl = this; -} - -gr_top_block_impl_sts::~gr_top_block_impl_sts() -{ - s_impl = 0; // don't call delete we don't own these -} - -void -gr_top_block_impl_sts::start_threads() -{ - if (GR_TOP_BLOCK_IMPL_STS_DEBUG) - std::cout << "start_threads: entered" << std::endl; - - d_graphs = d_ffg->partition(); - for (std::vector::iterator p = d_graphs.begin(); - p != d_graphs.end(); p++) { - gr_scheduler_thread *thread = new gr_scheduler_thread(make_gr_block_vector(*p)); - d_threads.push_back(thread); - if (GR_TOP_BLOCK_IMPL_STS_DEBUG) - std::cout << "start_threads: starting " << thread << std::endl; - thread->start(); - } -} - -/* - * N.B. as currently implemented, it is possible that this may be - * invoked by the SIGINT handler which is fragile as hell... - */ -void -gr_top_block_impl_sts::stop() -{ - if (GR_TOP_BLOCK_IMPL_STS_DEBUG){ - char *msg = "stop: entered\n"; - ::write(1, msg, strlen(msg)); - } - - for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { - if (*p) - (*p)->stop(); - } -} - -void -gr_top_block_impl_sts::wait() -{ - if (GR_TOP_BLOCK_IMPL_STS_DEBUG) - std::cout << "wait: entered" << std::endl; - - void *dummy_status; // don't ever dereference this - gr_local_sighandler sigint(SIGINT, runtime_sigint_handler); - - for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != d_threads.end(); p++) { - if (GR_TOP_BLOCK_IMPL_STS_DEBUG) - std::cout << "wait: joining thread " << (*p) << std::endl; - (*p)->join(&dummy_status); // omnithreads will self-delete, so pointer is now dead - (*p) = 0; // FIXME: switch to stl::list and actually remove from container - if (GR_TOP_BLOCK_IMPL_STS_DEBUG) - std::cout << "wait: join returned" << std::endl; - } - - d_threads.clear(); - d_running = false; -} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.h deleted file mode 100644 index ec2e51cf2..000000000 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_TOP_BLOCK_IMPL_STS_H -#define INCLUDED_GR_TOP_BLOCK_IMPL_STS_H - -#include -#include - -/*! - *\brief Implementation details of gr_top_block - * \ingroup internal - * - * Concrete implementation of gr_top_block using gr_single_threaded_scheduler. - */ -class gr_top_block_impl_sts : public gr_top_block_impl -{ -public: - gr_top_block_impl_sts(gr_top_block *owner); - ~gr_top_block_impl_sts(); - - // Signal scheduler threads to stop - void stop(); - - // Wait for scheduler threads to exit - void wait(); - -private: - - gr_scheduler_thread_vector_t d_threads; - std::vector d_graphs; - - void start_threads(); -}; - -#endif /* INCLUDED_GR_TOP_BLOCK_IMPL_STS_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc b/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc new file mode 100644 index 000000000..02e8deed8 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc @@ -0,0 +1,67 @@ +/* -*- 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 +#endif +#include +#include +#include +#include + +/* + * 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++){ + // Can you say, "pointer chasing?" + d->d_input[i]->buffer()->link()->detail()->d_tpb.set_output_changed(); + } +} + +void +gr_tpb_detail::notify_downstream(gr_block_detail *d) +{ + // For each of our outputs, tell the guys downstream that they have + // new input available. + + for (size_t i = 0; i < d->d_output.size(); i++){ + gr_buffer_sptr buf = d->d_output[i]; + for (size_t j = 0, k = buf->nreaders(); j < k; j++) + buf->reader(j)->link()->detail()->d_tpb.set_input_changed(); + } +} + +void +gr_tpb_detail::notify_neighbors(gr_block_detail *d) +{ + notify_downstream(d); + notify_upstream(d); +} diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h new file mode 100644 index 000000000..9566312dc --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h @@ -0,0 +1,81 @@ +/* -*- 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 + +class gr_block_detail; + +/*! + * \brief used by thread-per-block scheduler + */ +struct gr_tpb_detail { + typedef boost::unique_lock 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 to notify both upstream and downstream + void notify_neighbors(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 */ diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc new file mode 100644 index 000000000..f61e17243 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -0,0 +1,76 @@ +/* -*- 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 +#endif +#include +#include + +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_neighbors(d); + break; + + case gr_block_executor::READY_NO_OUTPUT: // Notify upstream only + d->d_tpb.notify_upstream(d); + break; + + case gr_block_executor::DONE: // Game over. + d->d_tpb.notify_neighbors(d); + 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() +{ +} diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h new file mode 100644 index 000000000..a630b1be9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h @@ -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 +#include +#include + +/*! + * \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 */ diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc index ad40f724d..7434cf657 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc @@ -52,7 +52,7 @@ t0_body () int nitems = 4000 / sizeof (int); int counter = 0; - gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); + gr_buffer_sptr buf(gr_make_buffer(nitems, sizeof (int), gr_block_sptr())); int last_sa; int sa; @@ -87,8 +87,8 @@ t1_body () int write_counter = 0; int read_counter = 0; - gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); - gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 0)); + gr_buffer_sptr buf(gr_make_buffer(nitems, sizeof (int), gr_block_sptr())); + gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 0, gr_block_sptr())); int sa; @@ -162,8 +162,8 @@ t2_body () int nitems = (64 * (1L << 10)) / sizeof (int); // 64K worth of ints - gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); - gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 0)); + gr_buffer_sptr buf(gr_make_buffer (nitems, sizeof (int), gr_block_sptr())); + gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 0, gr_block_sptr())); int read_counter = 0; int write_counter = 0; @@ -229,7 +229,7 @@ t3_body () int nitems = (64 * (1L << 10)) / sizeof (int); static const int N = 5; - gr_buffer_sptr buf (gr_make_buffer (nitems, sizeof (int))); + gr_buffer_sptr buf(gr_make_buffer(nitems, sizeof (int), gr_block_sptr())); gr_buffer_reader_sptr reader[N]; int read_counter[N]; int write_counter = 0; @@ -237,7 +237,7 @@ t3_body () for (int i = 0; i < N; i++){ read_counter[i] = 0; - reader[i] = gr_buffer_add_reader (buf, 0); + reader[i] = gr_buffer_add_reader (buf, 0, gr_block_sptr()); } for (int lc = 0; lc < 1000; lc++){ -- cgit From 8c2e26d9f7ef82fe5ae54a8e2b7744dedd746c2b Mon Sep 17 00:00:00 2001 From: eb Date: Sat, 20 Sep 2008 00:16:41 +0000 Subject: gr_realtime now uses gruel::enable_realtime_scheduling git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9610 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_realtime.cc | 71 +--------------------------- gnuradio-core/src/lib/runtime/gr_realtime.h | 12 ++--- 2 files changed, 6 insertions(+), 77 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.cc b/gnuradio-core/src/lib/runtime/gr_realtime.cc index d3cda0eaa..b44c4d408 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_realtime.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2007 Free Software Foundation, Inc. + * Copyright 2006,2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,75 +25,8 @@ #endif #include -#ifdef HAVE_SCHED_H -#include -#endif - -#include -#include -#include - -#if defined(HAVE_SCHED_SETSCHEDULER) - gr_rt_status_t gr_enable_realtime_scheduling() { - int policy = SCHED_FIFO; - int pri = (sched_get_priority_max (policy) + sched_get_priority_min (policy)) / 2; - int pid = 0; // this process - - struct sched_param param; - memset(¶m, 0, sizeof(param)); - param.sched_priority = pri; - int result = sched_setscheduler(pid, policy, ¶m); - if (result != 0){ - if (errno == EPERM) - return RT_NO_PRIVS; - else { - perror ("sched_setscheduler: failed to set real time priority"); - return RT_OTHER_ERROR; - } - } - //printf("SCHED_FIFO enabled with priority = %d\n", pri); - return RT_OK; + return gruel::enable_realtime_scheduling(); } - -#elif defined(HAVE_PTHREAD_SETSCHEDPARAM) - -#include -#include - -gr_rt_status_t -gr_enable_realtime_scheduling() -{ - int policy = SCHED_FIFO; - int pri = (sched_get_priority_max (policy) + - sched_get_priority_min (policy)) / 2; - pthread_t this_thread = pthread_self (); // this process - struct sched_param param; - memset (¶m, 0, sizeof (param)); - param.sched_priority = pri; - int result = pthread_setschedparam (this_thread, policy, ¶m); - if (result != 0) { - if (errno == EPERM) - return RT_NO_PRIVS; - else { - perror ("pthread_setschedparam: failed to set real time priority"); - return RT_OTHER_ERROR; - } - } - //printf("SCHED_FIFO enabled with priority = %d\n", pri); - return RT_OK; -} - -// #elif // could try negative niceness - -#else - -gr_rt_status_t -gr_enable_realtime_scheduling() -{ - return RT_NOT_IMPLEMENTED; -} - -#endif diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.h b/gnuradio-core/src/lib/runtime/gr_realtime.h index cf0423aaa..830c201d7 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.h +++ b/gnuradio-core/src/lib/runtime/gr_realtime.h @@ -23,18 +23,14 @@ #ifndef INCLUDED_GR_REALTIME_H #define INCLUDED_GR_REALTIME_H -typedef enum { - RT_OK = 0, - RT_NOT_IMPLEMENTED, - RT_NO_PRIVS, - RT_OTHER_ERROR -} gr_rt_status_t; +#include + +typedef gruel::rt_status_t gr_rt_status_t; /*! * \brief If possible, enable high-priority "real time" scheduling. * \ingroup misc */ -gr_rt_status_t -gr_enable_realtime_scheduling(); +gr_rt_status_t gr_enable_realtime_scheduling(); #endif /* INCLUDED_GR_REALTIME_H */ -- cgit From d6f1a54c745709543a28a66dcb9631c3dad39171 Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 24 Sep 2008 15:55:29 +0000 Subject: Applied patch from Stefan Brüns. It fixes a swig problem with enable_realtime_scheduling. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9652 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_realtime.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.i b/gnuradio-core/src/lib/runtime/gr_realtime.i index cb43e0514..e111f1341 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.i +++ b/gnuradio-core/src/lib/runtime/gr_realtime.i @@ -1,4 +1,4 @@ -%rename(enable_realtime_scheduling) gr_enable_realtime_scheduling; +%rename(enable_realtime_scheduling) gruel::enable_realtime_scheduling; -%include +%include -- cgit From 9c396d3353075919ae76b6f146ed6485b56880c6 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 3 Nov 2008 20:35:04 +0000 Subject: Fix issue caused by pkg-config stripping -I/usr/include from --cflags git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9920 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_realtime.i | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.i b/gnuradio-core/src/lib/runtime/gr_realtime.i index e111f1341..8f39625b4 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.i +++ b/gnuradio-core/src/lib/runtime/gr_realtime.i @@ -1,4 +1,33 @@ +/* -*- 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + %rename(enable_realtime_scheduling) gruel::enable_realtime_scheduling; -%include +// NOTE: This is duplicated from gruel/src/include/gruel/gr_realtime.h, +// and must be kept in sync with it. This is the least evil workaround +// for allowing 3rd party code builds to work when GNU Radio is +// installed from binary packages into the standard system directories. +// Otherwise, they can't find #include , since +// pkg-config strips -I/usr/include from the --cflags path. +typedef gruel::rt_status_t gr_rt_status_t; +gr_rt_status_t gr_enable_realtime_scheduling(); -- cgit From eed0956a285e6aaf062a5c6f69e17bccd8ef8a20 Mon Sep 17 00:00:00 2001 From: eb Date: Mon, 10 Nov 2008 20:19:39 +0000 Subject: wrap the return type from gr_enable_realtime_scheduling git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9969 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_realtime.i | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.i b/gnuradio-core/src/lib/runtime/gr_realtime.i index 8f39625b4..be7f12bf0 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.i +++ b/gnuradio-core/src/lib/runtime/gr_realtime.i @@ -20,7 +20,7 @@ * Boston, MA 02110-1301, USA. */ -%rename(enable_realtime_scheduling) gruel::enable_realtime_scheduling; +%rename(enable_realtime_scheduling) gr_enable_realtime_scheduling; // NOTE: This is duplicated from gruel/src/include/gruel/gr_realtime.h, // and must be kept in sync with it. This is the least evil workaround @@ -29,5 +29,16 @@ // Otherwise, they can't find #include , since // pkg-config strips -I/usr/include from the --cflags path. +namespace gruel { + + typedef enum { + RT_OK = 0, + RT_NOT_IMPLEMENTED, + RT_NO_PRIVS, + RT_OTHER_ERROR + } rt_status_t; + +} + typedef gruel::rt_status_t gr_rt_status_t; gr_rt_status_t gr_enable_realtime_scheduling(); -- cgit From bebf5a4a72d205a1a05c7dc70d9bef240cfc477f Mon Sep 17 00:00:00 2001 From: michaelld Date: Sat, 31 Jan 2009 02:48:58 +0000 Subject: Merged in misc_fixes branch. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10350 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 6 +++--- gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 68dbfd645..254a7a940 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -39,7 +39,7 @@ class gr_msg_queue : public gr_msg_handler { int d_count; public: - gr_msg_queue(); + gr_msg_queue(unsigned int limit); ~gr_msg_queue(); //! Generic msg_handler method: insert the message. @@ -87,7 +87,7 @@ public: * functions into the gr.msg_queue wrapper class, so that everything * appears normal. (An evil laugh is heard in the distance...) */ -%inline { +%inline %{ gr_message_sptr gr_py_msg_queue__delete_head(gr_msg_queue_sptr q) { gr_message_sptr msg; Py_BEGIN_ALLOW_THREADS; // release global interpreter lock @@ -101,7 +101,7 @@ public: q->insert_tail(msg); // possibly blocking call Py_END_ALLOW_THREADS; // acquire global interpreter lock } -} +%} // smash in new python delete_head and insert_tail methods... %pythoncode %{ diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i index fb2ff0d7f..5e9032449 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i @@ -42,11 +42,10 @@ class gr_single_threaded_scheduler { gr_single_threaded_scheduler (const std::vector &modules); }; -%inline { +%inline %{ void sts_pyrun (gr_single_threaded_scheduler_sptr s) { Py_BEGIN_ALLOW_THREADS; // release global interpreter lock s->run (); Py_END_ALLOW_THREADS; // acquire global interpreter lock } -} - +%} -- cgit From 7783dc88c6acf839b59c7c3358094f85e0012ada Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 10 Feb 2009 04:53:37 +0000 Subject: Merged r10385:10413 from michaelld/swig_tweaks into trunk. Passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10414 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 3 +- .../src/lib/runtime/gr_swig_block_magic.i | 45 ---------------------- 2 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 gnuradio-core/src/lib/runtime/gr_swig_block_magic.i (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index b21b32412..cc8da49de 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2003,2004,2007,2008 Free Software Foundation, Inc. +# Copyright 2003,2004,2007,2008,2009 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -152,7 +152,6 @@ swiginclude_HEADERS = \ gr_sync_block.i \ gr_sync_decimator.i \ gr_sync_interpolator.i \ - gr_swig_block_magic.i \ gr_top_block.i \ runtime.i diff --git a/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i b/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i deleted file mode 100644 index 083d60689..000000000 --- a/gnuradio-core/src/lib/runtime/gr_swig_block_magic.i +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -%define GR_SWIG_BLOCK_MAGIC(PKG, BASE_NAME) -_GR_SWIG_BLOCK_MAGIC_HELPER(PKG, PKG ## _ ## BASE_NAME, BASE_NAME) -%enddef - -%define _GR_SWIG_BLOCK_MAGIC_HELPER(PKG, NAME, BASE_NAME) -class NAME; -typedef boost::shared_ptr NAME ## _sptr; -%template(NAME ## _sptr) boost::shared_ptr; -%rename(BASE_NAME) PKG ## _make_ ## BASE_NAME; -%inline { - gr_block_sptr NAME ## _block (NAME ## _sptr r) - { - return gr_block_sptr (r); - } -} - -%pythoncode %{ -NAME ## _sptr.block = lambda self: NAME ## _block (self) -NAME ## _sptr.__repr__ = lambda self: "" % (self.name(), self.unique_id ()) -%} - -%ignore NAME; -%enddef -- cgit From 1fd57936765fd19c51842ce2bfec41abb9146eaf Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 17 Feb 2009 16:57:00 +0000 Subject: Added ability to determine if flowgraph is running git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10451 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_top_block.cc | 6 ++++++ gnuradio-core/src/lib/runtime/gr_top_block.h | 5 +++++ gnuradio-core/src/lib/runtime/gr_top_block.i | 1 + gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 6 ++++++ gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 3 +++ 5 files changed, 21 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 09e46dfbb..3fa324257 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -78,6 +78,12 @@ gr_top_block::run() wait(); } +bool +gr_top_block::is_running() +{ + return d_impl->is_running(); +} + void gr_top_block::lock() { diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index b47ec019c..415bb21f2 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -77,6 +77,11 @@ public: */ void wait(); + /*! + * Is the flowgraph running? + */ + bool is_running(); + /*! * Lock a flowgraph in preparation for reconfiguration. When an equal * number of calls to lock() and unlock() have occurred, the flowgraph diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 670e5b5e5..b5ced3cda 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -44,6 +44,7 @@ public: void stop(); void wait(); void run(); + bool is_running(); void lock(); void unlock() throw (std::runtime_error); void dump(); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 50d480d00..97b19adad 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -87,6 +87,12 @@ gr_top_block_impl::~gr_top_block_impl() d_owner = 0; } +bool +gr_top_block_impl::is_running() +{ + return (d_state != IDLE); +} + void gr_top_block_impl::start() { diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 35fb44ef9..794c4bc0d 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -60,6 +60,9 @@ public: // Dump the flowgraph to stdout void dump(); + + // Has flowgraph been started? + bool is_running(); protected: -- cgit From 002e7a2b4a8630599849ee2bb488cf62ffbd8757 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 23 Feb 2009 02:14:39 +0000 Subject: Reverted changeset r10451. Instead we will ensure top_block.stop() and wait() can be called on a stopped flowgraph with no ill effects. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10478 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_top_block.cc | 6 ------ gnuradio-core/src/lib/runtime/gr_top_block.h | 5 ----- gnuradio-core/src/lib/runtime/gr_top_block.i | 1 - gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 6 ------ gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 3 --- 5 files changed, 21 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 3fa324257..09e46dfbb 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -78,12 +78,6 @@ gr_top_block::run() wait(); } -bool -gr_top_block::is_running() -{ - return d_impl->is_running(); -} - void gr_top_block::lock() { diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 415bb21f2..b47ec019c 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -77,11 +77,6 @@ public: */ void wait(); - /*! - * Is the flowgraph running? - */ - bool is_running(); - /*! * Lock a flowgraph in preparation for reconfiguration. When an equal * number of calls to lock() and unlock() have occurred, the flowgraph diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index b5ced3cda..670e5b5e5 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -44,7 +44,6 @@ public: void stop(); void wait(); void run(); - bool is_running(); void lock(); void unlock() throw (std::runtime_error); void dump(); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 97b19adad..50d480d00 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -87,12 +87,6 @@ gr_top_block_impl::~gr_top_block_impl() d_owner = 0; } -bool -gr_top_block_impl::is_running() -{ - return (d_state != IDLE); -} - void gr_top_block_impl::start() { diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 794c4bc0d..35fb44ef9 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -60,9 +60,6 @@ public: // Dump the flowgraph to stdout void dump(); - - // Has flowgraph been started? - bool is_running(); protected: -- cgit From c48f42b58c67eefd19ea1a803329bcf62eac06e9 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Wed, 25 Feb 2009 19:04:35 +0000 Subject: Merged r10501:10505 from michaelld/omnithread into trunk. Moves omnithread header files into /gnuradio. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10506 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_msg_queue.h | 2 +- gnuradio-core/src/lib/runtime/gr_sptr_magic.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.h b/gnuradio-core/src/lib/runtime/gr_msg_queue.h index 38556b3ca..f965887e1 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.h @@ -23,7 +23,7 @@ #define INCLUDED_GR_MSG_QUEUE_H #include -#include +#include class gr_msg_queue; typedef boost::shared_ptr gr_msg_queue_sptr; diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc index dc0b232a7..3295f849e 100644 --- a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc @@ -32,7 +32,7 @@ typedef boost::mutex mutex; typedef boost::mutex::scoped_lock scoped_lock; #else - #include + #include typedef omni_mutex mutex; typedef omni_mutex_lock scoped_lock; #endif -- cgit From c3f962a1f0a4132ad643c58774bb69b190dccc49 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 14 Mar 2009 02:28:41 +0000 Subject: Merged r10554:10595 from michaelld/am_swig_4 into trunk. Major overhaul of SWIG usage in build system, also fixes ticket:130. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10596 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 2 -- 1 file changed, 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index cc8da49de..af5e4980d 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -154,5 +154,3 @@ swiginclude_HEADERS = \ gr_sync_interpolator.i \ gr_top_block.i \ runtime.i - -MOSTLYCLEANFILES = *~ *.loT -- cgit From 8cbe88292ba457fe1dca5931bf037d88a3650bc3 Mon Sep 17 00:00:00 2001 From: eb Date: Thu, 19 Mar 2009 20:58:41 +0000 Subject: Document run/start/stop/wait preconditions. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10654 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 10 +++++----- gnuradio-core/src/lib/runtime/gr_top_block.h | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index ece8b21ca..52b9bff96 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2007,2008 Free Software Foundation, Inc. + * Copyright 2006,2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -124,9 +124,9 @@ public: /*! * Lock a flowgraph in preparation for reconfiguration. When an equal * number of calls to lock() and unlock() have occurred, the flowgraph - * will be restarted automatically. + * will be reconfigured. * - * N.B. lock() and unlock() cannot be called from a flowgraph thread + * N.B. lock() and unlock() may not be called from a flowgraph thread * (E.g., gr_block::work method) or deadlock will occur when * reconfiguration happens. */ @@ -135,9 +135,9 @@ public: /*! * Unlock a flowgraph in preparation for reconfiguration. When an equal * number of calls to lock() and unlock() have occurred, the flowgraph - * will be restarted automatically. + * will be reconfigured. * - * N.B. lock() and unlock() cannot be called from a flowgraph thread + * N.B. lock() and unlock() may not be called from a flowgraph thread * (E.g., gr_block::work method) or deadlock will occur when * reconfiguration happens. */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index b47ec019c..bfe799c84 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -51,21 +51,22 @@ public: * \brief The simple interface to running a flowgraph. * * Calls start() then wait(). Used to run a flowgraph that will stop - * on its own, or to run a flowgraph indefinitely until SIGINT is - * received. + * on its own, or when another thread will call stop(). */ void run(); /*! * Start the contained flowgraph. Creates one or more threads to * execute the flow graph. Returns to the caller once the threads - * are created. + * are created. Calling start() on a top_block that is already + * started IS an error. */ void start(); /*! * Stop the running flowgraph. Notifies each thread created by the - * scheduler to shutdown, then returns to caller. + * scheduler to shutdown, then returns to caller. Calling stop() on + * a top_block that is already stopped IS NOT an error. */ void stop(); @@ -73,16 +74,17 @@ public: * Wait for a flowgraph to complete. Flowgraphs complete when * either (1) all blocks indicate that they are done (typically only * when using gr.file_source, or gr.head, or (2) after stop() has been - * called to request shutdown. + * called to request shutdown. Calling wait on a top_block that is + * not running IS NOT an error (wait returns w/o blocking). */ void wait(); /*! * Lock a flowgraph in preparation for reconfiguration. When an equal * number of calls to lock() and unlock() have occurred, the flowgraph - * will be restarted automatically. + * will be reconfigured. * - * N.B. lock() and unlock() cannot be called from a flowgraph thread + * N.B. lock() and unlock() may not be called from a flowgraph thread * (E.g., gr_block::work method) or deadlock will occur when * reconfiguration happens. */ @@ -91,9 +93,9 @@ public: /*! * Unlock a flowgraph in preparation for reconfiguration. When an equal * number of calls to lock() and unlock() have occurred, the flowgraph - * will be restarted automatically. + * will be reconfigured. * - * N.B. lock() and unlock() cannot be called from a flowgraph thread + * N.B. lock() and unlock() may not be called from a flowgraph thread * (E.g., gr_block::work method) or deadlock will occur when * reconfiguration happens. */ -- cgit From 88304ce16a97945d13510b5fdaefcc0f62462d9d Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 19 Mar 2009 22:32:30 +0000 Subject: Error out when hierarchical block inputs and outputs aren't wired internally. Fixes ticket:237 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10655 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index a026851d2..e5336d483 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -267,6 +267,12 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) throw std::runtime_error(msg.str()); } + if (d_inputs[port] == gr_endpoint()) { + msg << "hierarchical block '" << d_owner->name() << "' input " << port + << " is not connected internally"; + throw std::runtime_error(msg.str()); + } + result = resolve_endpoint(d_inputs[port], true); } else { @@ -275,6 +281,12 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) throw std::runtime_error(msg.str()); } + if (d_outputs[port] == gr_endpoint()) { + msg << "hierarchical block '" << d_owner->name() << "' output " << port + << " is not connected internally"; + throw std::runtime_error(msg.str()); + } + result = resolve_endpoint(d_outputs[port], false); } -- cgit From 4038332cdd92ab3050682e5d55a596aabb0ab806 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 23 Mar 2009 19:49:49 +0000 Subject: Error out when creating hierarchical blocks with arbitrary or variable numbers of inputs and outputs. Temporarily fixes ticket:247; this functionality will be added during the release 3.2 series but not for the first release. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10671 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2.i | 3 ++- .../src/lib/runtime/gr_hier_block2_detail.cc | 22 ++++++++++++++++++---- gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc | 14 +++++++------- 3 files changed, 27 insertions(+), 12 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index 5278eefce..a62f50e84 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -31,7 +31,8 @@ typedef boost::shared_ptr gr_hier_block2_sptr; %rename(hier_block2_swig) gr_make_hier_block2; gr_hier_block2_sptr gr_make_hier_block2(const std::string name, gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); + gr_io_signature_sptr output_signature) + throw (std::runtime_error); class gr_hier_block2 : public gr_basic_block { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index e5336d483..123d5c3cd 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -1,5 +1,5 @@ /* - * Copyright 2006,2007 Free Software Foundation, Inc. + * Copyright 2006,2007,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -33,10 +33,24 @@ gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : d_owner(owner), d_parent_detail(0), - d_fg(gr_make_flowgraph()), - d_inputs(owner->input_signature()->max_streams()), - d_outputs(owner->output_signature()->max_streams()) + d_fg(gr_make_flowgraph()) { + int min_inputs = owner->input_signature()->min_streams(); + int max_inputs = owner->input_signature()->max_streams(); + int min_outputs = owner->output_signature()->min_streams(); + int max_outputs = owner->output_signature()->max_streams(); + + if (max_inputs == gr_io_signature::IO_INFINITE || + max_outputs == gr_io_signature::IO_INFINITE || + (min_inputs != max_inputs) ||(min_outputs != max_outputs) ) { + std::stringstream msg; + msg << "Hierarchical blocks do not yet support arbitrary or" + << " variable numbers of inputs or outputs (" << d_owner->name() << ")"; + throw std::runtime_error(msg.str()); + } + + d_inputs = gr_endpoint_vector_t(max_inputs); + d_outputs = gr_endpoint_vector_t(max_outputs); } gr_hier_block2_detail::~gr_hier_block2_detail() diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc index 2cf1a8d10..d9d89ce2c 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2008 Free Software Foundation, Inc. + * Copyright 2006,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -33,8 +33,8 @@ void qa_gr_hier_block2::test_make() { gr_hier_block2_sptr src1(gr_make_hier_block2("test", - gr_make_io_signature(1, 2, 1 * sizeof(int)), - gr_make_io_signature(3, 4, 2 * sizeof(int)))); + gr_make_io_signature(1, 1, 1 * sizeof(int)), + gr_make_io_signature(1, 1, 1 * sizeof(int)))); CPPUNIT_ASSERT(src1); CPPUNIT_ASSERT_EQUAL(std::string("test"), src1->name()); @@ -43,14 +43,14 @@ void qa_gr_hier_block2::test_make() src1->input_signature()->sizeof_stream_item(0)); CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->min_streams()); - CPPUNIT_ASSERT_EQUAL(2, src1->input_signature()->max_streams()); + CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->max_streams()); - CPPUNIT_ASSERT_EQUAL(2 * (int) sizeof(int), + CPPUNIT_ASSERT_EQUAL(1 * (int) sizeof(int), src1->output_signature()->sizeof_stream_item(0)); - CPPUNIT_ASSERT_EQUAL(3, src1->output_signature()->min_streams()); - CPPUNIT_ASSERT_EQUAL(4, src1->output_signature()->max_streams()); + CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->min_streams()); + CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->max_streams()); } -- cgit From d0dc3ffdc43630abd1cf800cb6f3b9195770fd4d Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 25 Mar 2009 22:29:21 +0000 Subject: Add check for interruption to gr_tpb_thread_body to ensure that threads stop quickly. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10686 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index f61e17243..e3abf6d84 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -23,6 +23,7 @@ #endif #include #include +#include gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) : d_exec(block) @@ -33,6 +34,8 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) gr_block_executor::state s; while (1){ + boost::this_thread::interruption_point(); + d->d_tpb.clear_changed(); s = d_exec.run_one_iteration(); -- cgit From 798f915a63aa527895233eec5e67b8eb376ecd7b Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 7 Apr 2009 19:53:17 +0000 Subject: Fix for ticket:262. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10789 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_block.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 7c2e9901b..b8b1bd9c7 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -51,7 +51,7 @@ gr_block::forecast (int noutput_items, gr_vector_int &ninput_items_required) { unsigned ninputs = ninput_items_required.size (); for (unsigned i = 0; i < ninputs; i++) - ninput_items_required[i] = noutput_items; + ninput_items_required[i] = noutput_items + history() - 1; } // default implementation -- cgit From f0282d9fdf1a5e18aa4f1717843befe4d147ffb7 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 17 Apr 2009 17:24:17 +0000 Subject: Fixes ticket:374 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10865 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 123d5c3cd..c6cbd5b31 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -76,6 +76,14 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr block) throw std::invalid_argument(msg.str()); } + gr_hier_block2_sptr hblock(cast_to_hier_block2_sptr(block)); + + if (hblock && hblock.get() != d_owner) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "connect: block is hierarchical, setting parent to " << this << std::endl; + hblock->d_detail->d_parent_detail = this; + } + d_blocks.push_back(block); } -- cgit From e6fbd962e13459e87c084d27b5fdf54fda88af81 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 17 Apr 2009 18:45:58 +0000 Subject: Fixes ticket:386 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10869 221aa14e-8319-0410-a670-987f0aec2ac5 --- .../src/lib/runtime/gr_hier_block2_detail.cc | 38 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index c6cbd5b31..1c437d3c8 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -146,16 +146,44 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, void gr_hier_block2_detail::disconnect(gr_basic_block_sptr block) { + // Check on singleton list for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { if (*p == block) { d_blocks.erase(p); + + gr_hier_block2_sptr hblock(cast_to_hier_block2_sptr(block)); + if (block && block.get() != d_owner) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "disconnect: block is hierarchical, clearing parent" << std::endl; + hblock->d_detail->d_parent_detail = 0; + } + return; } } - std::stringstream msg; - msg << "cannot disconnect block " << block << ", not found"; - throw std::invalid_argument(msg.str()); + // Otherwise find all edges containing block + gr_edge_vector_t edges, tmp = d_fg->edges(); + gr_edge_vector_t::iterator p; + for (p = tmp.begin(); p != tmp.end(); p++) { + if ((*p).src().block() == block || (*p).dst().block() == block) { + edges.push_back(*p); + + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "disconnect: block found in edge " << (*p) << std::endl; + } + } + + if (edges.size() == 0) { + std::stringstream msg; + msg << "cannot disconnect block " << block << ", not found"; + throw std::invalid_argument(msg.str()); + } + + for (p = edges.begin(); p != edges.end(); p++) { + disconnect((*p).src().block(), (*p).src().port(), + (*p).dst().block(), (*p).dst().port()); + } } void @@ -174,13 +202,13 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, if (src_block && src.get() != d_owner) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) - std::cout << "connect: src is hierarchical, clearing parent" << std::endl; + std::cout << "disconnect: src is hierarchical, clearing parent" << std::endl; src_block->d_detail->d_parent_detail = 0; } if (dst_block && dst.get() != d_owner) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) - std::cout << "connect: dst is hierarchical, clearing parent" << std::endl; + std::cout << "disconnect: dst is hierarchical, clearing parent" << std::endl; dst_block->d_detail->d_parent_detail = 0; } -- cgit From 1ef3a813e491565b87247d7de5759f9932090d52 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 17 Apr 2009 20:30:56 +0000 Subject: Fixes ticket:383 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10871 221aa14e-8319-0410-a670-987f0aec2ac5 --- .../src/lib/runtime/gr_hier_block2_detail.cc | 37 +++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 1c437d3c8..d85d26749 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -365,9 +365,12 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) std::stringstream msg; // Check if endpoint is a leaf node - if (cast_to_block_sptr(endp.block())) + if (cast_to_block_sptr(endp.block())) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "Block " << endp.block() << " is a leaf node, returning." << std::endl; return endp; - + } + // Check if endpoint is a hierarchical block gr_hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(endp.block())); if (hier_block2) { @@ -387,35 +390,53 @@ void gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const { if (GR_HIER_BLOCK2_DETAIL_DEBUG) - std::cout << "flattening " << d_owner->name() << std::endl; + std::cout << "Flattening " << d_owner->name() << std::endl; // Add my edges to the flow graph, resolving references to actual endpoints gr_edge_vector_t edges = d_fg->edges(); - + for (gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "Flattening edge " << (*p) << std::endl; gr_endpoint src_endp = resolve_endpoint(p->src(), false); gr_endpoint dst_endp = resolve_endpoint(p->dst(), true); + + if (GR_HIER_BLOCK2_DETAIL_DEBUG) { + std::cout << "src_endp = " << src_endp + << ", dst_endp = " << dst_endp << std::endl; + } + sfg->connect(src_endp, dst_endp); } - // Construct unique list of blocks used either in edges or - // by themselves. I hate STL. + // Construct unique list of blocks used either in edges, inputs, + // outputs, or by themselves. I still hate STL. gr_basic_block_vector_t blocks, tmp = d_fg->calc_used_blocks(); - std::insert_iterator inserter(blocks, blocks.begin()); + std::vector::const_iterator p; // Because flatten_aux is const for (p = d_blocks.begin(); p != d_blocks.end(); p++) tmp.push_back(*p); + + std::vector::const_iterator e; // Because flatten_aux is const + for (e = d_inputs.begin(); e != d_inputs.end(); e++) + tmp.push_back((*e).block()); + for (e = d_outputs.begin(); e != d_outputs.end(); e++) + tmp.push_back((*e).block()); + sort(tmp.begin(), tmp.end()); + + std::insert_iterator inserter(blocks, blocks.begin()); unique_copy(tmp.begin(), tmp.end(), inserter); // Recurse hierarchical children for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { gr_hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(*p)); - if (hier_block2) + if (hier_block2) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "flatten_aux: recursing into hierarchical block " << hier_block2 << std::endl; hier_block2->d_detail->flatten_aux(sfg); + } } } -- cgit From 77bfe4faccd79741b49e0dee3bb0a21bd21da53f Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sun, 19 Apr 2009 20:45:40 +0000 Subject: Merged r10875:10880 from jcorgan/t161 into trunk. Implements ticket:161, allowing multiple internal blocks to be connected to a hier_block2 external input. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10881 221aa14e-8319-0410-a670-987f0aec2ac5 --- .../src/lib/runtime/gr_hier_block2_detail.cc | 86 +++++++++++++--------- .../src/lib/runtime/gr_hier_block2_detail.h | 12 +-- 2 files changed, 60 insertions(+), 38 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index d85d26749..fa52b7429 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -49,7 +49,7 @@ gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : throw std::runtime_error(msg.str()); } - d_inputs = gr_endpoint_vector_t(max_inputs); + d_inputs = std::vector(max_inputs); d_outputs = gr_endpoint_vector_t(max_outputs); } @@ -222,7 +222,6 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, d_fg->disconnect(src, src_port, dst, dst_port); } -// FIXME: ticket:161 will be implemented here void gr_hier_block2_detail::connect_input(int my_port, int port, gr_basic_block_sptr block) { @@ -233,13 +232,16 @@ gr_hier_block2_detail::connect_input(int my_port, int port, gr_basic_block_sptr throw std::invalid_argument(msg.str()); } - if (d_inputs[my_port].block()) { - msg << "external input port " << my_port << " already wired to " - << d_inputs[my_port]; + gr_endpoint_vector_t &endps = d_inputs[my_port]; + gr_endpoint endp(block, port); + + gr_endpoint_viter_t p = std::find(endps.begin(), endps.end(), endp); + if (p != endps.end()) { + msg << "external input port " << my_port << " already wired to " << endp; throw std::invalid_argument(msg.str()); } - - d_inputs[my_port] = gr_endpoint(block, port); + + endps.push_back(endp); } void @@ -271,13 +273,16 @@ gr_hier_block2_detail::disconnect_input(int my_port, int port, gr_basic_block_sp throw std::invalid_argument(msg.str()); } - if (d_inputs[my_port].block() != block) { - msg << "block " << block << " not assigned to input " - << my_port << ", can't disconnect"; + gr_endpoint_vector_t &endps = d_inputs[my_port]; + gr_endpoint endp(block, port); + + gr_endpoint_viter_t p = std::find(endps.begin(), endps.end(), endp); + if (p == endps.end()) { + msg << "external input port " << my_port << " not connected to " << endp; throw std::invalid_argument(msg.str()); } - - d_inputs[my_port] = gr_endpoint(); + + endps.erase(p); } void @@ -299,7 +304,7 @@ gr_hier_block2_detail::disconnect_output(int my_port, int port, gr_basic_block_s d_outputs[my_port] = gr_endpoint(); } -gr_endpoint +gr_endpoint_vector_t gr_hier_block2_detail::resolve_port(int port, bool is_input) { std::stringstream msg; @@ -309,7 +314,7 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) << (is_input ? "input" : "output") << " of " << d_owner->name() << std::endl; - gr_endpoint result; + gr_endpoint_vector_t result; if (is_input) { if (port < 0 || port >= (signed)d_inputs.size()) { @@ -317,13 +322,18 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) throw std::runtime_error(msg.str()); } - if (d_inputs[port] == gr_endpoint()) { + if (d_inputs[port].empty()) { msg << "hierarchical block '" << d_owner->name() << "' input " << port << " is not connected internally"; throw std::runtime_error(msg.str()); } - result = resolve_endpoint(d_inputs[port], true); + gr_endpoint_vector_t &endps = d_inputs[port]; + gr_endpoint_viter_t p; + for (p = endps.begin(); p != endps.end(); p++) { + gr_endpoint_vector_t tmp = resolve_endpoint(*p, true); + std::copy(tmp.begin(), tmp.end(), back_inserter(result)); + } } else { if (port < 0 || port >= (signed)d_outputs.size()) { @@ -340,7 +350,7 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) result = resolve_endpoint(d_outputs[port], false); } - if (!result.block()) { + if (result.empty()) { msg << "unable to resolve " << (is_input ? "input port " : "output port ") << port; @@ -359,16 +369,18 @@ gr_hier_block2_detail::disconnect_all() d_outputs.clear(); } -gr_endpoint +gr_endpoint_vector_t gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) const { std::stringstream msg; + gr_endpoint_vector_t result; // Check if endpoint is a leaf node if (cast_to_block_sptr(endp.block())) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "Block " << endp.block() << " is a leaf node, returning." << std::endl; - return endp; + result.push_back(endp); + return result; } // Check if endpoint is a hierarchical block @@ -394,33 +406,41 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const // Add my edges to the flow graph, resolving references to actual endpoints gr_edge_vector_t edges = d_fg->edges(); - - for (gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) { + gr_edge_viter_t p; + + for (p = edges.begin(); p != edges.end(); p++) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "Flattening edge " << (*p) << std::endl; - gr_endpoint src_endp = resolve_endpoint(p->src(), false); - gr_endpoint dst_endp = resolve_endpoint(p->dst(), true); + gr_endpoint_vector_t src_endps = resolve_endpoint(p->src(), false); + gr_endpoint_vector_t dst_endps = resolve_endpoint(p->dst(), true); - if (GR_HIER_BLOCK2_DETAIL_DEBUG) { - std::cout << "src_endp = " << src_endp - << ", dst_endp = " << dst_endp << std::endl; + gr_endpoint_viter_t s, d; + for (s = src_endps.begin(); s != src_endps.end(); s++) { + for (d = dst_endps.begin(); d != dst_endps.end(); d++) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << (*s) << "->" << (*d) << std::endl; + sfg->connect(*s, *d); + } } - sfg->connect(src_endp, dst_endp); } // Construct unique list of blocks used either in edges, inputs, // outputs, or by themselves. I still hate STL. gr_basic_block_vector_t blocks, tmp = d_fg->calc_used_blocks(); - std::vector::const_iterator p; // Because flatten_aux is const - for (p = d_blocks.begin(); p != d_blocks.end(); p++) - tmp.push_back(*p); + std::vector::const_iterator b; // Because flatten_aux is const + for (b = d_blocks.begin(); b != d_blocks.end(); b++) + tmp.push_back(*b); + + std::vector::const_iterator ep; // Because flatten_aux is const + std::vector::const_iterator e; // Because flatten_aux is const + + for (ep = d_inputs.begin(); ep != d_inputs.end(); ep++) + for (e = (*ep).begin(); e != (*ep).end(); e++) + tmp.push_back((*e).block()); - std::vector::const_iterator e; // Because flatten_aux is const - for (e = d_inputs.begin(); e != d_inputs.end(); e++) - tmp.push_back((*e).block()); for (e = d_outputs.begin(); e != d_outputs.end(); e++) tmp.push_back((*e).block()); diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index d31ae93e7..0e1f89fb4 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -1,5 +1,6 @@ +/* -*- c++ -*- */ /* - * Copyright 2006,2007 Free Software Foundation, Inc. + * Copyright 2006,2007,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -48,16 +49,17 @@ private: gr_hier_block2 *d_owner; gr_hier_block2_detail *d_parent_detail; gr_flowgraph_sptr d_fg; - gr_endpoint_vector_t d_inputs; - gr_endpoint_vector_t d_outputs; + std::vector d_inputs; // Multiple internal endpoints per external input + gr_endpoint_vector_t d_outputs; // Single internal endpoint per external output gr_basic_block_vector_t d_blocks; void connect_input(int my_port, int port, gr_basic_block_sptr block); void connect_output(int my_port, int port, gr_basic_block_sptr block); void disconnect_input(int my_port, int port, gr_basic_block_sptr block); void disconnect_output(int my_port, int port, gr_basic_block_sptr block); - gr_endpoint resolve_port(int port, bool is_input); - gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input) const; + + gr_endpoint_vector_t resolve_port(int port, bool is_input); + gr_endpoint_vector_t resolve_endpoint(const gr_endpoint &endp, bool is_input) const; }; #endif /* INCLUDED_GR_HIER_BLOCK2_DETAIL_H */ -- cgit From b8b202c0d29d9e764def63bde080bc07b00cc2cc Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 8 May 2009 18:51:39 +0000 Subject: Fix abort when user fails to connect hier_block2 outputs both internally and internally; throw meaningful exception instead. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10992 221aa14e-8319-0410-a670-987f0aec2ac5 --- .../src/lib/runtime/gr_hier_block2_detail.cc | 37 +++++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index fa52b7429..877e240c2 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -423,27 +423,40 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const sfg->connect(*s, *d); } } - } // Construct unique list of blocks used either in edges, inputs, // outputs, or by themselves. I still hate STL. - gr_basic_block_vector_t blocks, tmp = d_fg->calc_used_blocks(); + gr_basic_block_vector_t blocks; // unique list of used blocks + gr_basic_block_vector_t tmp = d_fg->calc_used_blocks(); + // First add the list of singleton blocks std::vector::const_iterator b; // Because flatten_aux is const - for (b = d_blocks.begin(); b != d_blocks.end(); b++) + for (b = d_blocks.begin(); b != d_blocks.end(); b++) tmp.push_back(*b); - std::vector::const_iterator ep; // Because flatten_aux is const - std::vector::const_iterator e; // Because flatten_aux is const - - for (ep = d_inputs.begin(); ep != d_inputs.end(); ep++) - for (e = (*ep).begin(); e != (*ep).end(); e++) - tmp.push_back((*e).block()); - - for (e = d_outputs.begin(); e != d_outputs.end(); e++) - tmp.push_back((*e).block()); + // Now add the list of connected input blocks + std::stringstream msg; + for (unsigned int i = 0; i < d_inputs.size(); i++) { + if (d_inputs[i].size() == 0) { + msg << "In hierarchical block " << d_owner->name() << ", input " << i + << " is not connected internally"; + throw std::runtime_error(msg.str()); + } + + for (unsigned int j = 0; j < d_inputs[i].size(); j++) + tmp.push_back(d_inputs[i][j].block()); + } + for (unsigned int i = 0; i < d_outputs.size(); i++) { + gr_basic_block_sptr blk = d_outputs[i].block(); + if (!blk) { + msg << "In hierarchical block " << d_owner->name() << ", output " << i + << " is not connected internally"; + throw std::runtime_error(msg.str()); + } + tmp.push_back(blk); + } sort(tmp.begin(), tmp.end()); std::insert_iterator inserter(blocks, blocks.begin()); -- cgit From ed236703145cb56e7e69c5605c5fbf01a1ab3878 Mon Sep 17 00:00:00 2001 From: eb Date: Fri, 22 May 2009 16:11:15 +0000 Subject: doc fixes! work-in-progress git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11085 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 3 +-- gnuradio-core/src/lib/runtime/gr_flowgraph.h | 7 +++---- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 3 ++- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h | 3 +++ gnuradio-core/src/lib/runtime/gr_io_signature.h | 1 + gnuradio-core/src/lib/runtime/gr_sync_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 2 +- gnuradio-core/src/lib/runtime/gr_sync_interpolator.h | 2 +- gnuradio-core/src/lib/runtime/gr_top_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h | 2 +- gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h | 2 +- 16 files changed, 21 insertions(+), 18 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 78297d3f0..faaba1c83 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -30,7 +30,7 @@ /*! * \brief The abstract base class for all signal processing blocks. - * \ingroup base + * \ingroup internal * * Basic blocks are the bare abstraction of an entity that has a name * and a set of inputs and outputs. These are never instantiated diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 437b610b4..354695c0b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -27,7 +27,7 @@ /*! * \brief The abstract base class for all 'terminal' processing blocks. - * \ingroup base + * \ingroup base_blk * * A signal processing flow is constructed by creating a tree of * hierarchical blocks, which at any level may also contain terminal nodes diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h index 673c4df16..8e9834337 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h @@ -33,8 +33,7 @@ gr_flat_flowgraph_sptr gr_make_flat_flowgraph(); /*! *\brief Class specializing gr_flat_flowgraph that has all nodes * as gr_blocks, with no hierarchy - * \ingroup base - * + * \ingroup internal */ class gr_flat_flowgraph : public gr_flowgraph { diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flowgraph.h index fc407e72b..8e988506b 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.h @@ -27,9 +27,8 @@ #include /*! - *\brief Class representing a specific input or output graph endpoint + * \brief Class representing a specific input or output graph endpoint * \ingroup internal - * */ class gr_endpoint { @@ -85,8 +84,8 @@ typedef std::vector::iterator gr_edge_viter_t; gr_flowgraph_sptr gr_make_flowgraph(); /*! - *\brief Class representing a directed, acyclic graph of basic blocks - * + * \brief Class representing a directed, acyclic graph of basic blocks + * \ingroup internal */ class gr_flowgraph { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 52b9bff96..f0bbe4e65 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -36,7 +36,8 @@ class gr_hier_block2_detail; /*! * \brief gr_hier_block2 - Hierarchical container class for gr_block's - * \ingroup internal + * \ingroup container_blk + * \ingroup base_blk * */ class gr_hier_block2 : public gr_basic_block diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index 0e1f89fb4..6f5384e5a 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -26,6 +26,9 @@ #include #include +/*! + * \ingroup internal + */ class gr_hier_block2_detail : boost::noncopyable { public: diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index bf71dea57..8c327259c 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -85,6 +85,7 @@ gr_make_io_signaturev(int min_streams, int max_streams, /*! * \brief i/o signature for input and output ports. + * \brief misc */ class gr_io_signature { int d_min_streams; diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index c7f7d4df3..3a5d89d19 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -27,7 +27,7 @@ /*! * \brief synchronous 1:1 input to output with history - * \ingroup internal + * \ingroup base_blk * * Override work to provide the signal processing implementation. */ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h index 1482ecc00..12cd54195 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -27,7 +27,7 @@ /*! * \brief synchronous N:1 input to output with history - * \ingroup internal + * \ingroup base_blk * * Override work to provide the signal processing implementation. */ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index 87e718cca..0363bc55c 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -27,7 +27,7 @@ /*! * \brief synchronous 1:N input to output with history - * \ingroup internal + * \ingroup base_blk * * Override work to provide the signal processing implementation. */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index bfe799c84..8052954e3 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -31,7 +31,7 @@ gr_top_block_sptr gr_make_top_block(const std::string &name); /*! *\brief Top-level hierarchical block representing a flowgraph - * \ingroup internal + * \ingroup container_blk * */ class gr_top_block : public gr_hier_block2 diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h index 0d4f45832..a73a1559c 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h @@ -27,7 +27,7 @@ /*! * \brief abstract class to implement doubly mapped virtual memory circular buffers - * \ingroup base + * \ingroup internal */ class gr_vmcircbuf { protected: diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h index 2bb7bb16f..9276ae98b 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h @@ -30,7 +30,7 @@ #endif /*! * \brief concrete class to implement circular buffers with mmap and shm_open - * \ingroup base + * \ingroup internal */ class gr_vmcircbuf_createfilemapping : public gr_vmcircbuf { diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h index 7e628fa59..238f44414 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h @@ -27,7 +27,7 @@ /*! * \brief concrete class to implement circular buffers with mmap and shm_open - * \ingroup base + * \ingroup internal */ class gr_vmcircbuf_mmap_shm_open : public gr_vmcircbuf { public: diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h index da91d2f02..e5be52768 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h @@ -27,7 +27,7 @@ /*! * \brief concrete class to implement circular buffers with mmap and shm_open - * \ingroup base + * \ingroup internal */ class gr_vmcircbuf_mmap_tmpfile : public gr_vmcircbuf { public: diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h index ffc74918e..cc87f8fe6 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h @@ -27,7 +27,7 @@ /*! * \brief concrete class to implement circular buffers with mmap and shm_open - * \ingroup base + * \ingroup internal */ class gr_vmcircbuf_sysv_shm : public gr_vmcircbuf { public: -- cgit From 5a4b9ba9af590b2a269cb3e5872c85faa7c284d1 Mon Sep 17 00:00:00 2001 From: eb Date: Fri, 22 May 2009 21:22:22 +0000 Subject: Doc fixes. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11088 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_buffer.h | 3 ++- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 2 +- gnuradio-core/src/lib/runtime/gr_io_signature.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 75063cc6a..cb593eea3 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -163,7 +163,8 @@ class gr_buffer { }; /*! - * \brief create a new gr_buffer_reader and attach it to buffer \p buf + * \brief Create a new gr_buffer_reader and attach it to buffer \p buf + * \param buf is the buffer the \p gr_buffer_reader reads from. * \param nzero_preload -- number of zero items to "preload" into buffer. * \param link is the block that reads from the buffer using this gr_buffer_reader. */ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index f0bbe4e65..f50b1cb94 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -35,7 +35,7 @@ gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, class gr_hier_block2_detail; /*! - * \brief gr_hier_block2 - Hierarchical container class for gr_block's + * \brief Hierarchical container class for gr_block's and gr_hier_block2's * \ingroup container_blk * \ingroup base_blk * diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index 8c327259c..5d194cf55 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -98,7 +98,7 @@ class gr_io_signature { friend gr_io_signature_sptr gr_make_io_signaturev(int min_streams, int max_streams, - const std::vector &sizeof_stream_item); + const std::vector &sizeof_stream_items); public: -- cgit From 40b8a57d69b4b85f207fb0408347c210e23202cc Mon Sep 17 00:00:00 2001 From: jcorgan Date: Wed, 27 May 2009 01:54:41 +0000 Subject: Merged r11123:11148 from jcorgan/np into trunk. Adds --enable-python option to configure (defaults to yes). Using --disable-python or --enable-python=no will cause only C++ API targets to be created and installed. Several new shared libraries are now created. Where in the past, the C++ objects of the actual gnuradio blocks that were in a component were hidden inside their corresponding Python extension modules, these are now split out into a libgnuradio-foo.so library, and the _foo.so Python module is linked to that. This has been the way several top- level components have operated for some time, such as gr-audio-alsa and gr-usrp and gr-usrp2. This changeset applies that pattern to all components. C++ API users can use pkg-config to discover the cflags and libs parameters needed to include and link against these libraries. These components have not been tested: gr-comedi gr-audio-osx gr-audio-windows Passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11150 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index af5e4980d..14ab464ad 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -135,6 +135,7 @@ noinst_HEADERS = \ qa_gr_vmcircbuf.h \ qa_runtime.h +if PYTHON swiginclude_HEADERS = \ gr_basic_block.i \ gr_block.i \ @@ -154,3 +155,4 @@ swiginclude_HEADERS = \ gr_sync_interpolator.i \ gr_top_block.i \ runtime.i +endif -- cgit From 4b4da4852482546157abbf8589f2a85bac6c3509 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 25 Jul 2009 17:39:00 +0000 Subject: Merge r11462:11485 from jcorgan/omni into trunk. Removes dependency on omnithreads from gnuradio-core. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11486 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 6 ++--- gnuradio-core/src/lib/runtime/gr_buffer.cc | 8 +++---- gnuradio-core/src/lib/runtime/gr_buffer.h | 14 +++++------- gnuradio-core/src/lib/runtime/gr_msg_queue.cc | 26 ++++++++++------------ gnuradio-core/src/lib/runtime/gr_msg_queue.h | 19 ++++++++-------- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 8 +------ gnuradio-core/src/lib/runtime/gr_sptr_magic.cc | 19 +++++----------- gnuradio-core/src/lib/runtime/gr_tpb_detail.h | 17 +++++++------- .../src/lib/runtime/gr_tpb_thread_body.cc | 6 ++--- 9 files changed, 51 insertions(+), 72 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index fd3a916d4..e8d30b963 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -68,7 +68,7 @@ min_available_space (gr_block_detail *d, int output_multiple) int min_space = std::numeric_limits::max(); for (int i = 0; i < d->noutputs (); i++){ - gr_buffer::scoped_lock guard(*d->output(i)->mutex()); + gruel::scoped_lock guard(*d->output(i)->mutex()); #if 0 int n = round_down(d->output(i)->space_available(), output_multiple); #else @@ -163,7 +163,7 @@ gr_block_executor::run_one_iteration() /* * Acquire the mutex and grab local copies of items_available and done. */ - gr_buffer::scoped_lock guard(*d->input(i)->mutex()); + gruel::scoped_lock guard(*d->input(i)->mutex()); d_ninput_items[i] = d->input(i)->items_available(); d_input_done[i] = d->input(i)->done(); } @@ -205,7 +205,7 @@ gr_block_executor::run_one_iteration() /* * Acquire the mutex and grab local copies of items_available and done. */ - gr_buffer::scoped_lock guard(*d->input(i)->mutex()); + gruel::scoped_lock guard(*d->input(i)->mutex()); d_ninput_items[i] = d->input(i)->items_available (); d_input_done[i] = d->input(i)->done(); } diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 31a471ea7..db2db5d6d 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.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 * @@ -175,14 +175,14 @@ gr_buffer::write_pointer () void gr_buffer::update_write_pointer (int nitems) { - scoped_lock guard(*mutex()); + gruel::scoped_lock guard(*mutex()); d_write_index = index_add (d_write_index, nitems); } void gr_buffer::set_done (bool done) { - scoped_lock guard(*mutex()); + gruel::scoped_lock guard(*mutex()); d_done = done; } @@ -251,7 +251,7 @@ gr_buffer_reader::read_pointer () void gr_buffer_reader::update_read_pointer (int nitems) { - scoped_lock guard(*mutex()); + gruel::scoped_lock guard(*mutex()); d_read_index = d_buffer->index_add (d_read_index, nitems); } diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index cb593eea3..207bfe7c5 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.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 * @@ -25,7 +25,7 @@ #include #include -#include +#include class gr_vmcircbuf; @@ -50,8 +50,6 @@ gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr lin class gr_buffer { public: - typedef boost::unique_lock scoped_lock; - virtual ~gr_buffer (); /*! @@ -88,7 +86,7 @@ class gr_buffer { size_t nreaders() const { return d_readers.size(); } gr_buffer_reader* reader(size_t index) { return d_readers[index]; } - boost::mutex *mutex() { return &d_mutex; } + gruel::mutex *mutex() { return &d_mutex; } // ------------------------------------------------------------------------- @@ -110,7 +108,7 @@ class gr_buffer { // // The mutex protects d_write_index, d_done and the d_read_index's in the buffer readers. // - boost::mutex d_mutex; + gruel::mutex d_mutex; unsigned int d_write_index; // in items [0,d_bufsize) bool d_done; @@ -185,8 +183,6 @@ long gr_buffer_ncurrently_allocated (); class gr_buffer_reader { public: - typedef gr_buffer::scoped_lock scoped_lock; - ~gr_buffer_reader (); /*! @@ -221,7 +217,7 @@ class gr_buffer_reader { void set_done (bool done) { d_buffer->set_done (done); } bool done () const { return d_buffer->done (); } - boost::mutex *mutex() { return d_buffer->mutex(); } + gruel::mutex *mutex() { return d_buffer->mutex(); } /*! diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc index 922eeda03..3097acc9e 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,16 +26,14 @@ #include #include - gr_msg_queue_sptr gr_make_msg_queue(unsigned int limit) { return gr_msg_queue_sptr (new gr_msg_queue(limit)); } - gr_msg_queue::gr_msg_queue(unsigned int limit) - : d_not_empty(&d_mutex), d_not_full(&d_mutex), + : d_not_empty(), d_not_full(), /*d_head(0), d_tail(0),*/ d_count(0), d_limit(limit) { } @@ -51,10 +49,10 @@ gr_msg_queue::insert_tail(gr_message_sptr msg) if (msg->d_next) throw std::invalid_argument("gr_msg_queue::insert_tail: msg already in queue"); - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); while (full_p()) - d_not_full.wait(); + d_not_full.wait(guard); if (d_tail == 0){ d_tail = d_head = msg; @@ -68,17 +66,17 @@ gr_msg_queue::insert_tail(gr_message_sptr msg) msg->d_next.reset(); } d_count++; - d_not_empty.signal(); + d_not_empty.notify_one(); } gr_message_sptr gr_msg_queue::delete_head() { - omni_mutex_lock l(d_mutex); - gr_message_sptr m; + gruel::scoped_lock guard(d_mutex); + gr_message_sptr m; while ((m = d_head) == 0) - d_not_empty.wait(); + d_not_empty.wait(guard); d_head = m->d_next; if (d_head == 0){ @@ -89,15 +87,15 @@ gr_msg_queue::delete_head() d_count--; // m->d_next = 0; m->d_next.reset(); - d_not_full.signal(); + d_not_full.notify_one(); return m; } gr_message_sptr gr_msg_queue::delete_head_nowait() { - omni_mutex_lock l(d_mutex); - gr_message_sptr m; + gruel::scoped_lock guard(d_mutex); + gr_message_sptr m; if ((m = d_head) == 0){ //return 0; @@ -113,7 +111,7 @@ gr_msg_queue::delete_head_nowait() d_count--; //m->d_next = 0; m->d_next.reset(); - d_not_full.signal(); + d_not_full.notify_one(); return m; } diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.h b/gnuradio-core/src/lib/runtime/gr_msg_queue.h index f965887e1..477b1ddf1 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #define INCLUDED_GR_MSG_QUEUE_H #include -#include +#include class gr_msg_queue; typedef boost::shared_ptr gr_msg_queue_sptr; @@ -35,13 +35,14 @@ gr_msg_queue_sptr gr_make_msg_queue(unsigned int limit=0); * \ingroup misc */ class gr_msg_queue : public gr_msg_handler { - omni_mutex d_mutex; - omni_condition d_not_empty; - omni_condition d_not_full; - gr_message_sptr d_head; - gr_message_sptr d_tail; - unsigned int d_count; // # of messages in queue. - unsigned int d_limit; // max # of messages in queue. 0 -> unbounded + + gruel::mutex d_mutex; + gruel::condition_variable d_not_empty; + gruel::condition_variable d_not_full; + gr_message_sptr d_head; + gr_message_sptr d_tail; + unsigned int d_count; // # of messages in queue. + unsigned int d_limit; // max # of messages in queue. 0 -> unbounded public: gr_msg_queue(unsigned int limit); diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 254a7a940..9ca92b6ec 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -32,12 +32,6 @@ gr_msg_queue_sptr gr_make_msg_queue(unsigned limit=0); */ %ignore gr_msg_queue; class gr_msg_queue : public gr_msg_handler { - omni_mutex d_mutex; - omni_condition d_cond; - gr_message_sptr d_head; - gr_message_sptr d_tail; - int d_count; - public: gr_msg_queue(unsigned int limit); ~gr_msg_queue(); diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc index 3295f849e..96ffae85f 100644 --- a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,19 +27,11 @@ #include -#if 0 - #include - typedef boost::mutex mutex; - typedef boost::mutex::scoped_lock scoped_lock; -#else - #include - typedef omni_mutex mutex; - typedef omni_mutex_lock scoped_lock; -#endif +#include namespace gnuradio { - static mutex s_mutex; + static gruel::mutex s_mutex; typedef std::map sptr_map; static sptr_map s_map; @@ -47,7 +39,7 @@ namespace gnuradio { detail::sptr_magic::create_and_stash_initial_sptr(gr_hier_block2 *p) { gr_basic_block_sptr sptr(p); - scoped_lock l(); + gruel::scoped_lock guard(); s_map.insert(sptr_map::value_type(static_cast(p), sptr)); } @@ -68,7 +60,7 @@ namespace gnuradio { * p is a subclass of gr_hier_block2, thus we've already created the shared pointer * and stashed it away. Fish it out and return it. */ - scoped_lock l(); + gruel::scoped_lock guard(); sptr_map::iterator pos = s_map.find(static_cast(p)); if (pos == s_map.end()) throw std::invalid_argument("gr_sptr_magic: invalid pointer!"); @@ -78,4 +70,3 @@ namespace gnuradio { return sptr; } }; - diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h index 9566312dc..ab955240b 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -21,7 +21,7 @@ #ifndef INCLUDED_GR_TPB_DETAIL_H #define INCLUDED_GR_TPB_DETAIL_H -#include +#include class gr_block_detail; @@ -29,13 +29,12 @@ class gr_block_detail; * \brief used by thread-per-block scheduler */ struct gr_tpb_detail { - typedef boost::unique_lock scoped_lock; - boost::mutex mutex; //< protects all vars + gruel::mutex mutex; //< protects all vars bool input_changed; - boost::condition_variable input_cond; + gruel::condition_variable input_cond; bool output_changed; - boost::condition_variable output_cond; + gruel::condition_variable output_cond; gr_tpb_detail() : input_changed(false), output_changed(false) {} @@ -53,7 +52,7 @@ struct gr_tpb_detail { //! Called by us void clear_changed() { - scoped_lock guard(mutex); + gruel::scoped_lock guard(mutex); input_changed = false; output_changed = false; } @@ -63,7 +62,7 @@ private: //! Used by notify_downstream void set_input_changed() { - scoped_lock guard(mutex); + gruel::scoped_lock guard(mutex); input_changed = true; input_cond.notify_one(); } @@ -71,7 +70,7 @@ private: //! Used by notify_upstream void set_output_changed() { - scoped_lock guard(mutex); + gruel::scoped_lock guard(mutex); output_changed = true; output_cond.notify_one(); } diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index e3abf6d84..458b16d64 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -54,7 +54,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) case gr_block_executor::BLKD_IN: // Wait for input. { - gr_tpb_detail::scoped_lock guard(d->d_tpb.mutex); + gruel::scoped_lock guard(d->d_tpb.mutex); while(!d->d_tpb.input_changed) d->d_tpb.input_cond.wait(guard); } @@ -62,7 +62,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) case gr_block_executor::BLKD_OUT: // Wait for output buffer space. { - gr_tpb_detail::scoped_lock guard(d->d_tpb.mutex); + gruel::scoped_lock guard(d->d_tpb.mutex); while(!d->d_tpb.output_changed) d->d_tpb.output_cond.wait(guard); } -- cgit From 3556ef4080be8b0fe569d28cae6568b761edbd7b Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 1 Aug 2009 14:56:28 +0000 Subject: Merged r11500:11506 from features/msg-passing into trunk. Work-in-progress, passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11524 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 5 ++++- gnuradio-core/src/lib/runtime/gr_basic_block.h | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index e94e089e2..71ccc0245 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -27,6 +27,8 @@ #include #include +using namespace pmt; + static long s_next_id = 0; static long s_ncurrently_allocated = 0; @@ -39,7 +41,8 @@ gr_basic_block_ncurrently_allocated() gr_basic_block::gr_basic_block(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature) - : d_name(name), + : gruel::msg_accepter_msgq(gruel::make_msg_queue(0)), + d_name(name), d_input_signature(input_signature), d_output_signature(output_signature), d_unique_id(s_next_id++), diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index faaba1c83..27ec0fd89 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2008 Free Software Foundation, Inc. + * Copyright 2006,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,20 +26,21 @@ #include #include #include +#include #include /*! * \brief The abstract base class for all signal processing blocks. * \ingroup internal * - * Basic blocks are the bare abstraction of an entity that has a name - * and a set of inputs and outputs. These are never instantiated + * Basic blocks are the bare abstraction of an entity that has a name, + * a set of inputs and outputs, and a message queue. These are never instantiated * directly; rather, this is the abstract parent class of both gr_hier_block, * which is a recursive container, and gr_block, which implements actual * signal processing functions. */ -class gr_basic_block : public boost::enable_shared_from_this +class gr_basic_block : gruel::msg_accepter_msgq, public boost::enable_shared_from_this { protected: friend class gr_flowgraph; @@ -96,6 +97,17 @@ public: * and output gr_io_signatures. */ virtual bool check_topology(int ninputs, int noutputs) { return true; } + + /*! + * \brief Block message handler. + * + * \param msg Arbitrary message encapsulated as pmt::pmt_t + * + * This function is called by the runtime system whenever there are + * messages in its queue. Blocks should override this to receive + * messages; the default behavior is to drop them on the floor. + */ + virtual void handle_msg(pmt::pmt_t msg) { }; }; inline bool operator<(gr_basic_block_sptr lhs, gr_basic_block_sptr rhs) -- cgit From f15982950e4674f0cad53d25d36409253661af34 Mon Sep 17 00:00:00 2001 From: git repository hosting Date: Thu, 13 Aug 2009 22:26:53 -0600 Subject: Added git ignore files auto created from svn:ignore properties. --- gnuradio-core/src/lib/runtime/.gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/.gitignore (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/.gitignore b/gnuradio-core/src/lib/runtime/.gitignore new file mode 100644 index 000000000..a02b6ff73 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/.gitignore @@ -0,0 +1,8 @@ +/Makefile +/Makefile.in +/.la +/.lo +/.deps +/.libs +/*.la +/*.lo -- cgit From f67c4ff12f19490d2aeab7ff0fbe0484195037f0 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 1 Aug 2009 09:43:02 -0700 Subject: Added gr_msg_accepter class. gr_msg_accepter derives from gruel::msg_accepter_msgq and will implement in its post() a notification of the destination block thread that a message is pending. Passes distcheck. --- gnuradio-core/src/lib/runtime/Makefile.am | 2 ++ gnuradio-core/src/lib/runtime/gr_basic_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_basic_block.h | 4 +-- gnuradio-core/src/lib/runtime/gr_msg_accepter.cc | 44 ++++++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_msg_accepter.h | 40 +++++++++++++++++++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/gr_msg_accepter.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_msg_accepter.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 14ab464ad..b0e804277 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -44,6 +44,7 @@ libruntime_la_SOURCES = \ gr_io_signature.cc \ gr_local_sighandler.cc \ gr_message.cc \ + gr_msg_accepter.cc \ gr_msg_handler.cc \ gr_msg_queue.cc \ gr_pagesize.cc \ @@ -96,6 +97,7 @@ grinclude_HEADERS = \ gr_io_signature.h \ gr_local_sighandler.h \ gr_message.h \ + gr_msg_accepter.h \ gr_msg_handler.h \ gr_msg_queue.h \ gr_pagesize.h \ diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 71ccc0245..8efa8267a 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -41,7 +41,7 @@ gr_basic_block_ncurrently_allocated() gr_basic_block::gr_basic_block(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature) - : gruel::msg_accepter_msgq(gruel::make_msg_queue(0)), + : gr_msg_accepter(gruel::make_msg_queue(0)), // Non-blocking insert d_name(name), d_input_signature(input_signature), d_output_signature(output_signature), diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 27ec0fd89..5d5b8cbc7 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include /*! @@ -40,7 +40,7 @@ * signal processing functions. */ -class gr_basic_block : gruel::msg_accepter_msgq, public boost::enable_shared_from_this +class gr_basic_block : gr_msg_accepter, public boost::enable_shared_from_this { protected: friend class gr_flowgraph; diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc new file mode 100644 index 000000000..b07f447c9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 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. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include + +using namespace pmt; + +gr_msg_accepter::gr_msg_accepter(gruel::msg_queue_sptr msgq) + : gruel::msg_accepter_msgq(msgq) +{ +} + +gr_msg_accepter::~gr_msg_accepter() +{ + // NOP, required as virtual destructor +} + +void +gr_msg_accepter::post(pmt_t msg) +{ + d_msg_queue->insert_tail(msg); +} diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h new file mode 100644 index 000000000..8ce8d1d9e --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h @@ -0,0 +1,40 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 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_MSG_ACCEPTER_H +#define INCLUDED_GR_MSG_ACCEPTER_H + +#include + +/*! + * \brief Accepts messages and inserts them into a message queue, then notifies + * subclass gr_basic_block there is a message pending. + */ +class gr_msg_accepter : gruel::msg_accepter_msgq +{ +public: + gr_msg_accepter(gruel::msg_queue_sptr msgq); + ~gr_msg_accepter(); + + void post(pmt::pmt_t msg); +}; + +#endif /* INCLUDED_GR_MSG_ACCEPTER_H */ -- cgit From 3d47afffbf216f5ab0fa036de2b70cdc7a1981da Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 4 Aug 2009 10:22:15 -0700 Subject: Notify derived class when post()ed --- gnuradio-core/src/lib/runtime/gr_msg_accepter.cc | 14 +++++++++++++- gnuradio-core/src/lib/runtime/gr_tpb_detail.h | 14 +++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc index b07f447c9..ebe11870a 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc @@ -24,6 +24,8 @@ #endif #include +#include +#include using namespace pmt; @@ -40,5 +42,15 @@ gr_msg_accepter::~gr_msg_accepter() void gr_msg_accepter::post(pmt_t msg) { - d_msg_queue->insert_tail(msg); + // Let parent class do whatever it would have + gruel::msg_accepter_msgq::post(msg); + + // Notify this block's scheduler a message is pending + gr_block *p = dynamic_cast(this); + if (p) + p->detail()->d_tpb.notify_msg(); + else { + // got here somehow with a non-gr_block + throw std::runtime_error("gr_msg_accepter::post() - invalid derived class"); + } } diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h index ab955240b..29101d730 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h @@ -35,10 +35,10 @@ struct gr_tpb_detail { gruel::condition_variable input_cond; bool output_changed; gruel::condition_variable output_cond; + bool msg_pending; gr_tpb_detail() - : input_changed(false), output_changed(false) {} - + : input_changed(false), output_changed(false), msg_pending(false) { } //! Called by us to tell all our upstream blocks that their output may have changed. void notify_upstream(gr_block_detail *d); @@ -57,6 +57,15 @@ struct gr_tpb_detail { output_changed = false; } + //! Called to notify us that a message is pending in the queue + void notify_msg() + { + gruel::scoped_lock guard(mutex); + msg_pending = true; + input_cond.notify_one(); + output_cond.notify_one(); + } + private: //! Used by notify_downstream @@ -74,7 +83,6 @@ private: output_changed = true; output_cond.notify_one(); } - }; #endif /* INCLUDED_GR_TPB_DETAIL_H */ -- cgit From 9a966d18567077d47f3e5bd65871b164805d2665 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 4 Aug 2009 13:17:18 -0700 Subject: Thread-per-block loop now checks and dequeues messages to handle_msg. --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_msg_accepter.cc | 10 +++---- gnuradio-core/src/lib/runtime/gr_msg_accepter.h | 2 +- gnuradio-core/src/lib/runtime/gr_tpb_detail.h | 6 ++-- .../src/lib/runtime/gr_tpb_thread_body.cc | 35 ++++++++++++++++++---- 5 files changed, 40 insertions(+), 15 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 5d5b8cbc7..b8797fdc6 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -40,7 +40,7 @@ * signal processing functions. */ -class gr_basic_block : gr_msg_accepter, public boost::enable_shared_from_this +class gr_basic_block : public gr_msg_accepter, public boost::enable_shared_from_this { protected: friend class gr_flowgraph; diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc index ebe11870a..50b41df88 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc @@ -45,12 +45,12 @@ gr_msg_accepter::post(pmt_t msg) // Let parent class do whatever it would have gruel::msg_accepter_msgq::post(msg); - // Notify this block's scheduler a message is pending + // Notify derived class, handled case by case gr_block *p = dynamic_cast(this); - if (p) + if (p) { p->detail()->d_tpb.notify_msg(); - else { - // got here somehow with a non-gr_block - throw std::runtime_error("gr_msg_accepter::post() - invalid derived class"); + return; } + + // Test for other derived classes and handle } diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h index 8ce8d1d9e..2073e7ff1 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h @@ -28,7 +28,7 @@ * \brief Accepts messages and inserts them into a message queue, then notifies * subclass gr_basic_block there is a message pending. */ -class gr_msg_accepter : gruel::msg_accepter_msgq +class gr_msg_accepter : public gruel::msg_accepter_msgq { public: gr_msg_accepter(gruel::msg_queue_sptr msgq); diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h index 29101d730..a1df55806 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h @@ -35,10 +35,9 @@ struct gr_tpb_detail { gruel::condition_variable input_cond; bool output_changed; gruel::condition_variable output_cond; - bool msg_pending; gr_tpb_detail() - : input_changed(false), output_changed(false), msg_pending(false) { } + : 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); @@ -61,7 +60,8 @@ struct gr_tpb_detail { void notify_msg() { gruel::scoped_lock guard(mutex); - msg_pending = true; + + // Just wake up thread if BLKD_IN or BLKD_OUT input_cond.notify_one(); output_cond.notify_one(); } diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index 458b16d64..c601b588c 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -24,17 +24,23 @@ #include #include #include +#include + +using namespace pmt; 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_detail *d = block->detail().get(); gr_block_executor::state s; while (1){ boost::this_thread::interruption_point(); + + while (!block->msg_queue()->empty_p()) + block->handle_msg(block->msg_queue()->delete_head_nowait()); d->d_tpb.clear_changed(); s = d_exec.run_one_iteration(); @@ -53,18 +59,37 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) return; case gr_block_executor::BLKD_IN: // Wait for input. + while (!d->d_tpb.input_changed) { + boost::this_thread::interruption_point(); gruel::scoped_lock guard(d->d_tpb.mutex); - while(!d->d_tpb.input_changed) - d->d_tpb.input_cond.wait(guard); + + // Block then wake on input_changed or msg arrived + while(!d->d_tpb.input_changed && !block->msg_queue()->empty_p()) + d->d_tpb.input_cond.wait(guard); + + // Run msgq while unlocked + guard.unlock(); + while (!block->msg_queue()->empty_p()) + block->handle_msg(block->msg_queue()->delete_head_nowait()); } break; + case gr_block_executor::BLKD_OUT: // Wait for output buffer space. + while (!d->d_tpb.output_changed) { + boost::this_thread::interruption_point(); gruel::scoped_lock guard(d->d_tpb.mutex); - while(!d->d_tpb.output_changed) - d->d_tpb.output_cond.wait(guard); + + // Block then wake on output_changed or msg arrived + while(!d->d_tpb.output_changed && !block->msg_queue()->empty_p()) + d->d_tpb.output_cond.wait(guard); + + // Run msgq while unlocked + guard.unlock(); + while (!block->msg_queue()->empty_p()) + block->handle_msg(block->msg_queue()->delete_head_nowait()); } break; -- cgit From 1181c2fe069075f9ceb3b66ed937115ff39aafa9 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Thu, 13 Aug 2009 21:50:06 -0700 Subject: Refactored gr_msg_accepter and gr_tpd_thread_body. Redirected gr_msg_accepter::post into gr_block::_post based on dynamic cast. --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 3 +- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 7 +++ gnuradio-core/src/lib/runtime/gr_block_detail.h | 6 +++ gnuradio-core/src/lib/runtime/gr_msg_accepter.cc | 17 +++++--- gnuradio-core/src/lib/runtime/gr_msg_accepter.h | 10 +++-- gnuradio-core/src/lib/runtime/gr_tpb_detail.cc | 45 ++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_tpb_detail.h | 30 +++++++++---- .../src/lib/runtime/gr_tpb_thread_body.cc | 51 ++++++++++++---------- 8 files changed, 125 insertions(+), 44 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 8efa8267a..2fa1066cb 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -41,8 +41,7 @@ gr_basic_block_ncurrently_allocated() gr_basic_block::gr_basic_block(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature) - : gr_msg_accepter(gruel::make_msg_queue(0)), // Non-blocking insert - d_name(name), + : d_name(name), d_input_signature(input_signature), d_output_signature(output_signature), d_unique_id(s_next_id++), diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index ae1ea2562..d33dfed84 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -106,3 +106,10 @@ gr_block_detail::produce_each (int how_many_items) for (int i = 0; i < noutputs (); i++) d_output[i]->update_write_pointer (how_many_items); } + + +void +gr_block_detail::_post(pmt::pmt_t msg) +{ + d_tpb.insert_tail(msg); +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 2856c402c..9d6358602 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -79,6 +79,12 @@ class gr_block_detail { 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 // ---------------------------------------------------------------------------- diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc index 50b41df88..89876ae29 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc @@ -26,11 +26,12 @@ #include #include #include +#include +#include using namespace pmt; -gr_msg_accepter::gr_msg_accepter(gruel::msg_queue_sptr msgq) - : gruel::msg_accepter_msgq(msgq) +gr_msg_accepter::gr_msg_accepter() { } @@ -42,15 +43,17 @@ gr_msg_accepter::~gr_msg_accepter() void gr_msg_accepter::post(pmt_t msg) { - // Let parent class do whatever it would have - gruel::msg_accepter_msgq::post(msg); - // Notify derived class, handled case by case gr_block *p = dynamic_cast(this); if (p) { - p->detail()->d_tpb.notify_msg(); + p->detail()->_post(msg); + return; + } + gr_hier_block2 *p2 = dynamic_cast(this); + if (p2){ + // FIXME do the right thing return; } - // Test for other derived classes and handle + throw std::runtime_error("unknown derived class"); } diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h index 2073e7ff1..79a631f3a 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h @@ -22,19 +22,21 @@ #ifndef INCLUDED_GR_MSG_ACCEPTER_H #define INCLUDED_GR_MSG_ACCEPTER_H -#include +#include +#include /*! * \brief Accepts messages and inserts them into a message queue, then notifies * subclass gr_basic_block there is a message pending. */ -class gr_msg_accepter : public gruel::msg_accepter_msgq +class gr_msg_accepter : public gruel::msg_accepter { public: - gr_msg_accepter(gruel::msg_queue_sptr msgq); + gr_msg_accepter(); ~gr_msg_accepter(); - + void post(pmt::pmt_t msg); + }; #endif /* INCLUDED_GR_MSG_ACCEPTER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc b/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc index 02e8deed8..c6311ccaa 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,6 +27,8 @@ #include #include +using namespace pmt; + /* * We assume that no worker threads are ever running when the * graph structure is being manipulated, thus it's safe for us to poke @@ -65,3 +67,44 @@ gr_tpb_detail::notify_neighbors(gr_block_detail *d) notify_downstream(d); notify_upstream(d); } + +void +gr_tpb_detail::insert_tail(pmt::pmt_t msg) +{ + gruel::scoped_lock guard(mutex); + + msg_queue.push_back(msg); + + // wake up thread if BLKD_IN or BLKD_OUT + input_cond.notify_one(); + output_cond.notify_one(); +} + +pmt_t +gr_tpb_detail::delete_head_nowait() +{ + gruel::scoped_lock guard(mutex); + + if (empty_p()) + return pmt_t(); + + pmt_t m(msg_queue.front()); + msg_queue.pop_front(); + + return m; +} + +/* + * Caller must already be holding the mutex + */ +pmt_t +gr_tpb_detail::delete_head_nowait_already_holding_mutex() +{ + if (empty_p()) + return pmt_t(); + + pmt_t m(msg_queue.front()); + msg_queue.pop_front(); + + return m; +} diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h index a1df55806..acfa264c7 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h @@ -22,6 +22,8 @@ #define INCLUDED_GR_TPB_DETAIL_H #include +#include +#include class gr_block_detail; @@ -36,6 +38,10 @@ struct gr_tpb_detail { bool output_changed; gruel::condition_variable output_cond; +private: + std::deque msg_queue; + +public: gr_tpb_detail() : input_changed(false), output_changed(false) { } @@ -55,16 +61,23 @@ struct gr_tpb_detail { input_changed = false; output_changed = false; } + + //! is the queue empty? + bool empty_p() const { return msg_queue.empty(); } - //! Called to notify us that a message is pending in the queue - void notify_msg() - { - gruel::scoped_lock guard(mutex); + //| Acquires and release the mutex + void insert_tail(pmt::pmt_t msg); - // Just wake up thread if BLKD_IN or BLKD_OUT - input_cond.notify_one(); - output_cond.notify_one(); - } + /*! + * \returns returns pmt at head of queue or pmt_t() if empty. + */ + pmt::pmt_t delete_head_nowait(); + + /*! + * \returns returns pmt at head of queue or pmt_t() if empty. + * Caller must already be holding the mutex + */ + pmt::pmt_t delete_head_nowait_already_holding_mutex(); private: @@ -83,6 +96,7 @@ private: output_changed = true; output_cond.notify_one(); } + }; #endif /* INCLUDED_GR_TPB_DETAIL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index c601b588c..03eef17d9 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -35,12 +35,15 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) gr_block_detail *d = block->detail().get(); gr_block_executor::state s; + pmt_t msg; + while (1){ boost::this_thread::interruption_point(); - while (!block->msg_queue()->empty_p()) - block->handle_msg(block->msg_queue()->delete_head_nowait()); + // handle any queued up messages + while ((msg = d->d_tpb.delete_head_nowait())) + block->handle_msg(msg); d->d_tpb.clear_changed(); s = d_exec.run_one_iteration(); @@ -59,37 +62,41 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) return; case gr_block_executor::BLKD_IN: // Wait for input. - while (!d->d_tpb.input_changed) { - boost::this_thread::interruption_point(); gruel::scoped_lock guard(d->d_tpb.mutex); - - // Block then wake on input_changed or msg arrived - while(!d->d_tpb.input_changed && !block->msg_queue()->empty_p()) - d->d_tpb.input_cond.wait(guard); + while (!d->d_tpb.input_changed){ + + // wait for input or message + while(!d->d_tpb.input_changed && d->d_tpb.empty_p()) + d->d_tpb.input_cond.wait(guard); - // Run msgq while unlocked - guard.unlock(); - while (!block->msg_queue()->empty_p()) - block->handle_msg(block->msg_queue()->delete_head_nowait()); + // handle all pending messages + while ((msg = d->d_tpb.delete_head_nowait_already_holding_mutex())){ + guard.unlock(); // release lock while processing msg + block->handle_msg(msg); + guard.lock(); + } + } } break; case gr_block_executor::BLKD_OUT: // Wait for output buffer space. - while (!d->d_tpb.output_changed) { - boost::this_thread::interruption_point(); gruel::scoped_lock guard(d->d_tpb.mutex); + while (!d->d_tpb.output_changed){ + + // wait for output room or message + while(!d->d_tpb.output_changed && d->d_tpb.empty_p()) + d->d_tpb.output_cond.wait(guard); - // Block then wake on output_changed or msg arrived - while(!d->d_tpb.output_changed && !block->msg_queue()->empty_p()) - d->d_tpb.output_cond.wait(guard); - - // Run msgq while unlocked - guard.unlock(); - while (!block->msg_queue()->empty_p()) - block->handle_msg(block->msg_queue()->delete_head_nowait()); + // handle all pending messages + while ((msg = d->d_tpb.delete_head_nowait_already_holding_mutex())){ + guard.unlock(); // release lock while processing msg + block->handle_msg(msg); + guard.lock(); + } + } } break; -- cgit From 253018c6cdb114f5662a2d7ba8ed748c6e68e3a7 Mon Sep 17 00:00:00 2001 From: git Date: Fri, 14 Aug 2009 18:10:11 +0000 Subject: Added git ignore files auto created from svn:ignore properties. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11592 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/.gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/.gitignore (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/.gitignore b/gnuradio-core/src/lib/runtime/.gitignore new file mode 100644 index 000000000..a02b6ff73 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/.gitignore @@ -0,0 +1,8 @@ +/Makefile +/Makefile.in +/.la +/.lo +/.deps +/.libs +/*.la +/*.lo -- cgit From 1579bab2e5840e8f7e7918b7cabf250ca4fd259a Mon Sep 17 00:00:00 2001 From: eb Date: Sat, 15 Aug 2009 17:39:10 +0000 Subject: gr_blocks may now produce different number of output items on each output stream. Merged eb/varying -r11178:11595 into trunk. Needs QA and examples. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11597 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/runtime/gr_block.cc | 8 +++++++- gnuradio-core/src/lib/runtime/gr_block.h | 19 ++++++++++++++++--- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 18 +++++++++++++++--- gnuradio-core/src/lib/runtime/gr_block_detail.h | 9 ++++++++- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 13 ++++++++----- 5 files changed, 54 insertions(+), 13 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') 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. */ @@ -149,6 +155,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 * @@ -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 ae1ea2562..f36a6c215 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) { @@ -99,10 +100,21 @@ gr_block_detail::consume_each (int how_many_items) d_input[i]->update_read_pointer (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 2856c402c..f32a875ec 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 * @@ -73,13 +73,20 @@ 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); + 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; } -- cgit From 3e366411a75b47eff5f76c76beb1f3a47006f6c7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 3 Nov 2009 13:01:48 -0800 Subject: fixed fixme in gr_top_block_impl --- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 6 +++--- gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 50d480d00..9cad687fb 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -90,7 +90,7 @@ gr_top_block_impl::~gr_top_block_impl() void gr_top_block_impl::start() { - gr_lock_guard l(d_mutex); + gruel::scoped_lock l(d_mutex); if (d_state != IDLE) throw std::runtime_error("top_block::start: top block already running or wait() not called after previous stop()"); @@ -131,14 +131,14 @@ gr_top_block_impl::wait() void gr_top_block_impl::lock() { - gr_lock_guard lock(d_mutex); + gruel::scoped_lock lock(d_mutex); d_lock_count++; } void gr_top_block_impl::unlock() { - gr_lock_guard lock(d_mutex); + gruel::scoped_lock lock(d_mutex); if (d_lock_count <= 0){ d_lock_count = 0; // fix it, then complain diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 35fb44ef9..ef28dd829 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -24,10 +24,7 @@ #define INCLUDED_GR_TOP_BLOCK_IMPL_H #include -#include - -typedef boost::mutex gr_mutex; // FIXME move these elsewhere -typedef boost::lock_guard gr_lock_guard; +#include /*! *\brief Abstract implementation details of gr_top_block @@ -69,7 +66,7 @@ protected: gr_flat_flowgraph_sptr d_ffg; gr_scheduler_sptr d_scheduler; - gr_mutex d_mutex; // protects d_state and d_lock_count + gruel::mutex d_mutex; // protects d_state and d_lock_count tb_state d_state; int d_lock_count; -- cgit From fa56c39802a82e6e0e730813a57e86e1aea09a24 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 3 Aug 2010 11:54:25 -0700 Subject: fix scoped_lock that didn't ref mutex --- gnuradio-core/src/lib/runtime/gr_sptr_magic.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc index 96ffae85f..b0351248c 100644 --- a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc @@ -39,7 +39,7 @@ namespace gnuradio { detail::sptr_magic::create_and_stash_initial_sptr(gr_hier_block2 *p) { gr_basic_block_sptr sptr(p); - gruel::scoped_lock guard(); + gruel::scoped_lock guard(s_mutex); s_map.insert(sptr_map::value_type(static_cast(p), sptr)); } @@ -60,7 +60,7 @@ namespace gnuradio { * p is a subclass of gr_hier_block2, thus we've already created the shared pointer * and stashed it away. Fish it out and return it. */ - gruel::scoped_lock guard(); + gruel::scoped_lock guard(s_mutex); sptr_map::iterator pos = s_map.find(static_cast(p)); if (pos == s_map.end()) throw std::invalid_argument("gr_sptr_magic: invalid pointer!"); -- cgit From 2b8bd0d2fa7c76282a772b75cb99e7bd5f2be13f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 2 Oct 2010 17:16:04 -0400 Subject: Moving XML output files from cppunit tests to $HOME/.gnuradio/unittests. This also adds a new utility gr_unittests.h, which sets up the path for output files. --- gnuradio-core/src/lib/runtime/Makefile.am | 1 + gnuradio-core/src/lib/runtime/gr_unittests.h | 70 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/gr_unittests.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index b0e804277..abd789a1d 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -120,6 +120,7 @@ grinclude_HEADERS = \ gr_timer.h \ gr_tmp_path.h \ gr_types.h \ + gr_unittests.h \ gr_vmcircbuf.h noinst_HEADERS = \ diff --git a/gnuradio-core/src/lib/runtime/gr_unittests.h b/gnuradio-core/src/lib/runtime/gr_unittests.h new file mode 100644 index 000000000..680e59ca4 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_unittests.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + + +#ifdef MKDIR_TAKES_ONE_ARG +#define gr_mkdir(pathname, mode) mkdir(pathname) +#else +#define gr_mkdir(pathname, mode) mkdir((pathname), (mode)) +#endif + +/* + * Mostly taken from gr_preferences.cc/h + * The simplest thing that could possibly work: + * the key is the filename; the value is the file contents. + */ + +static void +ensure_unittest_path (const char *grpath, const char *path) +{ + struct stat statbuf; + if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) + return; + + // blindly try to make it // FIXME make this robust. C++ SUCKS! + gr_mkdir (grpath, 0750); + gr_mkdir (path, 0750); +} + +static void +get_unittest_path (const char *filename, char *fullpath, size_t pathsize) +{ + char path[200]; + char grpath[200]; + snprintf (grpath, sizeof(grpath), "%s/.gnuradio", getenv ("HOME")); + snprintf (path, sizeof(path), "%s/unittests", grpath); + snprintf (fullpath, pathsize, "%s/%s", path, filename); + + ensure_unittest_path(grpath, path); +} + -- cgit From cb2fa9a58c9a52f3501881964ee4f59992c5d84d Mon Sep 17 00:00:00 2001 From: Michael Dickens Date: Sat, 9 Oct 2010 16:11:03 -0400 Subject: rearrange includes to always be: internal GR, external, with GR. --- gnuradio-core/src/lib/runtime/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index abd789a1d..f67e8843d 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2003,2004,2007,2008,2009 Free Software Foundation, Inc. +# Copyright 2003,2004,2007,2008,2009,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -21,7 +21,7 @@ include $(top_srcdir)/Makefile.common -AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(GRUEL_INCLUDES) $(WITH_INCLUDES) +AM_CPPFLAGS = $(GRUEL_INCLUDES) $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) noinst_LTLIBRARIES = libruntime.la libruntime-qa.la -- cgit From 2c544567f5f9322b51b26a32bdb6280ee12f16de Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 19 Oct 2010 16:33:40 -0400 Subject: Adding vectors to gr_block_detail that keep track of the number of samples read and written from each block's input. Accessor functions allow query of values through gr_block. Had to add gr_uint64 typedef to SWIG for it to understand how to handle the type. --- gnuradio-core/src/lib/runtime/gr_block.cc | 10 ++++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 6 ++++++ gnuradio-core/src/lib/runtime/gr_block.i | 3 +++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 23 ++++++++++++++++++----- gnuradio-core/src/lib/runtime/gr_block_detail.h | 16 ++++++++++++++++ 5 files changed, 53 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 8915f3360..83cc58738 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -117,6 +117,16 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) throw std::runtime_error("Unimplemented"); } +gr_uint64 +gr_block::n_items_read(unsigned int which_input) { + return d_detail->n_items_read(which_input); +} + +gr_uint64 +gr_block::n_items_written(unsigned int which_output) { + return d_detail->n_items_written(which_output); +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index b6f724dde..22e60da57 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -198,6 +198,12 @@ class gr_block : public gr_basic_block { */ virtual int fixed_rate_noutput_to_ninput(int noutput); + // Return the number of items read on input stream which_input + gr_uint64 n_items_read(unsigned int which_input); + + // Return the number of items written on output stream which_output + gr_uint64 n_items_written(unsigned int which_output); + // ---------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index c2e2aa4b8..d70a5854a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -49,6 +49,9 @@ class gr_block : public gr_basic_block { bool start(); bool stop(); + gr_uint64 n_items_read(unsigned int which_input); + gr_uint64 n_items_written(unsigned int which_output); + // internal use gr_block_detail_sptr detail () const { return d_detail; } void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 38d4a13ca..1f80fe2d4 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -39,6 +39,7 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_produce_or(0), d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), + d_n_items_read(ninputs, 0), d_n_items_written(noutputs, 0), d_done (false) { s_ncurrently_allocated++; @@ -88,16 +89,25 @@ gr_block_detail::set_done (bool done) void gr_block_detail::consume (int which_input, int how_many_items) { - if (how_many_items > 0) + if (how_many_items > 0) { input (which_input)->update_read_pointer (how_many_items); + + // Carefull here; we check that which_input exists above + // is this good enough protection that we don't get here? + d_n_items_read[which_input] += how_many_items; + } } + void gr_block_detail::consume_each (int how_many_items) { - if (how_many_items > 0) - for (int i = 0; i < ninputs (); i++) + if (how_many_items > 0) { + for (int i = 0; i < ninputs (); i++) { d_input[i]->update_read_pointer (how_many_items); + d_n_items_read[i] += how_many_items; + } + } } void @@ -105,6 +115,7 @@ 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_n_items_written[which_output] += how_many_items; d_produce_or |= how_many_items; } } @@ -112,9 +123,11 @@ gr_block_detail::produce (int which_output, int how_many_items) void gr_block_detail::produce_each (int how_many_items) { - if (how_many_items > 0){ - for (int i = 0; i < noutputs (); i++) + if (how_many_items > 0) { + for (int i = 0; i < noutputs (); i++) { d_output[i]->update_write_pointer (how_many_items); + d_n_items_written[i] += 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 c5787a5ad..e830ddd47 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -88,6 +88,20 @@ class gr_block_detail { */ void _post(pmt::pmt_t msg); + // Return the number of items read on input stream which_input + gr_uint64 n_items_read(unsigned int which_input) { + if(which_input >= d_ninputs) + throw std::invalid_argument ("gr_block_detail::n_input_items"); + return d_n_items_read[which_input]; + } + + // Return the number of items written on output stream which_output + gr_uint64 n_items_written(unsigned int which_output) { + if(which_output >= d_noutputs) + throw std::invalid_argument ("gr_block_detail::n_output_items"); + return d_n_items_written[which_output]; + } + gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -98,6 +112,8 @@ class gr_block_detail { unsigned int d_noutputs; std::vector d_input; std::vector d_output; + std::vector d_n_items_read; + std::vector d_n_items_written; bool d_done; -- cgit From b22efee47c7d891a8c10b1493f20976534fdb751 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 26 Oct 2010 19:59:42 -0400 Subject: Giving gr_block_detail a list of pmt tuples to hold item tagging information. Adds ability to add new tags from a block. --- gnuradio-core/src/lib/runtime/gr_block.cc | 8 ++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 5 +++++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 18 ++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block_detail.h | 7 +++++++ 4 files changed, 38 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 83cc58738..ed848e3ed 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -127,6 +127,14 @@ gr_block::n_items_written(unsigned int which_output) { return d_detail->n_items_written(which_output); } +void +gr_block::add_item_tag(unsigned int which_output, + uint64_t offset, + const pmt::pmt_t &key, const pmt::pmt_t &value) +{ + d_detail->add_item_tag(which_output, offset, key, value); +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 22e60da57..c4d639314 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -204,6 +204,11 @@ class gr_block : public gr_basic_block { // Return the number of items written on output stream which_output gr_uint64 n_items_written(unsigned int which_output); + void add_item_tag(unsigned int which_output, + uint64_t offset, + const pmt::pmt_t &key, const pmt::pmt_t &value); + + // ---------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 1f80fe2d4..656cdb13a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -138,3 +138,21 @@ gr_block_detail::_post(pmt::pmt_t msg) { d_tpb.insert_tail(msg); } + +void +gr_block_detail::add_item_tag(unsigned int which_output, + uint64_t offset, + const pmt::pmt_t &key, const pmt::pmt_t &value) +{ + if(pmt::pmt_is_symbol(key) == false) { + throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); + } + else { + pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); + pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); + pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); + d_item_tags.push_back(tuple); + + // need to add prunning routing + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index e830ddd47..6a8d94c72 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -101,6 +101,12 @@ class gr_block_detail { throw std::invalid_argument ("gr_block_detail::n_output_items"); return d_n_items_written[which_output]; } + + // Add an item tag tuple to list of tags + // -> is this just based on output stream? how to handle this... + void add_item_tag(unsigned int which_output, + uint64_t offset, + const pmt::pmt_t &key, const pmt::pmt_t &value); gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -114,6 +120,7 @@ class gr_block_detail { std::vector d_output; std::vector d_n_items_read; std::vector d_n_items_written; + std::list d_item_tags; bool d_done; -- cgit From d07a944f0c327b255285a8fef4604b65fa8fd7c8 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 26 Oct 2010 21:01:22 -0400 Subject: First stab at adding get functions for item tags in a given range. --- gnuradio-core/src/lib/runtime/gr_block.cc | 17 ++++++++++- gnuradio-core/src/lib/runtime/gr_block.h | 9 +++++- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 38 +++++++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_block_detail.h | 9 +++++- 4 files changed, 69 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index ed848e3ed..a2b495867 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -129,12 +129,27 @@ gr_block::n_items_written(unsigned int which_output) { void gr_block::add_item_tag(unsigned int which_output, - uint64_t offset, + gr_uint64 offset, const pmt::pmt_t &key, const pmt::pmt_t &value) { d_detail->add_item_tag(which_output, offset, key, value); } +std::list +gr_block::get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end) +{ + return d_detail->get_tags_in_range(which_output, start, end); +} + +std::list +gr_block::get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end, + const pmt::pmt_t &key) +{ + return d_detail->get_tags_in_range(which_output, start, end, key); +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index c4d639314..888ca811a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -24,6 +24,7 @@ #define INCLUDED_GR_BLOCK_H #include +#include /*! * \brief The abstract base class for all 'terminal' processing blocks. @@ -205,9 +206,15 @@ class gr_block : public gr_basic_block { gr_uint64 n_items_written(unsigned int which_output); void add_item_tag(unsigned int which_output, - uint64_t offset, + gr_uint64 offset, const pmt::pmt_t &key, const pmt::pmt_t &value); + std::list get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end); + + std::list get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end, + const pmt::pmt_t &key); // ---------------------------------------------------------------------------- diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 656cdb13a..dbe49f37c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -141,7 +141,7 @@ gr_block_detail::_post(pmt::pmt_t msg) void gr_block_detail::add_item_tag(unsigned int which_output, - uint64_t offset, + gr_uint64 offset, const pmt::pmt_t &key, const pmt::pmt_t &value) { if(pmt::pmt_is_symbol(key) == false) { @@ -156,3 +156,39 @@ gr_block_detail::add_item_tag(unsigned int which_output, // need to add prunning routing } } + +std::list +gr_block_detail::get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end) +{ + std::list found_items; + std::list::iterator itr = d_item_tags.begin(); + + gr_uint64 item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + while(itr != d_item_tags.end()) { + if((item_time < start) && (item_time < end)) { + found_items.push_back(*itr); + } + + itr++; + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + + // items are pushed onto list in sequential order; stop if we're past end + if(item_time > end) { + break; + } + } + + return found_items; +} + +std::list +gr_block_detail::get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end, + const pmt::pmt_t &key) +{ + std::list found_items; + std::list::iterator itr = d_item_tags.begin(); + + return found_items; +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 6a8d94c72..cb590cec9 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -105,9 +105,16 @@ class gr_block_detail { // Add an item tag tuple to list of tags // -> is this just based on output stream? how to handle this... void add_item_tag(unsigned int which_output, - uint64_t offset, + gr_uint64 offset, const pmt::pmt_t &key, const pmt::pmt_t &value); + std::list get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end); + + std::list get_tags_in_range(unsigned int which_output, + gr_uint64 start, gr_uint64 end, + const pmt::pmt_t &key); + gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; -- cgit From e3b866883186ed2fbf125964a7ca3a3a3022675c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 17:02:10 -0400 Subject: Fix to get_tags_in_range. Returns proper list and handles times when list is empty. --- gnuradio-core/src/lib/runtime/gr_block.cc | 6 ++++-- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index a2b495867..f3e0ecc91 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -118,12 +118,14 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) } gr_uint64 -gr_block::n_items_read(unsigned int which_input) { +gr_block::n_items_read(unsigned int which_input) +{ return d_detail->n_items_read(which_input); } gr_uint64 -gr_block::n_items_written(unsigned int which_output) { +gr_block::n_items_written(unsigned int which_output) +{ return d_detail->n_items_written(which_output); } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index dbe49f37c..6a920f7c0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -164,19 +164,20 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, std::list found_items; std::list::iterator itr = d_item_tags.begin(); - gr_uint64 item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + gr_uint64 item_time; while(itr != d_item_tags.end()) { - if((item_time < start) && (item_time < end)) { - found_items.push_back(*itr); - } - - itr++; item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); // items are pushed onto list in sequential order; stop if we're past end if(item_time > end) { break; } + + if((item_time > start) && (item_time < end)) { + found_items.push_back(*itr); + } + + itr++; } return found_items; -- cgit From e6dedf7fb1075e22e8ea46c9c8d456ba92f92df1 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 17:11:34 -0400 Subject: Adds functional ability to call get_tags_in_range with a specified key. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 6a920f7c0..18f3601fc 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -191,5 +191,23 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, std::list found_items; std::list::iterator itr = d_item_tags.begin(); + gr_uint64 item_time; + pmt::pmt_t itemkey; + while(itr != d_item_tags.end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + + // items are pushed onto list in sequential order; stop if we're past end + if(item_time > end) { + break; + } + + itemkey = pmt::pmt_tuple_ref(*itr, 2); + if((item_time > start) && (item_time < end) && (key == itemkey)) { + found_items.push_back(*itr); + } + + itr++; + } + return found_items; } -- cgit From 246c0b96f22b3eb945fb1cef1aafd32bbb7cd815 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 17:13:36 -0400 Subject: get_tags_in_range now gets items between start and end INCLUSIVELY. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 18f3601fc..69f65f0d0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -173,7 +173,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, break; } - if((item_time > start) && (item_time < end)) { + if((item_time >= start) && (item_time <= end)) { found_items.push_back(*itr); } @@ -202,7 +202,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, } itemkey = pmt::pmt_tuple_ref(*itr, 2); - if((item_time > start) && (item_time < end) && (key == itemkey)) { + if((item_time >= start) && (item_time <= end) && (key == itemkey)) { found_items.push_back(*itr); } -- cgit From 13f00f0ad96ee54a98751f9dceca005078850c93 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 18:06:39 -0400 Subject: Checks for duplicate entry when adding a new tag. add_item_tag looks at the last tag entered with the given key and tests if the value is the same. If it is the same value, then don't do add a new item. If the value is different, add a new tag of that key to the list. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 32 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 69f65f0d0..1007f13ef 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -142,18 +142,38 @@ gr_block_detail::_post(pmt::pmt_t msg) void gr_block_detail::add_item_tag(unsigned int which_output, gr_uint64 offset, - const pmt::pmt_t &key, const pmt::pmt_t &value) + const pmt::pmt_t &key, + const pmt::pmt_t &value) { if(pmt::pmt_is_symbol(key) == false) { throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { - pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); - pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); - pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); - d_item_tags.push_back(tuple); + bool duplicate = false; + + // Search through list of tags to see if new tag is a duplicate + std::list::reverse_iterator itr = d_item_tags.rbegin(); + while(itr != d_item_tags.rend()) { + // find the last item with this key if there is one + if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 2), key)) { + // check if this value is the same as last; its a duplicate if yes + if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 3), value)) { + duplicate = true; + } + break; // only looking for the last item of this key + } + itr++; + } + + // It not a duplicate, add new tag to the list + if(!duplicate) { + pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); + pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); + pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); + d_item_tags.push_back(tuple); + } - // need to add prunning routing + // need to add prunning routine } } -- cgit From 0bc7116e5227f95b7a5de944bc65c5a8b55e0ed5 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 31 Oct 2010 18:09:19 -0400 Subject: Using pmt_eqv for key testing instead of == to make sure typing is worked out properly. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 1007f13ef..effaf5269 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -222,7 +222,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, } itemkey = pmt::pmt_tuple_ref(*itr, 2); - if((item_time >= start) && (item_time <= end) && (key == itemkey)) { + if((item_time >= start) && (item_time <= end) && pmt::pmt_eqv(key, itemkey)) { found_items.push_back(*itr); } -- cgit From 428ccb2218464a33923b3e576ad42af21468c82d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Nov 2010 15:59:51 -0400 Subject: Adding some protection to the nitems read/written accessors. Should this return 0 or throw? --- gnuradio-core/src/lib/runtime/gr_block.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index f3e0ecc91..e0a223135 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -120,13 +120,25 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) gr_uint64 gr_block::n_items_read(unsigned int which_input) { - return d_detail->n_items_read(which_input); + if(d_detail) { + return d_detail->n_items_read(which_input); + } + else { + //throw std::runtime_error("No block_detail associated with block yet"); + return 0; + } } gr_uint64 gr_block::n_items_written(unsigned int which_output) { - return d_detail->n_items_written(which_output); + if(d_detail) { + return d_detail->n_items_written(which_output); + } + else { + //throw std::runtime_error("No block_detail associated with block yet"); + return 0; + } } void -- cgit From 1c7119f52792da359fc5638a589b8cc8fa959864 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Nov 2010 16:00:51 -0400 Subject: Adding QA code to perform some tests on tags. Setting and getting items read/written; testing adding and retrieving tags. --- gnuradio-core/src/lib/runtime/Makefile.am | 2 + gnuradio-core/src/lib/runtime/qa_block_tags.cc | 118 +++++++++++++++++++++++++ gnuradio-core/src/lib/runtime/qa_block_tags.h | 44 +++++++++ gnuradio-core/src/lib/runtime/qa_runtime.cc | 2 + 4 files changed, 166 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/qa_block_tags.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_block_tags.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index abd789a1d..4c52f3ab0 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -79,6 +79,7 @@ libruntime_qa_la_SOURCES = \ qa_gr_top_block.cc \ qa_gr_io_signature.cc \ qa_gr_vmcircbuf.cc \ + qa_block_tags.cc \ qa_runtime.cc grinclude_HEADERS = \ @@ -136,6 +137,7 @@ noinst_HEADERS = \ qa_gr_io_signature.h \ qa_gr_top_block.h \ qa_gr_vmcircbuf.h \ + qa_block_tags.h \ qa_runtime.h if PYTHON diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc new file mode 100644 index 000000000..c9ec788b0 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -0,0 +1,118 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include + + +// ---------------------------------------------------------------- + + +void +qa_block_tags::t0 () +{ + printf("\nqa_block_tags::t0\n"); + + unsigned int N = 1000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_block_sptr snk (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, snk, 0); + + //CPPUNIT_ASSERT_THROW(src->n_items_read(0), std::runtime_error); + //CPPUNIT_ASSERT_THROW(src->n_items_written(0), std::runtime_error); + CPPUNIT_ASSERT_EQUAL(src->n_items_read(0), (gr_uint64)0); + CPPUNIT_ASSERT_EQUAL(src->n_items_written(0), (gr_uint64)0); + + tb->run(); + + CPPUNIT_ASSERT_THROW(src->n_items_read(0), std::invalid_argument); + CPPUNIT_ASSERT(src->n_items_written(0) >= N); + CPPUNIT_ASSERT_EQUAL(snk->n_items_read(0), (gr_uint64)1000); + CPPUNIT_ASSERT_THROW(snk->n_items_written(0), std::invalid_argument); +} + + +void +qa_block_tags::t1 () +{ + printf("\nqa_block_tags::t1\n"); + + int N = 1000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_block_sptr snk (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, snk, 0); + tb->run(); + + gr_uint64 W = src->n_items_written(0); + src->add_item_tag(0, N, + pmt::pmt_string_to_symbol("test1"), + pmt::pmt_from_double(1.234)); + + // Make sure we can't get duplicates + src->add_item_tag(0, N, + pmt::pmt_string_to_symbol("test1"), + pmt::pmt_from_double(1.234)); + + // Add new tag at another position + src->add_item_tag(0, W, + pmt::pmt_string_to_symbol("test2"), + pmt::pmt_from_double(2.345)); + + // Test how many tags we get for different ranges + // should be 1, 0, 0, and 2 + std::list tags0, tags1, tags2, tags3; + tags0 = src->get_tags_in_range(0, N-10, N+10); + tags1 = src->get_tags_in_range(0, N-10, N- 1); + tags2 = src->get_tags_in_range(0, N+ 1, N+10); + tags3 = src->get_tags_in_range(0, 0, W); + + CPPUNIT_ASSERT(tags0.size() == 1); + CPPUNIT_ASSERT(tags1.size() == 0); + CPPUNIT_ASSERT(tags2.size() == 0); + CPPUNIT_ASSERT(tags3.size() == 2); + + // Check types and values are good + pmt::pmt_t tuple = tags0.front(); + pmt::pmt_t key = pmt::pmt_tuple_ref(tuple, 2); + double value = pmt::pmt_to_double(pmt::pmt_tuple_ref(tuple, 3)); + + CPPUNIT_ASSERT(pmt::pmt_is_tuple(tuple)); + CPPUNIT_ASSERT(pmt::pmt_eqv(key, pmt::pmt_string_to_symbol("test1"))); + CPPUNIT_ASSERT_EQUAL(value, 1.234); +} + diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h new file mode 100644 index 000000000..b7388885f --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_QA_BLOCK_TAGS_H +#define INCLUDED_QA_BLOCK_TAGS_H + +#include +#include +#include + +class qa_block_tags : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE (qa_block_tags); + CPPUNIT_TEST (t0); + CPPUNIT_TEST (t1); + CPPUNIT_TEST_SUITE_END (); + + private: + void t0 (); + void t1 (); + +}; + + +#endif /* INCLUDED_QA_BLOCK_TAGS_H */ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 31e3a82d6..967d4bfa8 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -38,6 +38,7 @@ #include #include #include +#include CppUnit::TestSuite * qa_runtime::suite () @@ -52,6 +53,7 @@ qa_runtime::suite () s->addTest (qa_gr_hier_block2::suite ()); s->addTest (qa_gr_hier_block2_derived::suite ()); s->addTest (qa_gr_buffer::suite ()); + s->addTest (qa_block_tags::suite ()); return s; } -- cgit From e70f8a0d50474784c1f1b64b94907feb9b913a2b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Nov 2010 19:57:24 -0400 Subject: Moved number items read/written from gr_block_detail into gr_buffer (abs_written_offset) and gr_buffer_reader (abs_read_offset). Keeps the API exposed in gr_blocks for now. --- gnuradio-core/src/lib/runtime/gr_block.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 24 ++++++++++++++++-------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 14 ++------------ gnuradio-core/src/lib/runtime/gr_buffer.cc | 5 +++-- gnuradio-core/src/lib/runtime/gr_buffer.h | 10 +++++++++- 5 files changed, 32 insertions(+), 25 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index e0a223135..c00a034de 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -121,7 +121,7 @@ gr_uint64 gr_block::n_items_read(unsigned int which_input) { if(d_detail) { - return d_detail->n_items_read(which_input); + return d_detail->nitems_read(which_input); } else { //throw std::runtime_error("No block_detail associated with block yet"); @@ -133,7 +133,7 @@ gr_uint64 gr_block::n_items_written(unsigned int which_output) { if(d_detail) { - return d_detail->n_items_written(which_output); + return d_detail->nitems_written(which_output); } else { //throw std::runtime_error("No block_detail associated with block yet"); diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index effaf5269..d12d808e9 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -39,7 +39,6 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_produce_or(0), d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), - d_n_items_read(ninputs, 0), d_n_items_written(noutputs, 0), d_done (false) { s_ncurrently_allocated++; @@ -91,10 +90,6 @@ gr_block_detail::consume (int which_input, int how_many_items) { if (how_many_items > 0) { input (which_input)->update_read_pointer (how_many_items); - - // Carefull here; we check that which_input exists above - // is this good enough protection that we don't get here? - d_n_items_read[which_input] += how_many_items; } } @@ -105,7 +100,6 @@ gr_block_detail::consume_each (int how_many_items) if (how_many_items > 0) { for (int i = 0; i < ninputs (); i++) { d_input[i]->update_read_pointer (how_many_items); - d_n_items_read[i] += how_many_items; } } } @@ -115,7 +109,6 @@ 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_n_items_written[which_output] += how_many_items; d_produce_or |= how_many_items; } } @@ -126,7 +119,6 @@ gr_block_detail::produce_each (int how_many_items) if (how_many_items > 0) { for (int i = 0; i < noutputs (); i++) { d_output[i]->update_write_pointer (how_many_items); - d_n_items_written[i] += how_many_items; } d_produce_or |= how_many_items; } @@ -139,6 +131,22 @@ gr_block_detail::_post(pmt::pmt_t msg) d_tpb.insert_tail(msg); } +gr_uint64 +gr_block_detail::nitems_read(unsigned int which_input) +{ + if(which_input >= d_ninputs) + throw std::invalid_argument ("gr_block_detail::n_input_items"); + return d_input[which_input]->nitems_read(); +} + +gr_uint64 +gr_block_detail::nitems_written(unsigned int which_output) +{ + if(which_output >= d_noutputs) + throw std::invalid_argument ("gr_block_detail::n_output_items"); + return d_output[which_output]->nitems_written(); +} + void gr_block_detail::add_item_tag(unsigned int which_output, gr_uint64 offset, diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index cb590cec9..ee226a349 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -89,18 +89,10 @@ class gr_block_detail { void _post(pmt::pmt_t msg); // Return the number of items read on input stream which_input - gr_uint64 n_items_read(unsigned int which_input) { - if(which_input >= d_ninputs) - throw std::invalid_argument ("gr_block_detail::n_input_items"); - return d_n_items_read[which_input]; - } + gr_uint64 nitems_read(unsigned int which_input); // Return the number of items written on output stream which_output - gr_uint64 n_items_written(unsigned int which_output) { - if(which_output >= d_noutputs) - throw std::invalid_argument ("gr_block_detail::n_output_items"); - return d_n_items_written[which_output]; - } + gr_uint64 nitems_written(unsigned int which_output); // Add an item tag tuple to list of tags // -> is this just based on output stream? how to handle this... @@ -125,8 +117,6 @@ class gr_block_detail { unsigned int d_noutputs; std::vector d_input; std::vector d_output; - std::vector d_n_items_read; - std::vector d_n_items_written; std::list d_item_tags; bool d_done; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index db2db5d6d..42d00e06f 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -80,7 +80,7 @@ minimum_buffer_items (long type_size, long page_size) gr_buffer::gr_buffer (int nitems, size_t sizeof_item, gr_block_sptr link) : d_base (0), d_bufsize (0), d_vmcircbuf (0), d_sizeof_item (sizeof_item), d_link(link), - d_write_index (0), d_done (false) + d_write_index (0), d_abs_write_offset(0), d_done (false) { if (!allocate_buffer (nitems, sizeof_item)) throw std::bad_alloc (); @@ -225,7 +225,7 @@ gr_buffer_ncurrently_allocated () gr_buffer_reader::gr_buffer_reader(gr_buffer_sptr buffer, unsigned int read_index, gr_block_sptr link) - : d_buffer(buffer), d_read_index(read_index), d_link(link) + : d_buffer(buffer), d_read_index(read_index), d_abs_read_offset(0), d_link(link) { s_buffer_reader_count++; } @@ -253,6 +253,7 @@ gr_buffer_reader::update_read_pointer (int nitems) { gruel::scoped_lock guard(*mutex()); d_read_index = d_buffer->index_add (d_read_index, nitems); + d_abs_read_offset += nitems; } long diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 207bfe7c5..8af72741a 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -88,6 +88,8 @@ class gr_buffer { gruel::mutex *mutex() { return &d_mutex; } + gr_uint64 nitems_written() { return d_abs_write_offset; } + // ------------------------------------------------------------------------- private: @@ -106,10 +108,13 @@ class gr_buffer { boost::weak_ptr d_link; // block that writes to this buffer // - // The mutex protects d_write_index, d_done and the d_read_index's in the buffer readers. + // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's + // and d_abs_read_offset's in the buffer readers. // gruel::mutex d_mutex; unsigned int d_write_index; // in items [0,d_bufsize) + gr_uint64 d_abs_write_offset; // num items written since the start + //deq tag_tuples bool d_done; unsigned @@ -220,6 +225,8 @@ class gr_buffer_reader { gruel::mutex *mutex() { return d_buffer->mutex(); } + gr_uint64 nitems_read() { return d_abs_read_offset; } + /*! * \brief Return the block that reads via this reader. */ @@ -236,6 +243,7 @@ class gr_buffer_reader { gr_buffer_sptr d_buffer; unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) + gr_uint64 d_abs_read_offset; // num items seen since the start boost::weak_ptr d_link; // block that reads via this buffer reader //! constructor is private. Use gr_buffer::add_reader to create instances -- cgit From c3725a7269a7e96252a957b6d078686352365de6 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 11:38:27 -0400 Subject: Fixing buffer to update abs_write_offset counter. Keeping access to counters exposed through gr_block for now, just remaining to nitem_*. --- gnuradio-core/src/lib/runtime/gr_block.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_block.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_block.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_buffer.cc | 1 + gnuradio-core/src/lib/runtime/qa_block_tags.cc | 18 +++++++++--------- 5 files changed, 16 insertions(+), 15 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index c00a034de..13035aa96 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -118,7 +118,7 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) } gr_uint64 -gr_block::n_items_read(unsigned int which_input) +gr_block::nitems_read(unsigned int which_input) { if(d_detail) { return d_detail->nitems_read(which_input); @@ -130,7 +130,7 @@ gr_block::n_items_read(unsigned int which_input) } gr_uint64 -gr_block::n_items_written(unsigned int which_output) +gr_block::nitems_written(unsigned int which_output) { if(d_detail) { return d_detail->nitems_written(which_output); diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 888ca811a..7564acd87 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -200,10 +200,10 @@ class gr_block : public gr_basic_block { virtual int fixed_rate_noutput_to_ninput(int noutput); // Return the number of items read on input stream which_input - gr_uint64 n_items_read(unsigned int which_input); + gr_uint64 nitems_read(unsigned int which_input); // Return the number of items written on output stream which_output - gr_uint64 n_items_written(unsigned int which_output); + gr_uint64 nitems_written(unsigned int which_output); void add_item_tag(unsigned int which_output, gr_uint64 offset, diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index d70a5854a..4684bd2f2 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -49,8 +49,8 @@ class gr_block : public gr_basic_block { bool start(); bool stop(); - gr_uint64 n_items_read(unsigned int which_input); - gr_uint64 n_items_written(unsigned int which_output); + gr_uint64 nitems_read(unsigned int which_input); + gr_uint64 nitems_written(unsigned int which_output); // internal use gr_block_detail_sptr detail () const { return d_detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 42d00e06f..89db99b69 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -177,6 +177,7 @@ gr_buffer::update_write_pointer (int nitems) { gruel::scoped_lock guard(*mutex()); d_write_index = index_add (d_write_index, nitems); + d_abs_write_offset += nitems; } void diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index c9ec788b0..73faa6ca7 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -49,17 +49,17 @@ qa_block_tags::t0 () tb->connect(src, 0, head, 0); tb->connect(head, 0, snk, 0); - //CPPUNIT_ASSERT_THROW(src->n_items_read(0), std::runtime_error); - //CPPUNIT_ASSERT_THROW(src->n_items_written(0), std::runtime_error); - CPPUNIT_ASSERT_EQUAL(src->n_items_read(0), (gr_uint64)0); - CPPUNIT_ASSERT_EQUAL(src->n_items_written(0), (gr_uint64)0); + //CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::runtime_error); + //CPPUNIT_ASSERT_THROW(src->nitems_written(0), std::runtime_error); + CPPUNIT_ASSERT_EQUAL(src->nitems_read(0), (gr_uint64)0); + CPPUNIT_ASSERT_EQUAL(src->nitems_written(0), (gr_uint64)0); tb->run(); - CPPUNIT_ASSERT_THROW(src->n_items_read(0), std::invalid_argument); - CPPUNIT_ASSERT(src->n_items_written(0) >= N); - CPPUNIT_ASSERT_EQUAL(snk->n_items_read(0), (gr_uint64)1000); - CPPUNIT_ASSERT_THROW(snk->n_items_written(0), std::invalid_argument); + CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::invalid_argument); + CPPUNIT_ASSERT(src->nitems_written(0) >= N); + CPPUNIT_ASSERT_EQUAL(snk->nitems_read(0), (gr_uint64)1000); + CPPUNIT_ASSERT_THROW(snk->nitems_written(0), std::invalid_argument); } @@ -78,7 +78,7 @@ qa_block_tags::t1 () tb->connect(head, 0, snk, 0); tb->run(); - gr_uint64 W = src->n_items_written(0); + gr_uint64 W = src->nitems_written(0); src->add_item_tag(0, N, pmt::pmt_string_to_symbol("test1"), pmt::pmt_from_double(1.234)); -- cgit From 779f498c46175bb12828c9db4643eada3e364b16 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 12:31:18 -0400 Subject: Moves gr_block functions dealing with tags into protected space. Adds documentation to functions in header. Adds a "srcid" parameter to the add_item_tag function. --- gnuradio-core/src/lib/runtime/gr_block.cc | 12 +++-- gnuradio-core/src/lib/runtime/gr_block.h | 83 +++++++++++++++++++++++++------ gnuradio-core/src/lib/runtime/gr_block.i | 2 +- 3 files changed, 76 insertions(+), 21 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 13035aa96..eb377953d 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,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -144,19 +144,21 @@ gr_block::nitems_written(unsigned int which_output) void gr_block::add_item_tag(unsigned int which_output, gr_uint64 offset, - const pmt::pmt_t &key, const pmt::pmt_t &value) + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid) { - d_detail->add_item_tag(which_output, offset, key, value); + d_detail->add_item_tag(which_output, offset, key, value, srcid); } -std::list +std::deque gr_block::get_tags_in_range(unsigned int which_output, gr_uint64 start, gr_uint64 end) { return d_detail->get_tags_in_range(which_output, start, end); } -std::list +std::deque gr_block::get_tags_in_range(unsigned int which_output, gr_uint64 start, gr_uint64 end, const pmt::pmt_t &key) diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 7564acd87..25886eb10 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,2009 Free Software Foundation, Inc. + * Copyright 2004,2007,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,7 +24,7 @@ #define INCLUDED_GR_BLOCK_H #include -#include +#include /*! * \brief The abstract base class for all 'terminal' processing blocks. @@ -199,23 +199,16 @@ class gr_block : public gr_basic_block { */ virtual int fixed_rate_noutput_to_ninput(int noutput); - // Return the number of items read on input stream which_input + /*! + * \brief Return the number of items read on input stream which_input + */ gr_uint64 nitems_read(unsigned int which_input); - // Return the number of items written on output stream which_output + /*! + * \brief Return the number of items written on output stream which_output + */ gr_uint64 nitems_written(unsigned int which_output); - void add_item_tag(unsigned int which_output, - gr_uint64 offset, - const pmt::pmt_t &key, const pmt::pmt_t &value); - - std::list get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end); - - std::list get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end, - const pmt::pmt_t &key); - // ---------------------------------------------------------------------------- private: @@ -234,6 +227,66 @@ class gr_block : public gr_basic_block { void set_fixed_rate(bool fixed_rate){ d_fixed_rate = fixed_rate; } + + /*! + * \brief Adds a new tag to the deque of tags on a given buffer. + * + * This is a call-through method to gr_block_detail to add the new tag. + * gr_block_detail takes care of formatting the tuple from the inputs here, + * it then calls gr_buffer::add_item_tag(pmt::pmt_t t), which appends the + * tag onto its deque of tags. + * + * \param which_ouput an integer of which output stream to attach the tag + * \param abs_offset a uint64 number of the absolute item number + * assicated with the tag. Can get from nitems_written. + * \param key a PMT symbol holding the key name (i.e., a string) + * \param value any PMT holding any value for the given key + * \param srcid optional source ID specifier; defauls to string "NA" + */ + void add_item_tag(unsigned int which_output, + gr_uint64 abs_offset, + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid=pmt::pmt_string_to_symbol("NA")); + + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range. + * + * Pass-through function to gr_block_detail. Range of counts is from + * start to end-1. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end); + + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range + * with a given key. + * + * Pass-through function to gr_block_detail. Range of counts is from + * start to end-1. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + * \param key a PMT symbol key to filter only tags of this key + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end, + const pmt::pmt_t &key); + + // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friends diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index 4684bd2f2..e6ea06060 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * -- cgit From 309b05cbb38125a910b6199f7adc4ff93bc98064 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 12:33:20 -0400 Subject: Changing API to match changes to gr_block, including adding "srcid" param to add_item_tag. Added documentation to header file. Changing to deque from list. Still holding the deque locally in block_detail, but will be moved to gr_buffer. Adding tag just builds the tag tuple and appends it; doesn't worry about duplications. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 61 +++++++------------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 72 ++++++++++++++++++++---- 2 files changed, 81 insertions(+), 52 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index d12d808e9..2ab762a30 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,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -149,59 +149,39 @@ gr_block_detail::nitems_written(unsigned int which_output) void gr_block_detail::add_item_tag(unsigned int which_output, - gr_uint64 offset, + gr_uint64 abs_offset, const pmt::pmt_t &key, - const pmt::pmt_t &value) + const pmt::pmt_t &value, + const pmt::pmt_t &srcid) { if(pmt::pmt_is_symbol(key) == false) { throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { - bool duplicate = false; - - // Search through list of tags to see if new tag is a duplicate - std::list::reverse_iterator itr = d_item_tags.rbegin(); - while(itr != d_item_tags.rend()) { - // find the last item with this key if there is one - if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 2), key)) { - // check if this value is the same as last; its a duplicate if yes - if(pmt::pmt_eqv(pmt::pmt_tuple_ref(*itr, 3), value)) { - duplicate = true; - } - break; // only looking for the last item of this key - } - itr++; - } - - // It not a duplicate, add new tag to the list - if(!duplicate) { - pmt::pmt_t nitem = pmt::pmt_from_uint64(offset); - pmt::pmt_t stream = pmt::pmt_string_to_symbol("NULL"); - pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, stream, key, value); - d_item_tags.push_back(tuple); - } - - // need to add prunning routine + pmt::pmt_t nitem = pmt::pmt_from_uint64(abs_offset); + pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, srcid, key, value); + d_item_tags.push_back(tuple); } } -std::list +std::deque gr_block_detail::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end) + gr_uint64 abs_start, + gr_uint64 abs_end) { - std::list found_items; - std::list::iterator itr = d_item_tags.begin(); + std::deque found_items; + std::deque::iterator itr = d_item_tags.begin(); gr_uint64 item_time; while(itr != d_item_tags.end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); // items are pushed onto list in sequential order; stop if we're past end - if(item_time > end) { + if(item_time > abs_end) { break; } - if((item_time >= start) && (item_time <= end)) { + if((item_time >= abs_start) && (item_time <= abs_end)) { found_items.push_back(*itr); } @@ -211,13 +191,14 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, return found_items; } -std::list +std::deque gr_block_detail::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end, + gr_uint64 abs_start, + gr_uint64 abs_end, const pmt::pmt_t &key) { - std::list found_items; - std::list::iterator itr = d_item_tags.begin(); + std::deque found_items; + std::deque::iterator itr = d_item_tags.begin(); gr_uint64 item_time; pmt::pmt_t itemkey; @@ -225,12 +206,12 @@ gr_block_detail::get_tags_in_range(unsigned int which_output, item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); // items are pushed onto list in sequential order; stop if we're past end - if(item_time > end) { + if(item_time > abs_end) { break; } itemkey = pmt::pmt_tuple_ref(*itr, 2); - if((item_time >= start) && (item_time <= end) && pmt::pmt_eqv(key, itemkey)) { + if((item_time >= abs_start) && (item_time <= abs_end) && pmt::pmt_eqv(key, itemkey)) { found_items.push_back(*itr); } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index ee226a349..547d7c22f 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,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -94,18 +94,66 @@ class gr_block_detail { // Return the number of items written on output stream which_output gr_uint64 nitems_written(unsigned int which_output); - // Add an item tag tuple to list of tags - // -> is this just based on output stream? how to handle this... - void add_item_tag(unsigned int which_output, - gr_uint64 offset, - const pmt::pmt_t &key, const pmt::pmt_t &value); - std::list get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end); + /*! + * \brief Adds a new tag to the deque of tags on a given buffer. + * + * Adds a new tag to deque of tags on a given buffer. This takes the input + * parameters and builds a PMT tuple from it. It then calls + * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the + * tag onto its deque of tags. + * + * \param which_ouput an integer of which output stream to attach the tag + * \param abs_offset a uint64 number of the absolute item number + * assicated with the tag. Can get from nitems_written. + * \param key a PMT symbol holding the key name (i.e., a string) + * \param value any PMT holding any value for the given key + * \param srcid a PMT source ID specifier + */ + void add_item_tag(unsigned int which_output, + gr_uint64 abs_offset, + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid); + + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range. + * + * Pass-through function to gr_buffer to get a deque of tags in given range. + * Range of counts is from start to end-1. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end); - std::list get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end, - const pmt::pmt_t &key); + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range + * with a given key. + * + * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a deque of + * tags from the buffers. This function then provides a secondary filter to + * the tags to extract only tags with the given 'key'. Returns a dequeu + * of these tags. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + * \param key a PMT symbol key to filter only tags of this key + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end, + const pmt::pmt_t &key); gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -117,7 +165,7 @@ class gr_block_detail { unsigned int d_noutputs; std::vector d_input; std::vector d_output; - std::list d_item_tags; + std::deque d_item_tags; bool d_done; -- cgit From 54803ebc0450e9ee46e66b15d3b29249e44c55ed Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 12:38:52 -0400 Subject: Adding shell block for a random annotator. This will be used only for testing the stream tags, which is why its sitting in runtime. --- gnuradio-core/src/lib/runtime/Makefile.am | 3 ++ .../src/lib/runtime/gr_random_annotator.cc | 53 ++++++++++++++++++++++ .../src/lib/runtime/gr_random_annotator.h | 51 +++++++++++++++++++++ .../src/lib/runtime/gr_random_annotator.i | 32 +++++++++++++ gnuradio-core/src/lib/runtime/runtime.i | 2 + 5 files changed, 141 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.h create mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.i (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 4c52f3ab0..1af91d80d 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -49,6 +49,7 @@ libruntime_la_SOURCES = \ gr_msg_queue.cc \ gr_pagesize.cc \ gr_preferences.cc \ + gr_random_annotator.cc \ gr_realtime.cc \ gr_scheduler.cc \ gr_scheduler_sts.cc \ @@ -103,6 +104,7 @@ grinclude_HEADERS = \ gr_msg_queue.h \ gr_pagesize.h \ gr_preferences.h \ + gr_random_annotator.h \ gr_realtime.h \ gr_runtime_types.h \ gr_scheduler.h \ @@ -153,6 +155,7 @@ swiginclude_HEADERS = \ gr_message.i \ gr_msg_handler.i \ gr_msg_queue.i \ + gr_random_annotator.i \ gr_realtime.i \ gr_single_threaded_scheduler.i \ gr_sync_block.i \ diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc new file mode 100644 index 000000000..85995fde1 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) + : gr_sync_block ("random_annotator", + gr_make_io_signature (1, 1, sizeof_stream_item), + gr_make_io_signature (1, 1, sizeof_stream_item)) +{ +} + +gr_random_annotator::~gr_random_annotator () +{ +} + +gr_random_annotator_sptr +gr_make_random_annotator (size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr (new gr_random_annotator (sizeof_stream_item)); +} + +int +gr_random_annotator::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + return noutput_items; +} diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h new file mode 100644 index 000000000..cf894c640 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_RANDOM_ANNOTATOR_H +#define INCLUDED_GR_RANDOM_ANNOTATOR_H + +#include + +class gr_random_annotator; +typedef boost::shared_ptr gr_random_annotator_sptr; + +// public constructor +gr_random_annotator_sptr +gr_make_random_annotator (size_t sizeof_stream_item); + +class gr_random_annotator : public gr_sync_block +{ + public: + ~gr_random_annotator (); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +protected: + gr_random_annotator (size_t sizeof_stream_item); + + private: + friend gr_random_annotator_sptr + gr_make_random_annotator (size_t sizeof_stream_item); +}; + +#endif diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.i b/gnuradio-core/src/lib/runtime/gr_random_annotator.i new file mode 100644 index 000000000..f8765a294 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.i @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,random_annotator); + +gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); + +class gr_random_annotator : public gr_sync_block +{ +private: + gr_random_annotator (size_t sizeof_stream_item); +}; + diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 20cf68a03..51b32de17 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ %include %include %include +%include %include %include %include -- cgit From d75b1bb7ae118e191ef31c5691d409b680f723df Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 12:55:51 -0400 Subject: Makding random_annotator simply copy input to output streams; fixes IO signatures. --- .../src/lib/runtime/gr_random_annotator.cc | 27 +++++++++++++++------- .../src/lib/runtime/gr_random_annotator.h | 2 ++ 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index 85995fde1..25e7458e5 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -26,22 +26,24 @@ #include #include +#include -gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) - : gr_sync_block ("random_annotator", - gr_make_io_signature (1, 1, sizeof_stream_item), - gr_make_io_signature (1, 1, sizeof_stream_item)) +gr_random_annotator_sptr +gr_make_random_annotator (size_t sizeof_stream_item) { + return gnuradio::get_initial_sptr (new gr_random_annotator (sizeof_stream_item)); } -gr_random_annotator::~gr_random_annotator () +gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) + : gr_sync_block ("random_annotator", + gr_make_io_signature (1, -1, sizeof_stream_item), + gr_make_io_signature (1, -1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item) { } -gr_random_annotator_sptr -gr_make_random_annotator (size_t sizeof_stream_item) +gr_random_annotator::~gr_random_annotator () { - return gnuradio::get_initial_sptr (new gr_random_annotator (sizeof_stream_item)); } int @@ -49,5 +51,14 @@ gr_random_annotator::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { + const float **in = (const float **) &input_items[0]; + float **out = (float **) &output_items[0]; + + // Work does nothing to the data stream; just copy all inputs to outputs + int ninputs = input_items.size(); + for (int i = 0; i < ninputs; i++){ + memcpy(out[i], in[i], noutput_items * d_itemsize); + } + return noutput_items; } diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h index cf894c640..7f200eff7 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.h +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.h @@ -44,6 +44,8 @@ protected: gr_random_annotator (size_t sizeof_stream_item); private: + size_t d_itemsize; + friend gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); }; -- cgit From ef9ff4ce4ab97a557f08fa5dad091b0cf63d313f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 13:19:00 -0400 Subject: Making annotator block build up tags with the noutput_items as the value held. Simply prints info to stdout when tags are retreived. --- .../src/lib/runtime/gr_random_annotator.cc | 23 +++++++++++ gnuradio-core/src/lib/runtime/qa_block_tags.cc | 45 ++++------------------ 2 files changed, 30 insertions(+), 38 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index 25e7458e5..bd74f5b84 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -27,6 +27,7 @@ #include #include #include +#include gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item) @@ -54,11 +55,33 @@ gr_random_annotator::work (int noutput_items, const float **in = (const float **) &input_items[0]; float **out = (float **) &output_items[0]; + gr_uint64 abs_N = nitems_written(0); + std::deque all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); + std::deque::iterator itr; + std::cout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; + for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { + gr_uint64 nitem = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + std::string srcid = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 1)); + std::string key = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 2)); + gr_uint64 value = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 3)); + + std::cout << "Tag at " << nitem << " from " << srcid + << " with key = \"" << key << "\" had value = " << value << std::endl; + } + // Work does nothing to the data stream; just copy all inputs to outputs int ninputs = input_items.size(); for (int i = 0; i < ninputs; i++){ memcpy(out[i], in[i], noutput_items * d_itemsize); } + // Storing the current noutput_items as the value to the "noutput_items" key + std::stringstream str; + str << name() << unique_id(); + pmt::pmt_t cur_N = pmt::pmt_from_uint64(noutput_items); + pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); + pmt::pmt_t key = pmt::pmt_string_to_symbol("noutput_items"); + add_item_tag(0, abs_N, key, cur_N, srcid); + return noutput_items; } diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 73faa6ca7..7fe1b4bfd 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -68,51 +69,19 @@ qa_block_tags::t1 () { printf("\nqa_block_tags::t1\n"); - int N = 1000; + int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_block_sptr ann0 (gr_make_random_annotator(sizeof(int))); + gr_block_sptr ann1 (gr_make_random_annotator(sizeof(int))); gr_block_sptr snk (gr_make_null_sink(sizeof(int))); tb->connect(src, 0, head, 0); - tb->connect(head, 0, snk, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann1, 0, snk, 0); tb->run(); - gr_uint64 W = src->nitems_written(0); - src->add_item_tag(0, N, - pmt::pmt_string_to_symbol("test1"), - pmt::pmt_from_double(1.234)); - - // Make sure we can't get duplicates - src->add_item_tag(0, N, - pmt::pmt_string_to_symbol("test1"), - pmt::pmt_from_double(1.234)); - - // Add new tag at another position - src->add_item_tag(0, W, - pmt::pmt_string_to_symbol("test2"), - pmt::pmt_from_double(2.345)); - - // Test how many tags we get for different ranges - // should be 1, 0, 0, and 2 - std::list tags0, tags1, tags2, tags3; - tags0 = src->get_tags_in_range(0, N-10, N+10); - tags1 = src->get_tags_in_range(0, N-10, N- 1); - tags2 = src->get_tags_in_range(0, N+ 1, N+10); - tags3 = src->get_tags_in_range(0, 0, W); - - CPPUNIT_ASSERT(tags0.size() == 1); - CPPUNIT_ASSERT(tags1.size() == 0); - CPPUNIT_ASSERT(tags2.size() == 0); - CPPUNIT_ASSERT(tags3.size() == 2); - - // Check types and values are good - pmt::pmt_t tuple = tags0.front(); - pmt::pmt_t key = pmt::pmt_tuple_ref(tuple, 2); - double value = pmt::pmt_to_double(pmt::pmt_tuple_ref(tuple, 3)); - - CPPUNIT_ASSERT(pmt::pmt_is_tuple(tuple)); - CPPUNIT_ASSERT(pmt::pmt_eqv(key, pmt::pmt_string_to_symbol("test1"))); - CPPUNIT_ASSERT_EQUAL(value, 1.234); } -- cgit From 70ca24e7cc6ba744589e3d5fb8077f706e813d28 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 18:16:26 -0400 Subject: Moving add_item_tag into gr_buffer and get_tags_in_range to gr_buffer_reader. gr_block_detail takes care of the high-level adding and retrieving tags via the buffers/readers; also takes care of filtering tags by key. Tags are now added to the gr_buffers on 'which_output' while they are retrieved from the gr_buffer_reader based on 'which_input." --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 61 +++++++++--------------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 5 +- gnuradio-core/src/lib/runtime/gr_buffer.cc | 35 +++++++++++++- gnuradio-core/src/lib/runtime/gr_buffer.h | 36 +++++++++++++- 4 files changed, 93 insertions(+), 44 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 2ab762a30..85b663ac6 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -158,65 +158,48 @@ gr_block_detail::add_item_tag(unsigned int which_output, throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { + // build tag tuple pmt::pmt_t nitem = pmt::pmt_from_uint64(abs_offset); pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, srcid, key, value); - d_item_tags.push_back(tuple); + + // Add tag to gr_buffer's deque tags + d_output[which_output]->add_item_tag(tuple); } } std::deque -gr_block_detail::get_tags_in_range(unsigned int which_output, +gr_block_detail::get_tags_in_range(unsigned int which_input, gr_uint64 abs_start, gr_uint64 abs_end) { - std::deque found_items; - std::deque::iterator itr = d_item_tags.begin(); - - gr_uint64 item_time; - while(itr != d_item_tags.end()) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); - - // items are pushed onto list in sequential order; stop if we're past end - if(item_time > abs_end) { - break; - } - - if((item_time >= abs_start) && (item_time <= abs_end)) { - found_items.push_back(*itr); - } - - itr++; - } - - return found_items; + // get from gr_buffer_reader's deque of tags + return d_input[which_input]->get_tags_in_range(which_input, + abs_start, + abs_end); } std::deque -gr_block_detail::get_tags_in_range(unsigned int which_output, +gr_block_detail::get_tags_in_range(unsigned int which_input, gr_uint64 abs_start, gr_uint64 abs_end, const pmt::pmt_t &key) { - std::deque found_items; - std::deque::iterator itr = d_item_tags.begin(); - - gr_uint64 item_time; - pmt::pmt_t itemkey; - while(itr != d_item_tags.end()) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + std::deque found_items, found_items_by_key; - // items are pushed onto list in sequential order; stop if we're past end - if(item_time > abs_end) { - break; - } + // get from gr_buffer_reader's deque of tags + found_items = d_input[which_input]->get_tags_in_range(which_input, + abs_start, + abs_end); + // Filter further by key name + pmt::pmt_t itemkey; + std::deque::iterator itr; + for(itr = found_items.begin(); itr != found_items.end(); itr++) { itemkey = pmt::pmt_tuple_ref(*itr, 2); - if((item_time >= abs_start) && (item_time <= abs_end) && pmt::pmt_eqv(key, itemkey)) { - found_items.push_back(*itr); + if(pmt::pmt_eqv(key, itemkey)) { + found_items_by_key.push_back(*itr); } - - itr++; } - return found_items; + return found_items_by_key; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 547d7c22f..ada807f68 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -119,8 +119,8 @@ class gr_block_detail { /*! * \brief Given a [start,end), returns a deque copy of all tags in the range. * - * Pass-through function to gr_buffer to get a deque of tags in given range. - * Range of counts is from start to end-1. + * Pass-through function to gr_buffer_reader to get a deque of tags + * in given range. Range of counts is from start to end-1. * * Tags are tuples of: * (item count, source id, key, value) @@ -165,7 +165,6 @@ class gr_block_detail { unsigned int d_noutputs; std::vector d_input; std::vector d_output; - std::deque d_item_tags; bool d_done; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 89db99b69..da7866f48 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -216,6 +216,12 @@ gr_buffer::drop_reader (gr_buffer_reader *reader) d_readers.erase (result); } +void +gr_buffer::add_item_tag(const pmt::pmt_t &tag) +{ + d_item_tags.push_back(tag); +} + long gr_buffer_ncurrently_allocated () { @@ -257,6 +263,33 @@ gr_buffer_reader::update_read_pointer (int nitems) d_abs_read_offset += nitems; } +std::deque +gr_buffer_reader::get_tags_in_range(unsigned int which_output, + gr_uint64 abs_start, + gr_uint64 abs_end) +{ + std::deque found_items; + std::deque::iterator itr = d_item_tags.begin(); + + gr_uint64 item_time; + while(itr != d_item_tags.end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + + // items are pushed onto list in sequential order; stop if we're past end + if(item_time > abs_end) { + break; + } + + if((item_time >= abs_start) && (item_time <= abs_end)) { + found_items.push_back(*itr); + } + + itr++; + } + + return found_items; +} + long gr_buffer_reader_ncurrently_allocated () { diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 8af72741a..e50f638b5 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,6 +26,7 @@ #include #include #include +#include class gr_vmcircbuf; @@ -90,6 +91,19 @@ class gr_buffer { gr_uint64 nitems_written() { return d_abs_write_offset; } + + /*! + * \brief Adds a new tag to the deque of tags on a given buffer. + * + * Adds a new tag to deque of tags on a given buffer. This takes the input + * parameters and builds a PMT tuple from it. It then calls + * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the + * tag onto its deque of tags. + * + * \param tag a PMT tuple containing the new tag + */ + void add_item_tag(const pmt::pmt_t &tag); + // ------------------------------------------------------------------------- private: @@ -107,6 +121,8 @@ class gr_buffer { std::vector d_readers; boost::weak_ptr d_link; // block that writes to this buffer + std::deque d_item_tags; + // // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's // and d_abs_read_offset's in the buffer readers. @@ -232,6 +248,23 @@ class gr_buffer_reader { */ gr_block_sptr link() { return gr_block_sptr(d_link); } + + /*! + * \brief Given a [start,end), returns a deque copy of all tags in the range. + * + * Get a deque of tags in given range. Range of counts is from start to end-1. + * + * Tags are tuples of: + * (item count, source id, key, value) + * + * \param which_input an integer of which input stream to pull from + * \param abs_start a uint64 count of the start of the range of interest + * \param abs_end a uint64 count of the end of the range of interest + */ + std::deque get_tags_in_range(unsigned int which_input, + gr_uint64 abs_start, + gr_uint64 abs_end); + // ------------------------------------------------------------------------- private: @@ -245,6 +278,7 @@ class gr_buffer_reader { unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) gr_uint64 d_abs_read_offset; // num items seen since the start boost::weak_ptr d_link; // block that reads via this buffer reader + std::deque d_item_tags; //! constructor is private. Use gr_buffer::add_reader to create instances gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index, gr_block_sptr link); -- cgit From 7f6f2a377bf8bca6880ecc030792202e09b631a7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 18:30:17 -0400 Subject: gr_buffer_reader doesn't need to know which input it is. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 3 +-- gnuradio-core/src/lib/runtime/gr_buffer.h | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index da7866f48..58cffe495 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -264,8 +264,7 @@ gr_buffer_reader::update_read_pointer (int nitems) } std::deque -gr_buffer_reader::get_tags_in_range(unsigned int which_output, - gr_uint64 abs_start, +gr_buffer_reader::get_tags_in_range(gr_uint64 abs_start, gr_uint64 abs_end) { std::deque found_items; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index e50f638b5..6498ee296 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -257,12 +257,10 @@ class gr_buffer_reader { * Tags are tuples of: * (item count, source id, key, value) * - * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, + std::deque get_tags_in_range(gr_uint64 abs_start, gr_uint64 abs_end); // ------------------------------------------------------------------------- -- cgit From bf079e66e50f4aff775175c288e952b6325ea71c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 4 Nov 2010 18:36:05 -0400 Subject: Fixing api call to gr_buffer_reader that no longer takes in which_input. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 85b663ac6..de4fb2196 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -173,9 +173,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, gr_uint64 abs_end) { // get from gr_buffer_reader's deque of tags - return d_input[which_input]->get_tags_in_range(which_input, - abs_start, - abs_end); + return d_input[which_input]->get_tags_in_range(abs_start, abs_end); } std::deque @@ -187,9 +185,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, std::deque found_items, found_items_by_key; // get from gr_buffer_reader's deque of tags - found_items = d_input[which_input]->get_tags_in_range(which_input, - abs_start, - abs_end); + found_items = d_input[which_input]->get_tags_in_range(abs_start, abs_end); // Filter further by key name pmt::pmt_t itemkey; -- cgit From d58d250c82ff8b106aec02f5222cea385b74d729 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 13:03:28 -0400 Subject: buffer_reader does not hold its own tags but looks upstream to the associated buffer to get them. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_buffer.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 58cffe495..9048d57a4 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -268,10 +268,10 @@ gr_buffer_reader::get_tags_in_range(gr_uint64 abs_start, gr_uint64 abs_end) { std::deque found_items; - std::deque::iterator itr = d_item_tags.begin(); + std::deque::iterator itr = d_buffer->get_tags_begin(); gr_uint64 item_time; - while(itr != d_item_tags.end()) { + while(itr != d_buffer->get_tags_end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); // items are pushed onto list in sequential order; stop if we're past end diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 6498ee296..8174b7e67 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -104,6 +104,9 @@ class gr_buffer { */ void add_item_tag(const pmt::pmt_t &tag); + std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } + std::deque::iterator get_tags_end() { return d_item_tags.end(); } + // ------------------------------------------------------------------------- private: @@ -121,7 +124,7 @@ class gr_buffer { std::vector d_readers; boost::weak_ptr d_link; // block that writes to this buffer - std::deque d_item_tags; + std::deque d_item_tags; // temp. store tags until moved to reader // // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's @@ -276,7 +279,6 @@ class gr_buffer_reader { unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) gr_uint64 d_abs_read_offset; // num items seen since the start boost::weak_ptr d_link; // block that reads via this buffer reader - std::deque d_item_tags; //! constructor is private. Use gr_buffer::add_reader to create instances gr_buffer_reader (gr_buffer_sptr buffer, unsigned int read_index, gr_block_sptr link); -- cgit From 6cc6925ec231897a2e46f3d7bfb52ba3aecfc492 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 13:18:32 -0400 Subject: Better formatting of tag information to make info more readable. --- gnuradio-core/src/lib/runtime/gr_random_annotator.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index bd74f5b84..d9ad15a55 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -28,6 +28,7 @@ #include #include #include +#include gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item) @@ -55,18 +56,27 @@ gr_random_annotator::work (int noutput_items, const float **in = (const float **) &input_items[0]; float **out = (float **) &output_items[0]; + std::stringstream str; + str << name() << unique_id(); + gr_uint64 abs_N = nitems_written(0); std::deque all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); std::deque::iterator itr; std::cout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; + + std::cout.setf(std::ios::left); + std::cout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" + << std::setw(10) << "nitem" << std::setw(20) << "key" + << std::setw(10) << "value" << std::endl; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { gr_uint64 nitem = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); std::string srcid = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 1)); std::string key = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 2)); gr_uint64 value = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 3)); - std::cout << "Tag at " << nitem << " from " << srcid - << " with key = \"" << key << "\" had value = " << value << std::endl; + std::cout << std::setw(25) << str.str() << std::setw(25) << srcid + << std::setw(10) << nitem << std::setw(20) << key + << std::setw(10) << value << std::endl; } // Work does nothing to the data stream; just copy all inputs to outputs @@ -76,8 +86,6 @@ gr_random_annotator::work (int noutput_items, } // Storing the current noutput_items as the value to the "noutput_items" key - std::stringstream str; - str << name() << unique_id(); pmt::pmt_t cur_N = pmt::pmt_from_uint64(noutput_items); pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); pmt::pmt_t key = pmt::pmt_string_to_symbol("noutput_items"); -- cgit From 20adc2d657d189cd07f9585aeb4cb213ffe0bb07 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 14:17:04 -0400 Subject: Because tags can be appended from upstream, they are not consecutive in time, so we need to cycle through them all. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 5 ----- 1 file changed, 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 9048d57a4..8387a3168 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -274,11 +274,6 @@ gr_buffer_reader::get_tags_in_range(gr_uint64 abs_start, while(itr != d_buffer->get_tags_end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); - // items are pushed onto list in sequential order; stop if we're past end - if(item_time > abs_end) { - break; - } - if((item_time >= abs_start) && (item_time <= abs_end)) { found_items.push_back(*itr); } -- cgit From 8b184fda9da4e7fdf08ddfd4d973d5d8d83be308 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 14:18:32 -0400 Subject: Adding call in scheduler to handle tag movements between blocks and some helper functions to get access and keep track of tags. --- gnuradio-core/src/lib/runtime/gr_block.cc | 7 +++++++ gnuradio-core/src/lib/runtime/gr_block.h | 9 +++++++++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 19 ++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_block_detail.h | 9 +++++++++ gnuradio-core/src/lib/runtime/gr_buffer.h | 18 +++++++++++++++++- gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc | 2 ++ 6 files changed, 62 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index eb377953d..51eb5b498 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -166,6 +166,13 @@ gr_block::get_tags_in_range(unsigned int which_output, return d_detail->get_tags_in_range(which_output, start, end, key); } +void +gr_block::handle_tags() +{ + d_detail->handle_tags(); +} + + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 25886eb10..89d762847 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -209,6 +209,15 @@ class gr_block : public gr_basic_block { */ gr_uint64 nitems_written(unsigned int which_output); + + /*! + * \brief Function to move tags downstream + * + * The default behavior proxies to gr_block_detail, which just moves all tags + * from input to output and flows them all downstream. + */ + virtual void handle_tags(); + // ---------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index de4fb2196..7994919d4 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -39,7 +39,8 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_produce_or(0), d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), - d_done (false) + d_done (false), + d_last_tag(0) { s_ncurrently_allocated++; } @@ -199,3 +200,19 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, return found_items_by_key; } + +void +gr_block_detail::handle_tags() +{ + for(unsigned int i = 0; i < d_ninputs; i++) { + pmt::pmt_t tuple; + while(d_input[i]->get_tag(d_last_tag, tuple)) { + d_last_tag++; + if(!sink_p()) { + for(unsigned int o = 0; o < d_noutputs; o++) { + d_output[o]->add_item_tag(tuple); + } + } + } + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index ada807f68..cbb59a689 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -155,6 +155,14 @@ class gr_block_detail { gr_uint64 abs_end, const pmt::pmt_t &key); + /*! + * \brief Default tag handler; moves all tags downstream + * + * Move all tags from input to output and flows them all downstream. Each input + * stream's tags get appended to each output streams tags. + */ + void handle_tags(); + gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -167,6 +175,7 @@ class gr_block_detail { std::vector d_output; bool d_done; + size_t d_last_tag; // keep track of which tags we've already received from upstream gr_block_detail (unsigned int ninputs, unsigned int noutputs); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 8174b7e67..6dcbff0b9 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -107,6 +107,17 @@ class gr_buffer { std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } std::deque::iterator get_tags_end() { return d_item_tags.end(); } + bool get_tag(size_t n, pmt::pmt_t &t) + { + if(n < d_item_tags.size()) { + t = d_item_tags[n]; + return true; + } + else { + return false; + } + } + // ------------------------------------------------------------------------- private: @@ -265,7 +276,12 @@ class gr_buffer_reader { */ std::deque get_tags_in_range(gr_uint64 abs_start, gr_uint64 abs_end); - + + bool get_tag(size_t n, pmt::pmt_t &t) + { + return d_buffer->get_tag(n, t); + } + // ------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index 03eef17d9..6a84f4be8 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -45,6 +45,8 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) while ((msg = d->d_tpb.delete_head_nowait())) block->handle_msg(msg); + block->handle_tags(); + d->d_tpb.clear_changed(); s = d_exec.run_one_iteration(); -- cgit From cafe83aa6bd47f8e05bd347cc4495d3662b5440f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 6 Nov 2010 14:24:19 -0400 Subject: Don't directly output tag info to screen from gr_random_annotator; instead, store the stream and write it to stdout when block is being destroyed. This avoids issues of the muliple threads writing simultaneously to screen. --- gnuradio-core/src/lib/runtime/gr_random_annotator.cc | 20 +++++++++++--------- gnuradio-core/src/lib/runtime/gr_random_annotator.h | 1 + gnuradio-core/src/lib/runtime/qa_block_tags.cc | 4 +++- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index d9ad15a55..93d9aa793 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -46,6 +46,7 @@ gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) gr_random_annotator::~gr_random_annotator () { + std::cout << d_sout.str(); } int @@ -62,21 +63,22 @@ gr_random_annotator::work (int noutput_items, gr_uint64 abs_N = nitems_written(0); std::deque all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); std::deque::iterator itr; - std::cout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; - std::cout.setf(std::ios::left); - std::cout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" - << std::setw(10) << "nitem" << std::setw(20) << "key" - << std::setw(10) << "value" << std::endl; + d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; + d_sout.setf(std::ios::left); + d_sout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" + << std::setw(10) << "nitem" << std::setw(20) << "key" + << std::setw(10) << "value" << std::endl; + for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { gr_uint64 nitem = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); std::string srcid = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 1)); std::string key = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 2)); gr_uint64 value = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 3)); - std::cout << std::setw(25) << str.str() << std::setw(25) << srcid - << std::setw(10) << nitem << std::setw(20) << key - << std::setw(10) << value << std::endl; + d_sout << std::setw(25) << str.str() << std::setw(25) << srcid + << std::setw(10) << nitem << std::setw(20) << key + << std::setw(10) << value << std::endl; } // Work does nothing to the data stream; just copy all inputs to outputs @@ -86,7 +88,7 @@ gr_random_annotator::work (int noutput_items, } // Storing the current noutput_items as the value to the "noutput_items" key - pmt::pmt_t cur_N = pmt::pmt_from_uint64(noutput_items); + pmt::pmt_t cur_N = pmt::pmt_from_uint64(random()); pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); pmt::pmt_t key = pmt::pmt_string_to_symbol("noutput_items"); add_item_tag(0, abs_N, key, cur_N, srcid); diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h index 7f200eff7..3f21b71ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.h +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.h @@ -45,6 +45,7 @@ protected: private: size_t d_itemsize; + std::stringstream d_sout; friend gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 7fe1b4bfd..ab3db6653 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -75,12 +75,14 @@ qa_block_tags::t1 () gr_block_sptr head (gr_make_head(sizeof(int), N)); gr_block_sptr ann0 (gr_make_random_annotator(sizeof(int))); gr_block_sptr ann1 (gr_make_random_annotator(sizeof(int))); + gr_block_sptr ann2 (gr_make_random_annotator(sizeof(int))); gr_block_sptr snk (gr_make_null_sink(sizeof(int))); tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); tb->connect(ann0, 0, ann1, 0); - tb->connect(ann1, 0, snk, 0); + tb->connect(ann1, 0, ann2, 0); + tb->connect(ann2, 0, snk, 0); tb->run(); } -- cgit From 95eaad323daecbd2c4c0a7aaf5176f9a1b33eec0 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 7 Nov 2010 16:05:08 -0500 Subject: Cleaning up. Better use of PMTs; comment mods; returning vectors when getting tags. --- gnuradio-core/src/lib/runtime/gr_block.cc | 14 +++--- gnuradio-core/src/lib/runtime/gr_block.h | 38 ++++++++-------- gnuradio-core/src/lib/runtime/gr_block.i | 4 +- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 50 +++++++++++----------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 42 +++++++++--------- gnuradio-core/src/lib/runtime/gr_buffer.cc | 10 ++--- gnuradio-core/src/lib/runtime/gr_buffer.h | 23 ++++------ .../src/lib/runtime/gr_random_annotator.cc | 20 ++++----- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 6 +-- 9 files changed, 98 insertions(+), 109 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 51eb5b498..73a86e38b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -117,7 +117,7 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) throw std::runtime_error("Unimplemented"); } -gr_uint64 +uint64_t gr_block::nitems_read(unsigned int which_input) { if(d_detail) { @@ -129,7 +129,7 @@ gr_block::nitems_read(unsigned int which_input) } } -gr_uint64 +uint64_t gr_block::nitems_written(unsigned int which_output) { if(d_detail) { @@ -143,7 +143,7 @@ gr_block::nitems_written(unsigned int which_output) void gr_block::add_item_tag(unsigned int which_output, - gr_uint64 offset, + uint64_t offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid) @@ -151,16 +151,16 @@ gr_block::add_item_tag(unsigned int which_output, d_detail->add_item_tag(which_output, offset, key, value, srcid); } -std::deque +std::vector gr_block::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end) + uint64_t start, uint64_t end) { return d_detail->get_tags_in_range(which_output, start, end); } -std::deque +std::vector gr_block::get_tags_in_range(unsigned int which_output, - gr_uint64 start, gr_uint64 end, + uint64_t start, uint64_t end, const pmt::pmt_t &key) { return d_detail->get_tags_in_range(which_output, start, end, key); diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 89d762847..4d1d6f875 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -24,7 +24,6 @@ #define INCLUDED_GR_BLOCK_H #include -#include /*! * \brief The abstract base class for all 'terminal' processing blocks. @@ -202,12 +201,12 @@ class gr_block : public gr_basic_block { /*! * \brief Return the number of items read on input stream which_input */ - gr_uint64 nitems_read(unsigned int which_input); + uint64_t nitems_read(unsigned int which_input); /*! * \brief Return the number of items written on output stream which_output */ - gr_uint64 nitems_written(unsigned int which_output); + uint64_t nitems_written(unsigned int which_output); /*! @@ -238,28 +237,25 @@ class gr_block : public gr_basic_block { /*! - * \brief Adds a new tag to the deque of tags on a given buffer. + * \brief Adds a new tag onto the given output buffer. * - * This is a call-through method to gr_block_detail to add the new tag. - * gr_block_detail takes care of formatting the tuple from the inputs here, - * it then calls gr_buffer::add_item_tag(pmt::pmt_t t), which appends the - * tag onto its deque of tags. + * This is a call-through method to gr_block_detail. * * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. - * \param key a PMT symbol holding the key name (i.e., a string) + * \param key a PMT symbol holding the key name * \param value any PMT holding any value for the given key - * \param srcid optional source ID specifier; defauls to string "NA" + * \param srcid optional source ID specifier; defaults to PMT_F */ void add_item_tag(unsigned int which_output, - gr_uint64 abs_offset, + uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, - const pmt::pmt_t &srcid=pmt::pmt_string_to_symbol("NA")); + const pmt::pmt_t &srcid=pmt::PMT_F); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range. + * \brief Given a [start,end), returns a vector of all tags in the range. * * Pass-through function to gr_block_detail. Range of counts is from * start to end-1. @@ -271,12 +267,12 @@ class gr_block : public gr_basic_block { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end); + std::vector get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range + * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. * * Pass-through function to gr_block_detail. Range of counts is from @@ -290,10 +286,10 @@ class gr_block : public gr_basic_block { * \param abs_end a uint64 count of the end of the range of interest * \param key a PMT symbol key to filter only tags of this key */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end, - const pmt::pmt_t &key); + std::vector get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); // These are really only for internal use, but leaving them public avoids diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index e6ea06060..2de354878 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -49,8 +49,8 @@ class gr_block : public gr_basic_block { bool start(); bool stop(); - gr_uint64 nitems_read(unsigned int which_input); - gr_uint64 nitems_written(unsigned int which_output); + uint64_t nitems_read(unsigned int which_input); + uint64_t nitems_written(unsigned int which_output); // internal use gr_block_detail_sptr detail () const { return d_detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 7994919d4..b3d1a7194 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -27,6 +27,8 @@ #include #include +using namespace pmt; + static long s_ncurrently_allocated = 0; long @@ -127,12 +129,12 @@ gr_block_detail::produce_each (int how_many_items) void -gr_block_detail::_post(pmt::pmt_t msg) +gr_block_detail::_post(pmt_t msg) { d_tpb.insert_tail(msg); } -gr_uint64 +uint64_t gr_block_detail::nitems_read(unsigned int which_input) { if(which_input >= d_ninputs) @@ -140,7 +142,7 @@ gr_block_detail::nitems_read(unsigned int which_input) return d_input[which_input]->nitems_read(); } -gr_uint64 +uint64_t gr_block_detail::nitems_written(unsigned int which_output) { if(which_output >= d_noutputs) @@ -150,50 +152,50 @@ gr_block_detail::nitems_written(unsigned int which_output) void gr_block_detail::add_item_tag(unsigned int which_output, - gr_uint64 abs_offset, - const pmt::pmt_t &key, - const pmt::pmt_t &value, - const pmt::pmt_t &srcid) + uint64_t abs_offset, + const pmt_t &key, + const pmt_t &value, + const pmt_t &srcid) { - if(pmt::pmt_is_symbol(key) == false) { - throw pmt::pmt_wrong_type("gr_block_detail::set_item_tag key", key); + if(!pmt_is_symbol(key)) { + throw pmt_wrong_type("gr_block_detail::set_item_tag key", key); } else { // build tag tuple - pmt::pmt_t nitem = pmt::pmt_from_uint64(abs_offset); - pmt::pmt_t tuple = pmt::pmt_make_tuple(nitem, srcid, key, value); + pmt_t nitem = pmt_from_uint64(abs_offset); + pmt_t tuple = pmt_make_tuple(nitem, srcid, key, value); // Add tag to gr_buffer's deque tags d_output[which_output]->add_item_tag(tuple); } } -std::deque +std::vector gr_block_detail::get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end) + uint64_t abs_start, + uint64_t abs_end) { // get from gr_buffer_reader's deque of tags return d_input[which_input]->get_tags_in_range(abs_start, abs_end); } -std::deque +std::vector gr_block_detail::get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end, - const pmt::pmt_t &key) + uint64_t abs_start, + uint64_t abs_end, + const pmt_t &key) { - std::deque found_items, found_items_by_key; + std::vector found_items, found_items_by_key; // get from gr_buffer_reader's deque of tags found_items = d_input[which_input]->get_tags_in_range(abs_start, abs_end); // Filter further by key name - pmt::pmt_t itemkey; - std::deque::iterator itr; + pmt_t itemkey; + std::vector::iterator itr; for(itr = found_items.begin(); itr != found_items.end(); itr++) { - itemkey = pmt::pmt_tuple_ref(*itr, 2); - if(pmt::pmt_eqv(key, itemkey)) { + itemkey = pmt_tuple_ref(*itr, 2); + if(pmt_eqv(key, itemkey)) { found_items_by_key.push_back(*itr); } } @@ -205,7 +207,7 @@ void gr_block_detail::handle_tags() { for(unsigned int i = 0; i < d_ninputs; i++) { - pmt::pmt_t tuple; + pmt_t tuple; while(d_input[i]->get_tag(d_last_tag, tuple)) { d_last_tag++; if(!sink_p()) { diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index cbb59a689..3a2b82190 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -89,19 +89,18 @@ class gr_block_detail { void _post(pmt::pmt_t msg); // Return the number of items read on input stream which_input - gr_uint64 nitems_read(unsigned int which_input); + uint64_t nitems_read(unsigned int which_input); // Return the number of items written on output stream which_output - gr_uint64 nitems_written(unsigned int which_output); + uint64_t nitems_written(unsigned int which_output); /*! - * \brief Adds a new tag to the deque of tags on a given buffer. + * \brief Adds a new tag to the given output stream. * - * Adds a new tag to deque of tags on a given buffer. This takes the input - * parameters and builds a PMT tuple from it. It then calls - * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the - * tag onto its deque of tags. + * This takes the input parameters and builds a PMT tuple + * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), + * which appends the tag onto its deque. * * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number @@ -111,15 +110,15 @@ class gr_block_detail { * \param srcid a PMT source ID specifier */ void add_item_tag(unsigned int which_output, - gr_uint64 abs_offset, + uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, const pmt::pmt_t &srcid); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range. + * \brief Given a [start,end), returns a vector of all tags in the range. * - * Pass-through function to gr_buffer_reader to get a deque of tags + * Pass-through function to gr_buffer_reader to get a vector of tags * in given range. Range of counts is from start to end-1. * * Tags are tuples of: @@ -129,18 +128,17 @@ class gr_block_detail { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end); + std::vector get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range + * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. * - * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a deque of + * Calls get_tags_in_range(which_input, abs_start, abs_end) to get a vector of * tags from the buffers. This function then provides a secondary filter to - * the tags to extract only tags with the given 'key'. Returns a dequeu - * of these tags. + * the tags to extract only tags with the given 'key'. * * Tags are tuples of: * (item count, source id, key, value) @@ -148,12 +146,12 @@ class gr_block_detail { * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest - * \param key a PMT symbol key to filter only tags of this key + * \param key a PMT symbol key to select only tags of this key */ - std::deque get_tags_in_range(unsigned int which_input, - gr_uint64 abs_start, - gr_uint64 abs_end, - const pmt::pmt_t &key); + std::vector get_tags_in_range(unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); /*! * \brief Default tag handler; moves all tags downstream diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 8387a3168..862d92b81 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -263,14 +263,14 @@ gr_buffer_reader::update_read_pointer (int nitems) d_abs_read_offset += nitems; } -std::deque -gr_buffer_reader::get_tags_in_range(gr_uint64 abs_start, - gr_uint64 abs_end) +std::vector +gr_buffer_reader::get_tags_in_range(uint64_t abs_start, + uint64_t abs_end) { - std::deque found_items; + std::vector found_items; std::deque::iterator itr = d_buffer->get_tags_begin(); - gr_uint64 item_time; + uint64_t item_time; while(itr != d_buffer->get_tags_end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 6dcbff0b9..5b8f21c94 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -89,17 +89,12 @@ class gr_buffer { gruel::mutex *mutex() { return &d_mutex; } - gr_uint64 nitems_written() { return d_abs_write_offset; } + uint64_t nitems_written() { return d_abs_write_offset; } /*! - * \brief Adds a new tag to the deque of tags on a given buffer. + * \brief Adds a new tag to the buffer. * - * Adds a new tag to deque of tags on a given buffer. This takes the input - * parameters and builds a PMT tuple from it. It then calls - * gr_buffer::add_item_tag(pmt::pmt_t t), which appends the - * tag onto its deque of tags. - * * \param tag a PMT tuple containing the new tag */ void add_item_tag(const pmt::pmt_t &tag); @@ -143,7 +138,7 @@ class gr_buffer { // gruel::mutex d_mutex; unsigned int d_write_index; // in items [0,d_bufsize) - gr_uint64 d_abs_write_offset; // num items written since the start + uint64_t d_abs_write_offset; // num items written since the start //deq tag_tuples bool d_done; @@ -255,7 +250,7 @@ class gr_buffer_reader { gruel::mutex *mutex() { return d_buffer->mutex(); } - gr_uint64 nitems_read() { return d_abs_read_offset; } + uint64_t nitems_read() { return d_abs_read_offset; } /*! * \brief Return the block that reads via this reader. @@ -264,9 +259,9 @@ class gr_buffer_reader { /*! - * \brief Given a [start,end), returns a deque copy of all tags in the range. + * \brief Given a [start,end), returns a vector all tags in the range. * - * Get a deque of tags in given range. Range of counts is from start to end-1. + * Get a vector of tags in given range. Range of counts is from start to end-1. * * Tags are tuples of: * (item count, source id, key, value) @@ -274,8 +269,8 @@ class gr_buffer_reader { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::deque get_tags_in_range(gr_uint64 abs_start, - gr_uint64 abs_end); + std::vector get_tags_in_range(uint64_t abs_start, + uint64_t abs_end); bool get_tag(size_t n, pmt::pmt_t &t) { @@ -293,7 +288,7 @@ class gr_buffer_reader { gr_buffer_sptr d_buffer; unsigned int d_read_index; // in items [0,d->buffer.d_bufsize) - gr_uint64 d_abs_read_offset; // num items seen since the start + uint64_t d_abs_read_offset; // num items seen since the start boost::weak_ptr d_link; // block that reads via this buffer reader //! constructor is private. Use gr_buffer::add_reader to create instances diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index 93d9aa793..d360c13a5 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -60,9 +60,9 @@ gr_random_annotator::work (int noutput_items, std::stringstream str; str << name() << unique_id(); - gr_uint64 abs_N = nitems_written(0); - std::deque all_tags = get_tags_in_range(0, (gr_uint64)0, abs_N); - std::deque::iterator itr; + uint64_t abs_N = nitems_written(0); + std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); + std::vector::iterator itr; d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; d_sout.setf(std::ios::left); @@ -71,14 +71,12 @@ gr_random_annotator::work (int noutput_items, << std::setw(10) << "value" << std::endl; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - gr_uint64 nitem = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); - std::string srcid = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 1)); - std::string key = pmt::pmt_symbol_to_string(pmt::pmt_tuple_ref(*itr, 2)); - gr_uint64 value = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 3)); - - d_sout << std::setw(25) << str.str() << std::setw(25) << srcid - << std::setw(10) << nitem << std::setw(20) << key - << std::setw(10) << value << std::endl; + d_sout << std::setw(25) << str.str() + << std::setw(25) << pmt::pmt_tuple_ref(*itr, 1) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 0) + << std::setw(20) << pmt::pmt_tuple_ref(*itr, 2) + << std::setw(10) << pmt::pmt_tuple_ref(*itr, 3) + << std::endl; } // Work does nothing to the data stream; just copy all inputs to outputs diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index ab3db6653..2fedb28fd 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -52,14 +52,14 @@ qa_block_tags::t0 () //CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::runtime_error); //CPPUNIT_ASSERT_THROW(src->nitems_written(0), std::runtime_error); - CPPUNIT_ASSERT_EQUAL(src->nitems_read(0), (gr_uint64)0); - CPPUNIT_ASSERT_EQUAL(src->nitems_written(0), (gr_uint64)0); + CPPUNIT_ASSERT_EQUAL(src->nitems_read(0), (uint64_t)0); + CPPUNIT_ASSERT_EQUAL(src->nitems_written(0), (uint64_t)0); tb->run(); CPPUNIT_ASSERT_THROW(src->nitems_read(0), std::invalid_argument); CPPUNIT_ASSERT(src->nitems_written(0) >= N); - CPPUNIT_ASSERT_EQUAL(snk->nitems_read(0), (gr_uint64)1000); + CPPUNIT_ASSERT_EQUAL(snk->nitems_read(0), (uint64_t)1000); CPPUNIT_ASSERT_THROW(snk->nitems_written(0), std::invalid_argument); } -- cgit From 3bf4a8423acded7743470adffcd9dcc57b049560 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 7 Nov 2010 17:30:59 -0500 Subject: Moving tags downstream is moved into gr_block_executor. Predefined three methods of moving tags that are selectable by a gr_block. --- gnuradio-core/src/lib/runtime/gr_block.cc | 11 ++++-- gnuradio-core/src/lib/runtime/gr_block.h | 10 +---- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 28 +++++++------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 19 +++++----- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 43 ++++++++++++++++++++++ .../src/lib/runtime/gr_tpb_thread_body.cc | 2 - 6 files changed, 77 insertions(+), 36 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 73a86e38b..1fb4633e5 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -166,12 +166,17 @@ gr_block::get_tags_in_range(unsigned int which_output, return d_detail->get_tags_in_range(which_output, start, end, key); } -void -gr_block::handle_tags() +int +gr_block::tag_handling_method() { - d_detail->handle_tags(); + return d_detail->tag_handling_method(); } +void +gr_block::set_tag_handling_method(int m) +{ + set_tag_handling_method(m); +} std::ostream& operator << (std::ostream& os, const gr_block *m) diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 4d1d6f875..4b246884e 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -208,14 +208,8 @@ class gr_block : public gr_basic_block { */ uint64_t nitems_written(unsigned int which_output); - - /*! - * \brief Function to move tags downstream - * - * The default behavior proxies to gr_block_detail, which just moves all tags - * from input to output and flows them all downstream. - */ - virtual void handle_tags(); + int tag_handling_method(); + void set_tag_handling_method(int m); // ---------------------------------------------------------------------------- diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index b3d1a7194..b7dc52a60 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -42,7 +42,7 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), d_done (false), - d_last_tag(0) + d_tag_handling_method(gr_block_detail::TAGS_ALL_TO_ALL) { s_ncurrently_allocated++; } @@ -203,18 +203,18 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, return found_items_by_key; } -void -gr_block_detail::handle_tags() -{ - for(unsigned int i = 0; i < d_ninputs; i++) { - pmt_t tuple; - while(d_input[i]->get_tag(d_last_tag, tuple)) { - d_last_tag++; - if(!sink_p()) { - for(unsigned int o = 0; o < d_noutputs; o++) { - d_output[o]->add_item_tag(tuple); - } - } - } +int +gr_block_detail::tag_handling_method() +{ + return d_tag_handling_method; +} + +void +gr_block_detail::set_tag_handling_method(int m) +{ + if((m == TAGS_ONE_TO_ONE) && (ninputs() != noutputs())) { + throw std::invalid_argument ("gr_block_detail::set_handling method to ONE-TO-ONE requires ninputs == noutputs"); } + + d_tag_handling_method = m; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 3a2b82190..711f59cf0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -37,6 +37,13 @@ */ class gr_block_detail { public: + + enum { + TAGS_NONE = 0, + TAGS_ALL_TO_ALL = 1, + TAGS_ONE_TO_ONE = 2 + }; + ~gr_block_detail (); int ninputs () const { return d_ninputs; } @@ -153,13 +160,8 @@ class gr_block_detail { uint64_t abs_end, const pmt::pmt_t &key); - /*! - * \brief Default tag handler; moves all tags downstream - * - * Move all tags from input to output and flows them all downstream. Each input - * stream's tags get appended to each output streams tags. - */ - void handle_tags(); + int tag_handling_method(); + void set_tag_handling_method(int m); gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -172,8 +174,7 @@ class gr_block_detail { std::vector d_input; std::vector d_output; bool d_done; - - size_t d_last_tag; // keep track of which tags we've already received from upstream + int d_tag_handling_method; gr_block_detail (unsigned int ninputs, unsigned int noutputs); diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 2c21a0b0f..f201c3937 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -294,12 +294,55 @@ gr_block_executor::run_one_iteration() for (int i = 0; i < d->noutputs (); i++) d_output_items[i] = d->output(i)->write_pointer(); + // store number of items consumed so far on in stream + std::vector start_count; + for (int i = 0; i < d->ninputs(); i++) + start_count.push_back(d->nitems_read(i)); + // Do the actual work of the block int n = m->general_work (noutput_items, d_ninput_items, d_input_items, d_output_items); LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); + // store number of items consumed after work + std::vector end_count; + for (int i = 0; i < d->ninputs (); i++) + end_count.push_back(d->nitems_read(i)); + + // Move tags downstream + // if a sink, we don't need to move downstream; + // and do not bother if block uses TAGS_NONE attribute + if(!d->sink_p() && (d->tag_handling_method() != gr_block_detail::TAGS_NONE)) { + + // every tag on every input propogates to everyone downstream + if(d->tag_handling_method() == gr_block_detail::TAGS_ALL_TO_ALL) { + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(*t); + } + } + } + + // tags from input i only go to output i + // this requires d->ninputs() == d->noutputs; this is checked when this + // type of tag-handling system is selected in gr_block_detail + else if(d->tag_handling_method() == gr_block_detail::TAGS_ONE_TO_ONE) { + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + d->output(i)->add_item_tag(*t); + } + } + } + + // else ; do nothing + } + if (n == gr_block::WORK_DONE) goto were_done; diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index 6a84f4be8..03eef17d9 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -45,8 +45,6 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) while ((msg = d->d_tpb.delete_head_nowait())) block->handle_msg(msg); - block->handle_tags(); - d->d_tpb.clear_changed(); s = d_exec.run_one_iteration(); -- cgit From 23285af07c88890daea3c9da011f983ae0e0da2d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 7 Nov 2010 18:39:15 -0500 Subject: Moving tag handling setup back into gr_block so it can be set in the constructor of a derived block. --- gnuradio-core/src/lib/runtime/gr_block.cc | 15 +++++++++++---- gnuradio-core/src/lib/runtime/gr_block.h | 15 ++++++++++++++- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 19 +------------------ gnuradio-core/src/lib/runtime/gr_block_detail.h | 11 ----------- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 20 ++++++++++++-------- 5 files changed, 38 insertions(+), 42 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 1fb4633e5..94cf23103 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -36,7 +36,8 @@ gr_block::gr_block (const std::string &name, d_output_multiple (1), d_relative_rate (1.0), d_history(1), - d_fixed_rate(false) + d_fixed_rate(false), + d_tag_handling_method(TAGS_ALL_TO_ALL) { } @@ -166,16 +167,22 @@ gr_block::get_tags_in_range(unsigned int which_output, return d_detail->get_tags_in_range(which_output, start, end, key); } -int +int gr_block::tag_handling_method() { - return d_detail->tag_handling_method(); + return d_tag_handling_method; } void gr_block::set_tag_handling_method(int m) { - set_tag_handling_method(m); + /* + if((m == TAGS_ONE_TO_ONE) && (ninputs() != noutputs())) { + throw std::invalid_argument ("gr_block::set_handling method to ONE-TO-ONE requires ninputs == noutputs"); + } + */ + + d_tag_handling_method = m; } std::ostream& diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 4b246884e..e278e8e9c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -25,6 +25,12 @@ #include +enum { + TAGS_NONE = 0, + TAGS_ALL_TO_ALL = 1, + TAGS_ONE_TO_ONE = 2 +}; + /*! * \brief The abstract base class for all 'terminal' processing blocks. * \ingroup base_blk @@ -208,7 +214,14 @@ class gr_block : public gr_basic_block { */ uint64_t nitems_written(unsigned int which_output); + /*! + * \brief Asks for the method used by the scheduler to moved tags downstream. + */ int tag_handling_method(); + + /*! + * \brief Used by the scheduler to determine how tags are moved downstream. + */ void set_tag_handling_method(int m); // ---------------------------------------------------------------------------- @@ -220,6 +233,7 @@ class gr_block : public gr_basic_block { gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; + int d_tag_handling_method; protected: @@ -285,7 +299,6 @@ class gr_block : public gr_basic_block { uint64_t abs_end, const pmt::pmt_t &key); - // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friends diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index b7dc52a60..1888b8839 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -41,8 +41,7 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_produce_or(0), d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), - d_done (false), - d_tag_handling_method(gr_block_detail::TAGS_ALL_TO_ALL) + d_done (false) { s_ncurrently_allocated++; } @@ -202,19 +201,3 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, return found_items_by_key; } - -int -gr_block_detail::tag_handling_method() -{ - return d_tag_handling_method; -} - -void -gr_block_detail::set_tag_handling_method(int m) -{ - if((m == TAGS_ONE_TO_ONE) && (ninputs() != noutputs())) { - throw std::invalid_argument ("gr_block_detail::set_handling method to ONE-TO-ONE requires ninputs == noutputs"); - } - - d_tag_handling_method = m; -} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 711f59cf0..929e36fc8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -37,13 +37,6 @@ */ class gr_block_detail { public: - - enum { - TAGS_NONE = 0, - TAGS_ALL_TO_ALL = 1, - TAGS_ONE_TO_ONE = 2 - }; - ~gr_block_detail (); int ninputs () const { return d_ninputs; } @@ -160,9 +153,6 @@ class gr_block_detail { uint64_t abs_end, const pmt::pmt_t &key); - int tag_handling_method(); - void set_tag_handling_method(int m); - gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -174,7 +164,6 @@ class gr_block_detail { std::vector d_input; std::vector d_output; bool d_done; - int d_tag_handling_method; gr_block_detail (unsigned int ninputs, unsigned int noutputs); diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index f201c3937..3fc536845 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -313,10 +313,10 @@ gr_block_executor::run_one_iteration() // Move tags downstream // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p() && (d->tag_handling_method() != gr_block_detail::TAGS_NONE)) { + if(!d->sink_p() && (m->tag_handling_method() != TAGS_NONE)) { // every tag on every input propogates to everyone downstream - if(d->tag_handling_method() == gr_block_detail::TAGS_ALL_TO_ALL) { + if(m->tag_handling_method() == TAGS_ALL_TO_ALL) { for(int i = 0; i < d->ninputs(); i++) { std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); std::vector::iterator t; @@ -330,14 +330,18 @@ gr_block_executor::run_one_iteration() // tags from input i only go to output i // this requires d->ninputs() == d->noutputs; this is checked when this // type of tag-handling system is selected in gr_block_detail - else if(d->tag_handling_method() == gr_block_detail::TAGS_ONE_TO_ONE) { - for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); - std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { - d->output(i)->add_item_tag(*t); + else if(m->tag_handling_method() == TAGS_ONE_TO_ONE) { + if(d->ninputs() != d->noutputs()) { + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + d->output(i)->add_item_tag(*t); + } } } + else + throw std::invalid_argument ("handling method 'ONE-TO-ONE' requires ninputs == noutputs"); } // else ; do nothing -- cgit From 75c9c767079868b1c938fbb9a8c5522a60f28c96 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 19:20:19 -0500 Subject: cleaning up; comments, naming, typos, excess code, etc. Moving to make gr_block_executor more readable. --- gnuradio-core/src/lib/runtime/gr_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block.h | 22 +++++++++------------- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 22 +++++++++------------- gnuradio-core/src/lib/runtime/gr_buffer.h | 19 ++----------------- .../src/lib/runtime/gr_random_annotator.cc | 2 +- 7 files changed, 25 insertions(+), 48 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 94cf23103..b3e6b0edc 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -37,7 +37,7 @@ gr_block::gr_block (const std::string &name, d_relative_rate (1.0), d_history(1), d_fixed_rate(false), - d_tag_handling_method(TAGS_ALL_TO_ALL) + d_tag_handling_method(TPP_ALL_TO_ALL) { } diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index e278e8e9c..be39a7b95 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -25,12 +25,6 @@ #include -enum { - TAGS_NONE = 0, - TAGS_ALL_TO_ALL = 1, - TAGS_ONE_TO_ONE = 2 -}; - /*! * \brief The abstract base class for all 'terminal' processing blocks. * \ingroup base_blk @@ -69,6 +63,12 @@ class gr_block : public gr_basic_block { WORK_DONE = -1 }; + enum TAG_PROPOGATION_POLICY { + TPP_DONT = 0, + TPP_ALL_TO_ALL = 1, + TPP_ONE_TO_ONE = 2 + }; + virtual ~gr_block (); /*! @@ -247,12 +247,10 @@ class gr_block : public gr_basic_block { /*! * \brief Adds a new tag onto the given output buffer. * - * This is a call-through method to gr_block_detail. - * * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. - * \param key a PMT symbol holding the key name + * \param key the tag key as a PMT symbol * \param value any PMT holding any value for the given key * \param srcid optional source ID specifier; defaults to PMT_F */ @@ -265,8 +263,7 @@ class gr_block : public gr_basic_block { /*! * \brief Given a [start,end), returns a vector of all tags in the range. * - * Pass-through function to gr_block_detail. Range of counts is from - * start to end-1. + * Range of counts is from start to end-1. * * Tags are tuples of: * (item count, source id, key, value) @@ -283,8 +280,7 @@ class gr_block : public gr_basic_block { * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. * - * Pass-through function to gr_block_detail. Range of counts is from - * start to end-1. + * Range of counts is from start to end-1. * * Tags are tuples of: * (item count, source id, key, value) diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 1888b8839..4f3ffc8dc 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -157,7 +157,7 @@ gr_block_detail::add_item_tag(unsigned int which_output, const pmt_t &srcid) { if(!pmt_is_symbol(key)) { - throw pmt_wrong_type("gr_block_detail::set_item_tag key", key); + throw pmt_wrong_type("gr_block_detail::add_item_tag key", key); } else { // build tag tuple diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 929e36fc8..5902d1559 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -105,7 +105,7 @@ class gr_block_detail { * \param which_ouput an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. - * \param key a PMT symbol holding the key name (i.e., a string) + * \param key the tag key as a PMT symbol * \param value any PMT holding any value for the given key * \param srcid a PMT source ID specifier */ @@ -146,7 +146,7 @@ class gr_block_detail { * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest - * \param key a PMT symbol key to select only tags of this key + * \param key a PMT symbol to select only tags of this key */ std::vector get_tags_in_range(unsigned int which_input, uint64_t abs_start, diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 3fc536845..c43f22895 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -295,9 +295,10 @@ gr_block_executor::run_one_iteration() d_output_items[i] = d->output(i)->write_pointer(); // store number of items consumed so far on in stream - std::vector start_count; + std::vector d_start_nitems_read; + d_start_nitems_read.resize(d->ninputs()); for (int i = 0; i < d->ninputs(); i++) - start_count.push_back(d->nitems_read(i)); + d_start_nitems_read[i] = d->nitems_read(i); // Do the actual work of the block int n = m->general_work (noutput_items, d_ninput_items, @@ -305,20 +306,15 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - // store number of items consumed after work - std::vector end_count; - for (int i = 0; i < d->ninputs (); i++) - end_count.push_back(d->nitems_read(i)); - // Move tags downstream // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p() && (m->tag_handling_method() != TAGS_NONE)) { + if(!d->sink_p() && (m->tag_handling_method() != gr_block::TPP_DONT)) { // every tag on every input propogates to everyone downstream - if(m->tag_handling_method() == TAGS_ALL_TO_ALL) { + if(m->tag_handling_method() == gr_block::TPP_ALL_TO_ALL) { for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { for(int o = 0; o < d->noutputs(); o++) @@ -330,10 +326,10 @@ gr_block_executor::run_one_iteration() // tags from input i only go to output i // this requires d->ninputs() == d->noutputs; this is checked when this // type of tag-handling system is selected in gr_block_detail - else if(m->tag_handling_method() == TAGS_ONE_TO_ONE) { - if(d->ninputs() != d->noutputs()) { + else if(m->tag_handling_method() == gr_block::TPP_ONE_TO_ONE) { + if(d->ninputs() == d->noutputs()) { for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_count[i], end_count[i]); + std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { d->output(i)->add_item_tag(*t); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 5b8f21c94..5f11b4581 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -102,17 +102,6 @@ class gr_buffer { std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } std::deque::iterator get_tags_end() { return d_item_tags.end(); } - bool get_tag(size_t n, pmt::pmt_t &t) - { - if(n < d_item_tags.size()) { - t = d_item_tags[n]; - return true; - } - else { - return false; - } - } - // ------------------------------------------------------------------------- private: @@ -130,7 +119,8 @@ class gr_buffer { std::vector d_readers; boost::weak_ptr d_link; // block that writes to this buffer - std::deque d_item_tags; // temp. store tags until moved to reader + std::deque d_item_tags; + // // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's @@ -272,11 +262,6 @@ class gr_buffer_reader { std::vector get_tags_in_range(uint64_t abs_start, uint64_t abs_end); - bool get_tag(size_t n, pmt::pmt_t &t) - { - return d_buffer->get_tag(n, t); - } - // ------------------------------------------------------------------------- private: diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index d360c13a5..08589984e 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -60,7 +60,7 @@ gr_random_annotator::work (int noutput_items, std::stringstream str; str << name() << unique_id(); - uint64_t abs_N = nitems_written(0); + uint64_t abs_N = nitems_read(0) + noutput_items; std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); std::vector::iterator itr; -- cgit From 0a2cb50b6b7e50bb69df9478e49db4d77599c324 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 19:30:54 -0500 Subject: Renaming "handling_method" to "propagation_policy". --- gnuradio-core/src/lib/runtime/gr_block.cc | 16 +++++----------- gnuradio-core/src/lib/runtime/gr_block.h | 12 ++++++------ gnuradio-core/src/lib/runtime/gr_block_executor.cc | 10 +++++----- 3 files changed, 16 insertions(+), 22 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index b3e6b0edc..e595b60b8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -37,7 +37,7 @@ gr_block::gr_block (const std::string &name, d_relative_rate (1.0), d_history(1), d_fixed_rate(false), - d_tag_handling_method(TPP_ALL_TO_ALL) + d_tag_propagation_policy(TPP_ALL_TO_ALL) { } @@ -168,21 +168,15 @@ gr_block::get_tags_in_range(unsigned int which_output, } int -gr_block::tag_handling_method() +gr_block::tag_propagation_policy() { - return d_tag_handling_method; + return d_tag_propagation_policy; } void -gr_block::set_tag_handling_method(int m) +gr_block::set_tag_propagation_policy(TAG_PROPAGATION_POLICY p) { - /* - if((m == TAGS_ONE_TO_ONE) && (ninputs() != noutputs())) { - throw std::invalid_argument ("gr_block::set_handling method to ONE-TO-ONE requires ninputs == noutputs"); - } - */ - - d_tag_handling_method = m; + d_tag_propagation_policy = p; } std::ostream& diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index be39a7b95..e2f00bb6f 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -63,7 +63,7 @@ class gr_block : public gr_basic_block { WORK_DONE = -1 }; - enum TAG_PROPOGATION_POLICY { + enum TAG_PROPAGATION_POLICY { TPP_DONT = 0, TPP_ALL_TO_ALL = 1, TPP_ONE_TO_ONE = 2 @@ -215,14 +215,14 @@ class gr_block : public gr_basic_block { uint64_t nitems_written(unsigned int which_output); /*! - * \brief Asks for the method used by the scheduler to moved tags downstream. + * \brief Asks for the policy used by the scheduler to moved tags downstream. */ - int tag_handling_method(); + int tag_propagation_policy(); /*! - * \brief Used by the scheduler to determine how tags are moved downstream. + * \brief Set the policy by the scheduler to determine how tags are moved downstream. */ - void set_tag_handling_method(int m); + void set_tag_propagation_policy(TAG_PROPAGATION_POLICY p); // ---------------------------------------------------------------------------- @@ -233,7 +233,7 @@ class gr_block : public gr_basic_block { gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; - int d_tag_handling_method; + TAG_PROPAGATION_POLICY d_tag_propagation_policy; // policy for moving tags downstream protected: diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index c43f22895..35aa8cf1e 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -309,10 +309,10 @@ gr_block_executor::run_one_iteration() // Move tags downstream // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p() && (m->tag_handling_method() != gr_block::TPP_DONT)) { + if(!d->sink_p() && (m->tag_propagation_policy() != gr_block::TPP_DONT)) { // every tag on every input propogates to everyone downstream - if(m->tag_handling_method() == gr_block::TPP_ALL_TO_ALL) { + if(m->tag_propagation_policy() == gr_block::TPP_ALL_TO_ALL) { for(int i = 0; i < d->ninputs(); i++) { std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); std::vector::iterator t; @@ -325,8 +325,8 @@ gr_block_executor::run_one_iteration() // tags from input i only go to output i // this requires d->ninputs() == d->noutputs; this is checked when this - // type of tag-handling system is selected in gr_block_detail - else if(m->tag_handling_method() == gr_block::TPP_ONE_TO_ONE) { + // type of tag-propagation system is selected in gr_block_detail + else if(m->tag_propagation_policy() == gr_block::TPP_ONE_TO_ONE) { if(d->ninputs() == d->noutputs()) { for(int i = 0; i < d->ninputs(); i++) { std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); @@ -337,7 +337,7 @@ gr_block_executor::run_one_iteration() } } else - throw std::invalid_argument ("handling method 'ONE-TO-ONE' requires ninputs == noutputs"); + throw std::invalid_argument ("propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs"); } // else ; do nothing -- cgit From 4cb301dec845778e468c73dac5eb04a9dfccb14a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 19:46:32 -0500 Subject: Made propagate_tags a function to be called from block_executor to move tags downstream. Also made d_start_nitems_read a member of gr_block_executor to better handle allocation. --- gnuradio-core/src/lib/runtime/gr_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 88 ++++++++++++---------- gnuradio-core/src/lib/runtime/gr_block_executor.h | 1 + 4 files changed, 53 insertions(+), 40 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index e595b60b8..778344769 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -167,7 +167,7 @@ gr_block::get_tags_in_range(unsigned int which_output, return d_detail->get_tags_in_range(which_output, start, end, key); } -int +gr_block::TAG_PROPAGATION_POLICY gr_block::tag_propagation_policy() { return d_tag_propagation_policy; diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index e2f00bb6f..a717946d2 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -217,7 +217,7 @@ class gr_block : public gr_basic_block { /*! * \brief Asks for the policy used by the scheduler to moved tags downstream. */ - int tag_propagation_policy(); + TAG_PROPAGATION_POLICY tag_propagation_policy(); /*! * \brief Set the policy by the scheduler to determine how tags are moved downstream. diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 35aa8cf1e..7d19f44ab 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -87,7 +87,53 @@ min_available_space (gr_block_detail *d, int output_multiple) return min_space; } +static void +propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, + const std::vector &start_nitems_read) +{ + // Move tags downstream + // if a sink, we don't need to move downstream; + // and do not bother if block uses TAGS_NONE attribute + if(!d->sink_p()) { + return; + } + switch(policy) { + case(gr_block::TPP_DONT): + return; + break; + case(gr_block::TPP_ALL_TO_ALL): + // every tag on every input propogates to everyone downstream + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], d->nitems_read(i)); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(*t); + } + } + break; + case(gr_block::TPP_ONE_TO_ONE): + // tags from input i only go to output i + // this requires d->ninputs() == d->noutputs; this is checked when this + // type of tag-propagation system is selected in gr_block_detail + if(d->ninputs() == d->noutputs()) { + for(int i = 0; i < d->ninputs(); i++) { + std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], d->nitems_read(i)); + std::vector::iterator t; + for(t = tuple.begin(); t != tuple.end(); t++ ) { + d->output(i)->add_item_tag(*t); + } + } + } + else + throw std::invalid_argument ("propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs"); + + break; + default: + return; + } +} gr_block_executor::gr_block_executor (gr_block_sptr block) : d_block(block), d_log(0) @@ -134,6 +180,7 @@ gr_block_executor::run_one_iteration() d_input_items.resize (0); d_input_done.resize(0); d_output_items.resize (d->noutputs ()); + d_start_nitems_read.resize(0); // determine the minimum available output space noutput_items = min_available_space (d, m->output_multiple ()); @@ -155,6 +202,7 @@ gr_block_executor::run_one_iteration() d_input_items.resize (d->ninputs ()); d_input_done.resize(d->ninputs()); d_output_items.resize (0); + d_start_nitems_read.resize(d->ninputs()); LOG(*d_log << " sink\n"); max_items_avail = 0; @@ -198,6 +246,7 @@ gr_block_executor::run_one_iteration() d_input_items.resize (d->ninputs ()); d_input_done.resize(d->ninputs()); d_output_items.resize (d->noutputs ()); + d_start_nitems_read.resize(d->ninputs()); max_items_avail = 0; for (int i = 0; i < d->ninputs (); i++){ @@ -295,8 +344,6 @@ gr_block_executor::run_one_iteration() d_output_items[i] = d->output(i)->write_pointer(); // store number of items consumed so far on in stream - std::vector d_start_nitems_read; - d_start_nitems_read.resize(d->ninputs()); for (int i = 0; i < d->ninputs(); i++) d_start_nitems_read[i] = d->nitems_read(i); @@ -306,42 +353,7 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - // Move tags downstream - // if a sink, we don't need to move downstream; - // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p() && (m->tag_propagation_policy() != gr_block::TPP_DONT)) { - - // every tag on every input propogates to everyone downstream - if(m->tag_propagation_policy() == gr_block::TPP_ALL_TO_ALL) { - for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); - std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { - for(int o = 0; o < d->noutputs(); o++) - d->output(o)->add_item_tag(*t); - } - } - } - - // tags from input i only go to output i - // this requires d->ninputs() == d->noutputs; this is checked when this - // type of tag-propagation system is selected in gr_block_detail - else if(m->tag_propagation_policy() == gr_block::TPP_ONE_TO_ONE) { - if(d->ninputs() == d->noutputs()) { - for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, d_start_nitems_read[i], d->nitems_read(i)); - std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { - d->output(i)->add_item_tag(*t); - } - } - } - else - throw std::invalid_argument ("propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs"); - } - - // else ; do nothing - } + propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read); if (n == gr_block::WORK_DONE) goto were_done; diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h index 41b5ede7c..22b782883 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.h +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -47,6 +47,7 @@ protected: gr_vector_const_void_star d_input_items; std::vector d_input_done; gr_vector_void_star d_output_items; + std::vector d_start_nitems_read; //stores where tag counts are before work public: gr_block_executor(gr_block_sptr block); -- cgit From ab8c921bf73b61c19305bc0bf1fc4d26b110779e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 19:52:50 -0500 Subject: Adding mutex protection around adding and getting tags from buffers. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 3 +++ gnuradio-core/src/lib/runtime/gr_buffer.h | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 862d92b81..1d67470ec 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -219,6 +219,7 @@ gr_buffer::drop_reader (gr_buffer_reader *reader) void gr_buffer::add_item_tag(const pmt::pmt_t &tag) { + gruel::scoped_lock guard(*mutex()); d_item_tags.push_back(tag); } @@ -267,6 +268,8 @@ std::vector gr_buffer_reader::get_tags_in_range(uint64_t abs_start, uint64_t abs_end) { + gruel::scoped_lock guard(*mutex()); + std::vector found_items; std::deque::iterator itr = d_buffer->get_tags_begin(); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 5f11b4581..d6d5564e8 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -119,18 +119,16 @@ class gr_buffer { std::vector d_readers; boost::weak_ptr d_link; // block that writes to this buffer - std::deque d_item_tags; - - // - // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's - // and d_abs_read_offset's in the buffer readers. + // The mutex protects d_write_index, d_abs_write_offset, d_done, d_item_tags + // and the d_read_index's and d_abs_read_offset's in the buffer readers. // gruel::mutex d_mutex; unsigned int d_write_index; // in items [0,d_bufsize) uint64_t d_abs_write_offset; // num items written since the start - //deq tag_tuples bool d_done; + std::deque d_item_tags; + unsigned index_add (unsigned a, unsigned b) -- cgit From ec79e6f688c0ef94e66c938eba24c8b95e9856ba Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 20:03:21 -0500 Subject: Burned by another copy-paste error. Correctly checking and acting if its a sink. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 7d19f44ab..804c9e197 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -94,7 +94,7 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // Move tags downstream // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute - if(!d->sink_p()) { + if(d->sink_p()) { return; } -- cgit From 9eeb6dbaa1398946229db780f2eb1ca4e9eae04b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 8 Nov 2010 01:44:16 -0500 Subject: Adding a bit more checking on file operations. --- gnuradio-core/src/lib/runtime/gr_preferences.cc | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index e0be2db62..5f7412248 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2003 Free Software Foundation, Inc. + * Copyright 2003,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -77,11 +77,20 @@ gr_preferences::get (const char *key) static char buf[1024]; FILE *fp = fopen (pathname (key), "r"); - if (fp == 0) + if (fp == 0) { + perror (pathname (key)); return 0; + } memset (buf, 0, sizeof (buf)); - fread (buf, 1, sizeof (buf) - 1, fp); + size_t ret = fread (buf, 1, sizeof (buf) - 1, fp); + if(ret == 0) { + if(ferror(fp) != 0) { + perror (pathname (key)); + fclose (fp); + return 0; + } + } fclose (fp); return buf; } @@ -97,6 +106,13 @@ gr_preferences::set (const char *key, const char *value) return; } - fwrite (value, 1, strlen (value), fp); + size_t ret = fwrite (value, 1, strlen (value), fp); + if(ret == 0) { + if(ferror(fp) != 0) { + perror (pathname (key)); + fclose (fp); + return; + } + } fclose (fp); }; -- cgit From 1caa7d707377d093cf7d9b7e65176848a93bba5c Mon Sep 17 00:00:00 2001 From: Rob Savoye Date: Sat, 16 Oct 2010 08:51:47 -0600 Subject: wrap all %pythoncode in SWIGPYTHON so they don't get inserted into other languages --- gnuradio-core/src/lib/runtime/gr_basic_block.i | 6 ++++++ gnuradio-core/src/lib/runtime/gr_block.i | 5 +++++ gnuradio-core/src/lib/runtime/gr_msg_queue.i | 5 +++++ 3 files changed, 16 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 60e08aac3..847ef3689 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -47,6 +47,12 @@ public: %rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; long gr_basic_block_ncurrently_allocated(); +#ifdef SWIGPYTHON %pythoncode %{ gr_basic_block_sptr.__repr__ = lambda self: "" % (self.name(), self.unique_id ()) %} +#endif + +#ifdef SWIGGUILE +#endif + diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index c2e2aa4b8..d89e638b2 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -54,7 +54,12 @@ class gr_block : public gr_basic_block { void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } }; +#ifdef SWIGPYTHON %pythoncode %{ gr_block_sptr.__repr__ = lambda self: "" % (self.name(), self.unique_id ()) gr_block_sptr.block = lambda self: self %} +#endif + +#ifdef SWIGGUILE +#endif diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 9ca92b6ec..64aea602a 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -97,9 +97,14 @@ public: } %} +#ifdef SWIGPYTHON // smash in new python delete_head and insert_tail methods... %pythoncode %{ gr_msg_queue_sptr.delete_head = gr_py_msg_queue__delete_head gr_msg_queue_sptr.insert_tail = gr_py_msg_queue__insert_tail gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail %} +#endif + +#ifdef SWIGGUILE +#endif -- cgit From 422d912f685b412bdfd91f088628da6f5f8196ba Mon Sep 17 00:00:00 2001 From: Rob Savoye Date: Sat, 16 Oct 2010 08:53:40 -0600 Subject: wrap pyrun python code in SWIGPYTHON ifdef so it doesn't appear in other languages --- gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i index 5e9032449..2378a1880 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i @@ -42,6 +42,7 @@ class gr_single_threaded_scheduler { gr_single_threaded_scheduler (const std::vector &modules); }; +#ifdef SWIGPYTHON %inline %{ void sts_pyrun (gr_single_threaded_scheduler_sptr s) { Py_BEGIN_ALLOW_THREADS; // release global interpreter lock @@ -49,3 +50,5 @@ class gr_single_threaded_scheduler { Py_END_ALLOW_THREADS; // acquire global interpreter lock } %} +#endif + -- cgit From 54bfe42875fc8625b193b63dc8a4d7327e89edc2 Mon Sep 17 00:00:00 2001 From: Rob Savoye Date: Sat, 16 Oct 2010 09:47:39 -0600 Subject: add #warning for missing guile support --- gnuradio-core/src/lib/runtime/gr_basic_block.i | 1 + gnuradio-core/src/lib/runtime/gr_block.i | 1 + gnuradio-core/src/lib/runtime/gr_msg_queue.i | 3 ++- gnuradio-core/src/lib/runtime/gr_top_block.i | 8 ++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 847ef3689..f1de9e08a 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -54,5 +54,6 @@ gr_basic_block_sptr.__repr__ = lambda self: "" % (self.n #endif #ifdef SWIGGUILE +#warning "gr_basic_block.i: gr_block_sptr needs to be implemented!" #endif diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index d89e638b2..d13c268ca 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -62,4 +62,5 @@ gr_block_sptr.block = lambda self: self #endif #ifdef SWIGGUILE +#warning "gr_block.i: gr_block_sptr needs to be implemented!" #endif diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 64aea602a..5b8fea49f 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -81,6 +81,7 @@ public: * functions into the gr.msg_queue wrapper class, so that everything * appears normal. (An evil laugh is heard in the distance...) */ +#ifdef SWIGPYTHON %inline %{ gr_message_sptr gr_py_msg_queue__delete_head(gr_msg_queue_sptr q) { gr_message_sptr msg; @@ -97,7 +98,6 @@ public: } %} -#ifdef SWIGPYTHON // smash in new python delete_head and insert_tail methods... %pythoncode %{ gr_msg_queue_sptr.delete_head = gr_py_msg_queue__delete_head @@ -107,4 +107,5 @@ gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail #endif #ifdef SWIGGUILE +#warning "gr_msg_queue.i: gr_msg_queue_sptr needs to be implemented!" #endif diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 670e5b5e5..579ef8f70 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -49,6 +49,8 @@ public: void dump(); }; +#ifdef SWIGPYTHON + %inline %{ void top_block_run_unlocked(gr_top_block_sptr r) throw (std::runtime_error) { @@ -64,3 +66,9 @@ void top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error) Py_END_ALLOW_THREADS; // acquire global interpreter lock } %} + +#endif + +#ifdef SWIG_GUILE +#warning "gr_top_block.i: top_block_run_unlocked needs to be implemented!" +#endif -- cgit From cbfffe4100daff91746db0b6ea66cec9f7b2ceed Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Fri, 29 Oct 2010 02:20:32 -0700 Subject: Move sizeof_* from gnuradio.i to runtime.i to avoid multiple definitions --- gnuradio-core/src/lib/runtime/runtime.i | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 20cf68a03..ca89b8fbd 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -40,6 +40,13 @@ #include %} +%constant int sizeof_char = sizeof(char); +%constant int sizeof_short = sizeof(short); +%constant int sizeof_int = sizeof(int); +%constant int sizeof_float = sizeof(float); +%constant int sizeof_double = sizeof(double); +%constant int sizeof_gr_complex = sizeof(gr_complex); + %include %include %include -- cgit From c34cf20f501dea19385cb42bf31e92ad889e7040 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sat, 30 Oct 2010 18:17:12 -0700 Subject: Rename basic_block coersion method to to_basic_block. Add to_hier_block2 and to_top_block. basic_block was renamed because the number of guile generic methods on basic_block was getting large and confusing. to_hier_block2 and to_top_block were added to support coercion to those types in guile (and python). This change simplifies the handling of "connect" in guile. --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_basic_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_basic_block.i | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 5 +++++ gnuradio-core/src/lib/runtime/gr_hier_block2.h | 2 ++ gnuradio-core/src/lib/runtime/gr_hier_block2.i | 2 ++ gnuradio-core/src/lib/runtime/gr_top_block.cc | 6 ++++++ gnuradio-core/src/lib/runtime/gr_top_block.h | 7 +++++++ gnuradio-core/src/lib/runtime/gr_top_block.i | 2 ++ 9 files changed, 27 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 2fa1066cb..0e0dad16b 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -56,7 +56,7 @@ gr_basic_block::~gr_basic_block() } gr_basic_block_sptr -gr_basic_block::basic_block() +gr_basic_block::to_basic_block() { return shared_from_this(); } diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index b8797fdc6..d059a4bd3 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -81,7 +81,7 @@ public: std::string name() const { return d_name; } gr_io_signature_sptr input_signature() const { return d_input_signature; } gr_io_signature_sptr output_signature() const { return d_output_signature; } - gr_basic_block_sptr basic_block(); // Needed for Python type coercion + gr_basic_block_sptr to_basic_block(); // Needed for Python/Guile type coercion /*! * \brief Confirm that ninputs and noutputs is an acceptable combination. diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index f1de9e08a..9b360e5ab 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -40,7 +40,7 @@ public: gr_io_signature_sptr input_signature() const; gr_io_signature_sptr output_signature() const; long unique_id() const; - gr_basic_block_sptr basic_block(); + gr_basic_block_sptr to_basic_block(); bool check_topology (int ninputs, int noutputs); }; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index e3a25e1a8..d6e317136 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -61,6 +61,11 @@ gr_hier_block2::self() return shared_from_this(); } +gr_hier_block2_sptr +gr_hier_block2::to_hier_block2() +{ + return cast_to_hier_block2_sptr(shared_from_this()); +} void gr_hier_block2::connect(gr_basic_block_sptr block) diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index f50b1cb94..0a40c36b7 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -147,6 +147,8 @@ public: // This is a public method for ease of code organization, but should be // ignored by the user. gr_flat_flowgraph_sptr flatten() const; + + gr_hier_block2_sptr to_hier_block2(); // Needed for Python/Guile type coercion }; inline gr_hier_block2_sptr cast_to_hier_block2_sptr(gr_basic_block_sptr block) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index a62f50e84..1b974fd6b 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -57,4 +57,6 @@ public: void disconnect_all(); void lock(); void unlock(); + + gr_hier_block2_sptr to_hier_block2(); // Needed for Python/Guile type coercion }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 09e46dfbb..f341525c0 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -95,3 +95,9 @@ gr_top_block::dump() { d_impl->dump(); } + +gr_top_block_sptr +gr_top_block::to_top_block() +{ + return cast_to_top_block_sptr(shared_from_this()); +} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 8052954e3..ed244cb7c 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -105,6 +105,13 @@ public: * Displays flattened flowgraph edges and block connectivity */ void dump(); + + gr_top_block_sptr to_top_block(); // Needed for Python/Guile type coercion }; +inline gr_top_block_sptr cast_to_top_block_sptr(gr_basic_block_sptr block) { + return boost::dynamic_pointer_cast(block); +} + + #endif /* INCLUDED_GR_TOP_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 579ef8f70..d9adf1e18 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -47,6 +47,8 @@ public: void lock(); void unlock() throw (std::runtime_error); void dump(); + + gr_top_block_sptr to_top_block(); // Needed for Python/Guile type coercion }; #ifdef SWIGPYTHON -- cgit From 8fe7f0fe5fe89f6ec32732dd802608060e973f0d Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sun, 31 Oct 2010 20:03:35 -0700 Subject: Cleanup gr:connect and gr:disconnect for Guile. Rename {dis,}connect to {dis,}primitive_connect in .i file. Update python code to reflect change. --- gnuradio-core/src/lib/runtime/gr_hier_block2.i | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index 1b974fd6b..32b656e24 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -34,6 +34,11 @@ gr_hier_block2_sptr gr_make_hier_block2(const std::string name, gr_io_signature_sptr output_signature) throw (std::runtime_error); +// Rename connect and disconnect so that we can more easily build a +// better interface in scripting land. +%rename(primitive_connect) gr_hier_block2::connect; +%rename(primitive_disconnect) gr_hier_block2::disconnect; + class gr_hier_block2 : public gr_basic_block { private: -- cgit From 941c9a792f103c48de6157026d08d7b0a6bae227 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Mon, 8 Nov 2010 14:03:19 -0800 Subject: Enable test case & fix (missing throw (std::runtime_error) declaration). --- gnuradio-core/src/lib/runtime/gr_top_block.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index d9adf1e18..f18d8890b 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -43,7 +43,7 @@ public: void start() throw (std::runtime_error); void stop(); void wait(); - void run(); + void run() throw (std::runtime_error); void lock(); void unlock() throw (std::runtime_error); void dump(); -- cgit From c204913321f0618ac131738088dab23065bdfa80 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 14:19:02 -0500 Subject: Fixed small bug in how tags are propagated downstream. Also using seq. numbers in annotator test block to better keep track. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_random_annotator.cc | 7 ++++++- gnuradio-core/src/lib/runtime/gr_random_annotator.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 804c9e197..840cf8e5c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -343,9 +343,9 @@ gr_block_executor::run_one_iteration() for (int i = 0; i < d->noutputs (); i++) d_output_items[i] = d->output(i)->write_pointer(); - // store number of items consumed so far on in stream + // determine where to start looking for new tags as 1 past nitems read for (int i = 0; i < d->ninputs(); i++) - d_start_nitems_read[i] = d->nitems_read(i); + d_start_nitems_read[i] = d->nitems_read(i)+1; // Do the actual work of the block int n = m->general_work (noutput_items, d_ninput_items, diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc index 08589984e..366130984 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc @@ -42,6 +42,11 @@ gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) gr_make_io_signature (1, -1, sizeof_stream_item)), d_itemsize(sizeof_stream_item) { + //set_tag_propagation_policy(TPP_DONT); + set_tag_propagation_policy(TPP_ALL_TO_ALL); + //set_tag_propagation_policy(TPP_ONE_TO_ONE); + + d_tag_counter = 0; } gr_random_annotator::~gr_random_annotator () @@ -86,7 +91,7 @@ gr_random_annotator::work (int noutput_items, } // Storing the current noutput_items as the value to the "noutput_items" key - pmt::pmt_t cur_N = pmt::pmt_from_uint64(random()); + pmt::pmt_t cur_N = pmt::pmt_from_uint64(d_tag_counter++); pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); pmt::pmt_t key = pmt::pmt_string_to_symbol("noutput_items"); add_item_tag(0, abs_N, key, cur_N, srcid); diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h index 3f21b71ad..5fca53830 100644 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.h +++ b/gnuradio-core/src/lib/runtime/gr_random_annotator.h @@ -46,6 +46,7 @@ protected: private: size_t d_itemsize; std::stringstream d_sout; + uint64_t d_tag_counter; friend gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); -- cgit From 9aaf98cff5e03ec2821da492f3857780a767258f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 15:55:04 -0500 Subject: Renaming random_annotator to annotator_1toall that moves tags from single input to all outputs. --- gnuradio-core/src/lib/runtime/Makefile.am | 3 - .../src/lib/runtime/gr_random_annotator.cc | 100 --------------------- .../src/lib/runtime/gr_random_annotator.h | 55 ------------ .../src/lib/runtime/gr_random_annotator.i | 32 ------- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 23 +++-- gnuradio-core/src/lib/runtime/runtime.i | 2 - 6 files changed, 15 insertions(+), 200 deletions(-) delete mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.h delete mode 100644 gnuradio-core/src/lib/runtime/gr_random_annotator.i (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 1af91d80d..4c52f3ab0 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -49,7 +49,6 @@ libruntime_la_SOURCES = \ gr_msg_queue.cc \ gr_pagesize.cc \ gr_preferences.cc \ - gr_random_annotator.cc \ gr_realtime.cc \ gr_scheduler.cc \ gr_scheduler_sts.cc \ @@ -104,7 +103,6 @@ grinclude_HEADERS = \ gr_msg_queue.h \ gr_pagesize.h \ gr_preferences.h \ - gr_random_annotator.h \ gr_realtime.h \ gr_runtime_types.h \ gr_scheduler.h \ @@ -155,7 +153,6 @@ swiginclude_HEADERS = \ gr_message.i \ gr_msg_handler.i \ gr_msg_queue.i \ - gr_random_annotator.i \ gr_realtime.i \ gr_single_threaded_scheduler.i \ gr_sync_block.i \ diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc b/gnuradio-core/src/lib/runtime/gr_random_annotator.cc deleted file mode 100644 index 366130984..000000000 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -gr_random_annotator_sptr -gr_make_random_annotator (size_t sizeof_stream_item) -{ - return gnuradio::get_initial_sptr (new gr_random_annotator (sizeof_stream_item)); -} - -gr_random_annotator::gr_random_annotator (size_t sizeof_stream_item) - : gr_sync_block ("random_annotator", - gr_make_io_signature (1, -1, sizeof_stream_item), - gr_make_io_signature (1, -1, sizeof_stream_item)), - d_itemsize(sizeof_stream_item) -{ - //set_tag_propagation_policy(TPP_DONT); - set_tag_propagation_policy(TPP_ALL_TO_ALL); - //set_tag_propagation_policy(TPP_ONE_TO_ONE); - - d_tag_counter = 0; -} - -gr_random_annotator::~gr_random_annotator () -{ - std::cout << d_sout.str(); -} - -int -gr_random_annotator::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const float **in = (const float **) &input_items[0]; - float **out = (float **) &output_items[0]; - - std::stringstream str; - str << name() << unique_id(); - - uint64_t abs_N = nitems_read(0) + noutput_items; - std::vector all_tags = get_tags_in_range(0, (uint64_t)0, abs_N); - std::vector::iterator itr; - - d_sout << std::endl << "Found " << all_tags.size() << " tags." << std::endl; - d_sout.setf(std::ios::left); - d_sout << std::setw(25) << "Receiver" << std::setw(25) << "Sender" - << std::setw(10) << "nitem" << std::setw(20) << "key" - << std::setw(10) << "value" << std::endl; - - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - d_sout << std::setw(25) << str.str() - << std::setw(25) << pmt::pmt_tuple_ref(*itr, 1) - << std::setw(10) << pmt::pmt_tuple_ref(*itr, 0) - << std::setw(20) << pmt::pmt_tuple_ref(*itr, 2) - << std::setw(10) << pmt::pmt_tuple_ref(*itr, 3) - << std::endl; - } - - // Work does nothing to the data stream; just copy all inputs to outputs - int ninputs = input_items.size(); - for (int i = 0; i < ninputs; i++){ - memcpy(out[i], in[i], noutput_items * d_itemsize); - } - - // Storing the current noutput_items as the value to the "noutput_items" key - pmt::pmt_t cur_N = pmt::pmt_from_uint64(d_tag_counter++); - pmt::pmt_t srcid = pmt::pmt_string_to_symbol(str.str()); - pmt::pmt_t key = pmt::pmt_string_to_symbol("noutput_items"); - add_item_tag(0, abs_N, key, cur_N, srcid); - - return noutput_items; -} diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.h b/gnuradio-core/src/lib/runtime/gr_random_annotator.h deleted file mode 100644 index 5fca53830..000000000 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_RANDOM_ANNOTATOR_H -#define INCLUDED_GR_RANDOM_ANNOTATOR_H - -#include - -class gr_random_annotator; -typedef boost::shared_ptr gr_random_annotator_sptr; - -// public constructor -gr_random_annotator_sptr -gr_make_random_annotator (size_t sizeof_stream_item); - -class gr_random_annotator : public gr_sync_block -{ - public: - ~gr_random_annotator (); - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - -protected: - gr_random_annotator (size_t sizeof_stream_item); - - private: - size_t d_itemsize; - std::stringstream d_sout; - uint64_t d_tag_counter; - - friend gr_random_annotator_sptr - gr_make_random_annotator (size_t sizeof_stream_item); -}; - -#endif diff --git a/gnuradio-core/src/lib/runtime/gr_random_annotator.i b/gnuradio-core/src/lib/runtime/gr_random_annotator.i deleted file mode 100644 index f8765a294..000000000 --- a/gnuradio-core/src/lib/runtime/gr_random_annotator.i +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -GR_SWIG_BLOCK_MAGIC(gr,random_annotator); - -gr_random_annotator_sptr gr_make_random_annotator (size_t sizeof_stream_item); - -class gr_random_annotator : public gr_sync_block -{ -private: - gr_random_annotator (size_t sizeof_stream_item); -}; - diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 2fedb28fd..a845f70dc 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include @@ -73,17 +73,24 @@ qa_block_tags::t1 () gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); - gr_block_sptr ann0 (gr_make_random_annotator(sizeof(int))); - gr_block_sptr ann1 (gr_make_random_annotator(sizeof(int))); - gr_block_sptr ann2 (gr_make_random_annotator(sizeof(int))); - gr_block_sptr snk (gr_make_null_sink(sizeof(int))); + gr_block_sptr ann0 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr ann4 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); - tb->connect(ann1, 0, ann2, 0); - tb->connect(ann2, 0, snk, 0); - tb->run(); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, ann3, 0); + tb->connect(ann2, 0, ann4, 0); + tb->connect(ann1, 0, snk0, 0); + tb->connect(ann2, 0, snk1, 0); + tb->run(); } diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 51b32de17..20cf68a03 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -54,7 +53,6 @@ %include %include %include -%include %include %include %include -- cgit From 0952d5a28a898309f3b7a11a27fff27b52731b53 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 15:55:58 -0500 Subject: Adding an annotator block that moves tags using 1-to-1 policy. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index a845f70dc..0c96052e3 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -89,8 +89,9 @@ qa_block_tags::t1 () tb->connect(ann1, 0, ann3, 0); tb->connect(ann2, 0, ann4, 0); - tb->connect(ann1, 0, snk0, 0); - tb->connect(ann2, 0, snk1, 0); + tb->connect(ann3, 0, snk0, 0); + tb->connect(ann4, 0, snk1, 0); + tb->run(); } -- cgit From 54b396764a9fad91cbfd10f618e4faed1c8bafa2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 19:41:46 -0500 Subject: Switches to using the new annotator block with a known graph structure to run tests against the all-to-all tag propagation policy to make sure the tags are flowing downstream properly. Adding stub for testing the 1-to-1 tag propagation policy. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 83 +++++++++++++++++++++++++- gnuradio-core/src/lib/runtime/qa_block_tags.h | 2 + 2 files changed, 84 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 0c96052e3..4dc096f27 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -30,11 +30,13 @@ #include #include #include +#include #include // ---------------------------------------------------------------- +using namespace pmt; void qa_block_tags::t0 () @@ -73,7 +75,85 @@ qa_block_tags::t1 () gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); - gr_block_sptr ann0 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann0 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann4 (gr_make_annotator_1toall(sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, ann3, 0); + tb->connect(ann2, 0, ann4, 0); + + tb->connect(ann3, 0, snk0, 0); + tb->connect(ann4, 0, snk1, 0); + + tb->run(); + + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + pmt_t expected_tags3[8]; + expected_tags3[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + + pmt_t expected_tags4[8]; + expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(40000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + + // For annotator 3, we know it gets tags from ann0 and ann1, test this + for(size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; + //pmt_equal(tags3[i], expected_tags3[i]) + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + } + + // For annotator 4, we know it gets tags from ann0 and ann2, test this + for(size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } +} + + +void +qa_block_tags::t2 () +{ + printf("\nqa_block_tags::t2\n"); + + int N = 40000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_block_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); gr_block_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); gr_block_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); gr_block_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); @@ -83,6 +163,7 @@ qa_block_tags::t1 () tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); + tb->connect(head, 0, ann0, 1); tb->connect(ann0, 0, ann1, 0); tb->connect(ann0, 1, ann2, 0); diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index b7388885f..69bc0480c 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -32,11 +32,13 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST_SUITE (qa_block_tags); CPPUNIT_TEST (t0); CPPUNIT_TEST (t1); + //CPPUNIT_TEST (t2); CPPUNIT_TEST_SUITE_END (); private: void t0 (); void t1 (); + void t2 (); }; -- cgit From 4a63bc91ddceaa8ce9d14a3f714bd0cdc3e85128 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 11 Nov 2010 20:04:44 -0500 Subject: Reworked 1-to-1 annotator block to better testing purposes. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 58 +++++++++++++++++++++++--- gnuradio-core/src/lib/runtime/qa_block_tags.h | 2 +- 2 files changed, 54 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 4dc096f27..ee16ec108 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -137,6 +137,7 @@ qa_block_tags::t1 () } // For annotator 4, we know it gets tags from ann0 and ann2, test this + std::cout << std::endl; for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); @@ -153,11 +154,11 @@ qa_block_tags::t2 () gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); - gr_block_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); - gr_block_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); - gr_block_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); - gr_block_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); - gr_block_sptr ann4 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); @@ -174,5 +175,52 @@ qa_block_tags::t2 () tb->connect(ann4, 0, snk1, 0); tb->run(); + + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + pmt_t expected_tags3[8]; + expected_tags3[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + + pmt_t expected_tags4[8]; + expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(40000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + + // For annotator 3, we know it gets tags from ann0 and ann1, test this + for(size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; + //pmt_equal(tags3[i], expected_tags3[i]) + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + } + + // For annotator 4, we know it gets tags from ann0 and ann2, test this + std::cout << std::endl; + for(size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } } diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index 69bc0480c..44bef9fac 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -32,7 +32,7 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST_SUITE (qa_block_tags); CPPUNIT_TEST (t0); CPPUNIT_TEST (t1); - //CPPUNIT_TEST (t2); + CPPUNIT_TEST (t2); CPPUNIT_TEST_SUITE_END (); private: -- cgit From 3fb01df05227913c2cc8cde6cb651dc1c9a81ff9 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 13 Nov 2010 14:28:37 -0500 Subject: Block executor propagation method returns an error indicator to stop the flowgraph in an error instead of throwing. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 840cf8e5c..86d10f81b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -87,7 +87,7 @@ min_available_space (gr_block_detail *d, int output_multiple) return min_space; } -static void +static int propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, const std::vector &start_nitems_read) { @@ -95,17 +95,18 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute if(d->sink_p()) { - return; + return 0; } switch(policy) { case(gr_block::TPP_DONT): - return; + return 0; break; case(gr_block::TPP_ALL_TO_ALL): // every tag on every input propogates to everyone downstream for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], d->nitems_read(i)); + std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], + d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { for(int o = 0; o < d->noutputs(); o++) @@ -119,20 +120,24 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // type of tag-propagation system is selected in gr_block_detail if(d->ninputs() == d->noutputs()) { for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], d->nitems_read(i)); + std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], + d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { d->output(i)->add_item_tag(*t); } } } - else - throw std::invalid_argument ("propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs"); + else { + std::cerr << "Error: propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs" << std::endl; + return -1; + } break; default: - return; + return 0; } + return 0; } gr_block_executor::gr_block_executor (gr_block_sptr block) @@ -353,7 +358,8 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read); + if(propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read) == -1) + goto were_done; if (n == gr_block::WORK_DONE) goto were_done; -- cgit From 77d778896b72379676d2b00e591f9bbb5f6fcc44 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 13 Nov 2010 14:29:11 -0500 Subject: More test methods. Better testing of the all-to-all policy and more tests for the 1-to-1. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 139 +++++++++++++++++++++++-- gnuradio-core/src/lib/runtime/qa_block_tags.h | 4 + 2 files changed, 134 insertions(+), 9 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index ee16ec108..2560b7860 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -75,11 +75,11 @@ qa_block_tags::t1 () gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); - gr_annotator_1toall_sptr ann0 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann3 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann4 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); @@ -144,19 +144,112 @@ qa_block_tags::t1 () } } - void qa_block_tags::t2 () { printf("\nqa_block_tags::t2\n"); + int N = 40000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk2 (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann1, 1); + tb->connect(ann1, 0, ann2, 0); + tb->connect(ann1, 1, ann3, 0); + tb->connect(ann1, 2, ann4, 0); + + tb->connect(ann2, 0, snk0, 0); + tb->connect(ann3, 0, snk1, 0); + tb->connect(ann4, 0, snk2, 0); + + tb->run(); + + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + + pmt_t expected_tags2[12]; + expected_tags2[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); + expected_tags2[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags2[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags2[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags2[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags2[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags2[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(6)); + expected_tags2[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags2[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags2[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(9)); + expected_tags2[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags2[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + pmt_t expected_tags4[12]; + expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); + expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(5)); + expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(8)); + expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags4[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(11)); + expected_tags4[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags4[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)8); + + // For annotator[2-4], we know it gets tags from ann0 and ann1 + // but the tags from the different outputs of ann1 are different for each. + // Just testing ann2 and ann4; if they are correct it would be + // inconceivable for ann3 to have it wrong. + for(size_t i = 0; i < tags2.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; + //pmt_equal(tags2[i], expected_tags2[i]) + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); + } + + std::cout << std::endl; + for(size_t i = 0; i < tags4.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; + //pmt_equal(tags4[i], expected_tags4[i]) + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); + } +} + + +void +qa_block_tags::t3 () +{ + printf("\nqa_block_tags::t3\n"); + int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_1toall_sptr ann1 (gr_make_annotator_1toall(sizeof(int))); - gr_annotator_1toall_sptr ann2 (gr_make_annotator_1toall(sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(sizeof(int))); gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); @@ -224,3 +317,31 @@ qa_block_tags::t2 () } } + +void +qa_block_tags::t4 () +{ + printf("\nqa_block_tags::t4\n"); + + int N = 40000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann1 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann2 (gr_make_annotator_1to1(sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); + + // using 1-to-1 tag propagation without having equal number of + // ins and outs. Make sure this works; will just exit run early. + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann0, 1, ann2, 0); + tb->connect(ann1, 0, snk0, 0); + tb->connect(ann2, 0, snk1, 0); + + tb->run(); +} + diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index 44bef9fac..2bf134d96 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -33,12 +33,16 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST (t0); CPPUNIT_TEST (t1); CPPUNIT_TEST (t2); + CPPUNIT_TEST (t3); + CPPUNIT_TEST (t4); CPPUNIT_TEST_SUITE_END (); private: void t0 (); void t1 (); void t2 (); + void t3 (); + void t4 (); }; -- cgit From 222c6c5be69575c00d6396b95d523e0dfa19f2c3 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 14 Nov 2010 00:04:11 -0500 Subject: Fixing some bugs. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 18 +-- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 122 +++++++++++---------- 2 files changed, 75 insertions(+), 65 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 86d10f81b..dd0993ec7 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -87,7 +87,7 @@ min_available_space (gr_block_detail *d, int output_multiple) return min_space; } -static int +static bool propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, const std::vector &start_nitems_read) { @@ -95,12 +95,12 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // if a sink, we don't need to move downstream; // and do not bother if block uses TAGS_NONE attribute if(d->sink_p()) { - return 0; + return true; } switch(policy) { case(gr_block::TPP_DONT): - return 0; + return true; break; case(gr_block::TPP_ALL_TO_ALL): // every tag on every input propogates to everyone downstream @@ -129,15 +129,15 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, } } else { - std::cerr << "Error: propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs" << std::endl; - return -1; + std::cerr << "Error: gr_block_executor: propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs" << std::endl; + return false; } break; default: - return 0; + return true; } - return 0; + return true; } gr_block_executor::gr_block_executor (gr_block_sptr block) @@ -350,7 +350,7 @@ gr_block_executor::run_one_iteration() // determine where to start looking for new tags as 1 past nitems read for (int i = 0; i < d->ninputs(); i++) - d_start_nitems_read[i] = d->nitems_read(i)+1; + d_start_nitems_read[i] = d->nitems_read(i); // Do the actual work of the block int n = m->general_work (noutput_items, d_ninput_items, @@ -358,7 +358,7 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - if(propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read) == -1) + if(!propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read)) goto were_done; if (n == gr_block::WORK_DONE) diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 2560b7860..8612a1067 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -103,24 +103,24 @@ qa_block_tags::t1 () str2 << ann2->name() << ann2->unique_id(); pmt_t expected_tags3[8]; - expected_tags3[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); - expected_tags3[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); - expected_tags3[2] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(1)); - expected_tags3[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags3[4] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(2)); - expected_tags3[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); - expected_tags3[6] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(3)); - expected_tags3[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags3[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); pmt_t expected_tags4[8]; - expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(0)); - expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags4[2] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(1)); - expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags4[4] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(2)); - expected_tags4[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); - expected_tags4[6] = mp(pmt_from_uint64(40000), mp(str2.str()), mp("seq"), mp(3)); - expected_tags4[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + expected_tags4[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); std::vector tags0 = ann0->data(); std::vector tags3 = ann3->data(); @@ -130,6 +130,7 @@ qa_block_tags::t1 () CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); // For annotator 3, we know it gets tags from ann0 and ann1, test this + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; //pmt_equal(tags3[i], expected_tags3[i]) @@ -138,6 +139,7 @@ qa_block_tags::t1 () // For annotator 4, we know it gets tags from ann0 and ann2, test this std::cout << std::endl; + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); @@ -183,42 +185,48 @@ qa_block_tags::t2 () str1 << ann1->name() << ann1->unique_id(); pmt_t expected_tags2[12]; - expected_tags2[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); - expected_tags2[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); - expected_tags2[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags2[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(3)); - expected_tags2[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags2[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags2[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(6)); - expected_tags2[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); - expected_tags2[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); - expected_tags2[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(9)); - expected_tags2[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); - expected_tags2[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + expected_tags2[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags2[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags2[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags2[3] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags2[4] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags2[5] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags2[6] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(6)); + expected_tags2[7] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags2[8] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags2[9] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(9)); + expected_tags2[10] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags2[11] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); pmt_t expected_tags4[12]; - expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(2)); - expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); - expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(5)); - expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(8)); - expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); - expected_tags4[8] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); - expected_tags4[9] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(11)); - expected_tags4[10] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); - expected_tags4[11] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + expected_tags4[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(2)); + expected_tags4[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags4[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(5)); + expected_tags4[4] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[6] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(8)); + expected_tags4[7] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags4[8] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[9] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(11)); + expected_tags4[10] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags4[11] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); std::vector tags0 = ann0->data(); std::vector tags1 = ann1->data(); std::vector tags2 = ann2->data(); + std::vector tags3 = ann4->data(); std::vector tags4 = ann4->data(); // The first annotator does not receive any tags from the null sink upstream CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)8); + // Make sure the rest all have 12 tags + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)12); + // For annotator[2-4], we know it gets tags from ann0 and ann1 // but the tags from the different outputs of ann1 are different for each. // Just testing ann2 and ann4; if they are correct it would be @@ -276,24 +284,24 @@ qa_block_tags::t3 () str2 << ann2->name() << ann2->unique_id(); pmt_t expected_tags3[8]; - expected_tags3[0] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(0)); - expected_tags3[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(0)); - expected_tags3[2] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(1)); - expected_tags3[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags3[4] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(2)); - expected_tags3[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(4)); - expected_tags3[6] = mp(pmt_from_uint64(40000), mp(str1.str()), mp("seq"), mp(3)); - expected_tags3[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(6)); + expected_tags3[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(10000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[4] = mp(pmt_from_uint64(20000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(4)); + expected_tags3[6] = mp(pmt_from_uint64(30000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); pmt_t expected_tags4[8]; - expected_tags4[0] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(0)); - expected_tags4[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags4[2] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(1)); - expected_tags4[3] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags4[4] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(2)); - expected_tags4[5] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(5)); - expected_tags4[6] = mp(pmt_from_uint64(40000), mp(str2.str()), mp("seq"), mp(3)); - expected_tags4[7] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(7)); + expected_tags4[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); + expected_tags4[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(1)); + expected_tags4[2] = mp(pmt_from_uint64(10000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags4[3] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags4[4] = mp(pmt_from_uint64(20000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); + expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); std::vector tags0 = ann0->data(); std::vector tags3 = ann3->data(); @@ -303,6 +311,7 @@ qa_block_tags::t3 () CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); // For annotator 3, we know it gets tags from ann0 and ann1, test this + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; //pmt_equal(tags3[i], expected_tags3[i]) @@ -311,6 +320,7 @@ qa_block_tags::t3 () // For annotator 4, we know it gets tags from ann0 and ann2, test this std::cout << std::endl; + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); -- cgit From 11b2b7c40048bee5201bd10dd753a9471cd6345d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 14 Nov 2010 01:20:44 -0500 Subject: Adds argument to annotator test blocks to determine when they add a new tag. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 36 +++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 8612a1067..9c4dac698 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -75,11 +75,11 @@ qa_block_tags::t1 () gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); - gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); @@ -155,11 +155,11 @@ qa_block_tags::t2 () gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); - gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(sizeof(int))); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk2 (gr_make_null_sink(sizeof(int))); @@ -255,11 +255,11 @@ qa_block_tags::t3 () gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); - gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(sizeof(int))); - gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_1to1_sptr ann3 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); @@ -337,9 +337,9 @@ qa_block_tags::t4 () gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); - gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_1to1_sptr ann1 (gr_make_annotator_1to1(sizeof(int))); - gr_annotator_1to1_sptr ann2 (gr_make_annotator_1to1(sizeof(int))); + gr_annotator_1to1_sptr ann0 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_1to1_sptr ann1 (gr_make_annotator_1to1(10000, sizeof(int))); + gr_annotator_1to1_sptr ann2 (gr_make_annotator_1to1(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); -- cgit From a6b5781e36ff75adb1e4d39d755d4ab8f5efd9dd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 14 Nov 2010 13:43:05 -0500 Subject: First hack at pruning tags to keep from growing. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 28 +++++++++++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_buffer.h | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 1d67470ec..f6a0a98fb 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -156,8 +156,15 @@ gr_buffer::space_available () // Find out the maximum amount of data available to our readers int most_data = d_readers[0]->items_available (); - for (unsigned int i = 1; i < d_readers.size (); i++) + uint64_t min_items_read = d_readers[0]->nitems_read(); + for (size_t i = 1; i < d_readers.size (); i++) { most_data = std::max (most_data, d_readers[i]->items_available ()); + min_items_read = std::min(min_items_read, d_readers[i]->nitems_read()); + } + + for (size_t i = 0; i < d_readers.size (); i++) { + d_readers[i]->prune_tags(min_items_read); + } // The -1 ensures that the case d_write_index == d_read_index is // unambiguous. It indicates that there is no data for the reader @@ -287,6 +294,25 @@ gr_buffer_reader::get_tags_in_range(uint64_t abs_start, return found_items; } +void +gr_buffer_reader::prune_tags(uint64_t max_time) +{ + int n = 0; + uint64_t item_time; + std::deque::iterator itr = d_buffer->get_tags_begin(); + + while(itr != d_buffer->get_tags_end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + if(item_time < max_time) { + d_buffer->tags_pop_front(); + n++; + } + else + break; + itr++; + } +} + long gr_buffer_reader_ncurrently_allocated () { diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index d6d5564e8..47ba4cd96 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -101,6 +101,7 @@ class gr_buffer { std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } std::deque::iterator get_tags_end() { return d_item_tags.end(); } + void tags_pop_front() { d_item_tags.pop_front(); } // ------------------------------------------------------------------------- @@ -260,6 +261,8 @@ class gr_buffer_reader { std::vector get_tags_in_range(uint64_t abs_start, uint64_t abs_end); + void prune_tags(uint64_t max_time); + // ------------------------------------------------------------------------- private: -- cgit From e8d0dbbdfce26f6963dfe0a727faf9c9cc5baf75 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sun, 14 Nov 2010 11:57:19 -0800 Subject: Remove code that's no longer needed. --- gnuradio-core/src/lib/runtime/gr_basic_block.i | 7 +------ gnuradio-core/src/lib/runtime/gr_block.i | 13 +------------ 2 files changed, 2 insertions(+), 18 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 9b360e5ab..03d4725d5 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -52,8 +52,3 @@ long gr_basic_block_ncurrently_allocated(); gr_basic_block_sptr.__repr__ = lambda self: "" % (self.name(), self.unique_id ()) %} #endif - -#ifdef SWIGGUILE -#warning "gr_basic_block.i: gr_block_sptr needs to be implemented!" -#endif - diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index d13c268ca..f4ee43477 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -53,14 +53,3 @@ class gr_block : public gr_basic_block { gr_block_detail_sptr detail () const { return d_detail; } void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } }; - -#ifdef SWIGPYTHON -%pythoncode %{ -gr_block_sptr.__repr__ = lambda self: "" % (self.name(), self.unique_id ()) -gr_block_sptr.block = lambda self: self -%} -#endif - -#ifdef SWIGGUILE -#warning "gr_block.i: gr_block_sptr needs to be implemented!" -#endif -- cgit From 8d84a2fc9a804b2248fe43c3d8b230ef99aebaa2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 15:02:55 -0800 Subject: Adding a way for propagate_tags to handle different rates. The tags are rewritten between blocks to adjust their count based on teh block's relative_rate.w --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 14 ++- gnuradio-core/src/lib/runtime/gr_buffer.cc | 4 +- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 99 ++++++++++++++++++++++ gnuradio-core/src/lib/runtime/qa_block_tags.h | 2 + 4 files changed, 114 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index dd0993ec7..9882c2e5d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -89,7 +89,7 @@ min_available_space (gr_block_detail *d, int output_multiple) static bool propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, - const std::vector &start_nitems_read) + const std::vector &start_nitems_read, double rrate) { // Move tags downstream // if a sink, we don't need to move downstream; @@ -109,8 +109,15 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, d->nitems_read(i)); std::vector::iterator t; for(t = tuple.begin(); t != tuple.end(); t++ ) { + uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); + pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), + pmt::pmt_tuple_ref(*t, 1), + pmt::pmt_tuple_ref(*t, 2), + pmt::pmt_tuple_ref(*t, 3)); + for(int o = 0; o < d->noutputs(); o++) - d->output(o)->add_item_tag(*t); + d->output(o)->add_item_tag(newtup); + //d->output(o)->add_item_tag(*t); } } break; @@ -358,7 +365,8 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); - if(!propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read)) + if(!propagate_tags(m->tag_propagation_policy(), d, + d_start_nitems_read, m->relative_rate())) goto were_done; if (n == gr_block::WORK_DONE) diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index f6a0a98fb..84a65f921 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -307,8 +307,8 @@ gr_buffer_reader::prune_tags(uint64_t max_time) d_buffer->tags_pop_front(); n++; } - else - break; + //else + // break; itr++; } } diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 9c4dac698..e337e3768 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -355,3 +355,102 @@ qa_block_tags::t4 () tb->run(); } + +void +qa_block_tags::t5 () +{ + printf("\nqa_block_tags::t5\n"); + + int N = 40000; + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(int))); + gr_block_sptr head (gr_make_head(sizeof(int), N)); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(1000, sizeof(int))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(1000, sizeof(int))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(1000, sizeof(int))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); + + tb->connect(src, 0, head, 0); + tb->connect(head, 0, ann0, 0); + tb->connect(ann0, 0, ann1, 0); + tb->connect(ann1, 0, ann2, 0); + tb->connect(ann2, 0, snk0, 0); + + tb->run(); + + // Kludge together the tags that we know should result from the above graph + std::stringstream str0, str1, str2; + str0 << ann0->name() << ann0->unique_id(); + str1 << ann1->name() << ann1->unique_id(); + str2 << ann2->name() << ann2->unique_id(); + + pmt_t expected_tags1[5]; + expected_tags1[0] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags1[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags1[2] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags1[3] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags1[4] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(4)); + + pmt_t expected_tags2[10]; + expected_tags2[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags2[1] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags2[2] = mp(pmt_from_uint64(1000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags2[3] = mp(pmt_from_uint64(1000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags2[4] = mp(pmt_from_uint64(2000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags2[5] = mp(pmt_from_uint64(2000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags2[6] = mp(pmt_from_uint64(3000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags2[7] = mp(pmt_from_uint64(3000), mp(str0.str()), mp("seq"), mp(3)); + expected_tags2[8] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(4)); + expected_tags2[9] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(4)); + + pmt_t expected_tags3[12]; + expected_tags3[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); + expected_tags3[1] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); + expected_tags3[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); + expected_tags3[3] = mp(pmt_from_uint64(1000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags3[4] = mp(pmt_from_uint64(2000), mp(str1.str()), mp("seq"), mp(1)); + expected_tags3[5] = mp(pmt_from_uint64(2000), mp(str0.str()), mp("seq"), mp(1)); + expected_tags3[6] = mp(pmt_from_uint64(2000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags3[7] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(2)); + expected_tags3[8] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(2)); + expected_tags3[9] = mp(pmt_from_uint64(3000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags3[10] = mp(pmt_from_uint64(6000), mp(str1.str()), mp("seq"), mp(3)); + expected_tags3[11] = mp(pmt_from_uint64(6000), mp(str0.str()), mp("seq"), mp(3)); + + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); + std::vector tags3 = ann3->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + + // annotator 1 gets tags from annotator 0 + std::cout << "tags1.size(): " << tags1.size() << std::endl; + //CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); + for(size_t i = 0; i < tags1.size(); i++) { + std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i] << std::endl; + //pmt_equal(tags1[i], expected_tags1[i]) + //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags1[i]), pmt_write_string(expected_tags1[i])); + } + + // annotator 2 gets tags from annotators 0 and 1 + std::cout << std::endl; + std::cout << "tags2.size(): " << tags2.size() << std::endl; + //CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + for(size_t i = 0; i < tags2.size(); i++) { + std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; + //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); + } + + // annotator 3 gets tags from annotators 0, 1, and 2 + std::cout << std::endl; + std::cout << "tags3.size(): " << tags3.size() << std::endl; + //CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + for(size_t i = 0; i < tags3.size(); i++) { + std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; + //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + } +} + diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index 2bf134d96..661d607b2 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -35,6 +35,7 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST (t2); CPPUNIT_TEST (t3); CPPUNIT_TEST (t4); + //CPPUNIT_TEST (t5); CPPUNIT_TEST_SUITE_END (); private: @@ -43,6 +44,7 @@ class qa_block_tags : public CppUnit::TestCase { void t2 (); void t3 (); void t4 (); + void t5 (); }; -- cgit From 9d6c7400ba39a9d5e3ddab9da294b8b6303d9509 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 15:36:24 -0800 Subject: Adding QA test for testing rate changes. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 50 +++++++++++++++----------- gnuradio-core/src/lib/runtime/qa_block_tags.h | 2 +- 2 files changed, 31 insertions(+), 21 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index e337e3768..2092e48ed 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -31,6 +31,9 @@ #include #include #include +#include +#include +#include #include @@ -363,19 +366,27 @@ qa_block_tags::t5 () int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); - gr_block_sptr src (gr_make_null_source(sizeof(int))); - gr_block_sptr head (gr_make_head(sizeof(int), N)); - gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(int))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(1000, sizeof(int))); - gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(1000, sizeof(int))); - gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(1000, sizeof(int))); - gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); - + gr_block_sptr src (gr_make_null_source(sizeof(float))); + gr_block_sptr head (gr_make_head(sizeof(float), N)); + gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(float))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(float))); + gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(1000, sizeof(float))); + gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(2000, sizeof(float))); + gr_block_sptr snk0 (gr_make_null_sink(sizeof(float))); + + // Rate change blocks + std::vector taps = gr_firdes::low_pass_2(1, 1, 0.4, 0.1, 60); + gr_fir_filter_fff_sptr fir_dec10 (gr_make_fir_filter_fff(10, taps)); + gr_interp_fir_filter_fff_sptr fir_int2 (gr_make_interp_fir_filter_fff(2, taps)); + tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); tb->connect(ann0, 0, ann1, 0); - tb->connect(ann1, 0, ann2, 0); - tb->connect(ann2, 0, snk0, 0); + tb->connect(ann1, 0, fir_dec10, 0); + tb->connect(fir_dec10, 0, ann2, 0); + tb->connect(ann2, 0, fir_int2, 0); + tb->connect(fir_int2, 0, ann3, 0); + tb->connect(ann3, 0, snk0, 0); tb->run(); @@ -390,7 +401,6 @@ qa_block_tags::t5 () expected_tags1[1] = mp(pmt_from_uint64(10000), mp(str0.str()), mp("seq"), mp(1)); expected_tags1[2] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(2)); expected_tags1[3] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(3)); - expected_tags1[4] = mp(pmt_from_uint64(40000), mp(str0.str()), mp("seq"), mp(4)); pmt_t expected_tags2[10]; expected_tags2[0] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); @@ -408,13 +418,13 @@ qa_block_tags::t5 () expected_tags3[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); expected_tags3[1] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); expected_tags3[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); - expected_tags3[3] = mp(pmt_from_uint64(1000), mp(str2.str()), mp("seq"), mp(1)); + expected_tags3[3] = mp(pmt_from_uint64(2000), mp(str2.str()), mp("seq"), mp(1)); expected_tags3[4] = mp(pmt_from_uint64(2000), mp(str1.str()), mp("seq"), mp(1)); expected_tags3[5] = mp(pmt_from_uint64(2000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags3[6] = mp(pmt_from_uint64(2000), mp(str2.str()), mp("seq"), mp(2)); + expected_tags3[6] = mp(pmt_from_uint64(4000), mp(str2.str()), mp("seq"), mp(2)); expected_tags3[7] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(2)); expected_tags3[8] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags3[9] = mp(pmt_from_uint64(3000), mp(str2.str()), mp("seq"), mp(3)); + expected_tags3[9] = mp(pmt_from_uint64(6000), mp(str2.str()), mp("seq"), mp(3)); expected_tags3[10] = mp(pmt_from_uint64(6000), mp(str1.str()), mp("seq"), mp(3)); expected_tags3[11] = mp(pmt_from_uint64(6000), mp(str0.str()), mp("seq"), mp(3)); @@ -428,29 +438,29 @@ qa_block_tags::t5 () // annotator 1 gets tags from annotator 0 std::cout << "tags1.size(): " << tags1.size() << std::endl; - //CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); for(size_t i = 0; i < tags1.size(); i++) { std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i] << std::endl; //pmt_equal(tags1[i], expected_tags1[i]) - //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags1[i]), pmt_write_string(expected_tags1[i])); + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags1[i]), pmt_write_string(expected_tags1[i])); } // annotator 2 gets tags from annotators 0 and 1 std::cout << std::endl; std::cout << "tags2.size(): " << tags2.size() << std::endl; - //CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); for(size_t i = 0; i < tags2.size(); i++) { std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; - //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); } // annotator 3 gets tags from annotators 0, 1, and 2 std::cout << std::endl; std::cout << "tags3.size(): " << tags3.size() << std::endl; - //CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - //CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); + CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); } } diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index 661d607b2..b0d211390 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -35,7 +35,7 @@ class qa_block_tags : public CppUnit::TestCase { CPPUNIT_TEST (t2); CPPUNIT_TEST (t3); CPPUNIT_TEST (t4); - //CPPUNIT_TEST (t5); + CPPUNIT_TEST (t5); CPPUNIT_TEST_SUITE_END (); private: -- cgit From 38d1a6be0d4f80a4a5334ddb8bac0aef08d5c794 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 15:56:50 -0800 Subject: Adding information and convinience functions for accessing tag information. --- gnuradio-core/src/lib/runtime/gr_tag_info.cc | 37 ++++++++++++++++ gnuradio-core/src/lib/runtime/gr_tag_info.h | 65 ++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/gr_tag_info.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_tag_info.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.cc b/gnuradio-core/src/lib/runtime/gr_tag_info.cc new file mode 100644 index 000000000..211f330e9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.cc @@ -0,0 +1,37 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +namespace gr_tags { + + const pmt::pmt_t s_key_time = pmt::pmt_string_to_symbol("time"); + const pmt::pmt_t s_key_sample_rate = pmt::pmt_string_to_symbol("sample_rate"); + const pmt::pmt_t s_key_frequency = pmt::pmt_string_to_symbol("frequency"); + const pmt::pmt_t s_key_rssi = pmt::pmt_string_to_symbol("rssi"); + const pmt::pmt_t s_key_rx_gain = pmt::pmt_string_to_symbol("gain"); +} diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.h b/gnuradio-core/src/lib/runtime/gr_tag_info.h new file mode 100644 index 000000000..af51cf6a9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TAG_INFO_H +#define INCLUDED_GR_TAG_INFO_H + +#include + +namespace gr_tags { + + enum { + TAG_NITEM_REF = 0, + TAG_SRCID_REF, + TAG_KEY_REF, + TAG_VALUE_REF + }; + + extern const pmt::pmt_t s_key_time; + extern const pmt::pmt_t s_key_sample_rate; + extern const pmt::pmt_t s_key_frequency; + extern const pmt::pmt_t s_key_rssi; + extern const pmt::pmt_t s_key_gain; + + static inline uint64_t + get_nitems(const pmt::pmt_t &tag) { + return pmt::pmt_to_uint64(pmt::pmt_tuple_ref(tag, TAG_NITEM_REF)); + } + + static inline pmt::pmt_t + get_srcid(const pmt::pmt_t &tag) { + return pmt::pmt_tuple_ref(tag, TAG_SRCID_REF); + } + + static inline pmt::pmt_t + get_key(const pmt::pmt_t &tag) { + return pmt::pmt_tuple_ref(tag, TAG_KEY_REF); + } + + static inline pmt::pmt_t + get_value(const pmt::pmt_t &tag) { + return pmt::pmt_tuple_ref(tag, TAG_VALUE_REF); + } + +}; /* namespace tags */ + +#endif /* GR_TAG_INFO */ -- cgit From 97b1f1aa7d646fbc1250158ec94fe49d0979809c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 15:58:04 -0800 Subject: Makefile changes to work in tag info stuff. --- gnuradio-core/src/lib/runtime/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index a3aa36a39..dd9a8ea64 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -68,7 +68,8 @@ libruntime_la_SOURCES = \ gr_vmcircbuf_mmap_tmpfile.cc \ gr_vmcircbuf_createfilemapping.cc \ gr_vmcircbuf_sysv_shm.cc \ - gr_select_handler.cc + gr_select_handler.cc \ + gr_tag_info.cc libruntime_qa_la_SOURCES = \ qa_gr_block.cc \ @@ -122,7 +123,8 @@ grinclude_HEADERS = \ gr_tmp_path.h \ gr_types.h \ gr_unittests.h \ - gr_vmcircbuf.h + gr_vmcircbuf.h \ + gr_tag_info.h noinst_HEADERS = \ gr_vmcircbuf_mmap_shm_open.h \ -- cgit From 6d4393613a78417b91e67af33820748ad3483e61 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 15:58:49 -0800 Subject: Changing get_tags API to take in a vector reference instead of returning a vector. --- gnuradio-core/src/lib/runtime/gr_block.cc | 14 ++++++----- gnuradio-core/src/lib/runtime/gr_block.h | 18 ++++++++------ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 22 +++++++++-------- gnuradio-core/src/lib/runtime/gr_block_detail.h | 19 +++++++++------ gnuradio-core/src/lib/runtime/gr_block_executor.cc | 28 ++++++++++++++-------- gnuradio-core/src/lib/runtime/gr_block_executor.h | 2 ++ gnuradio-core/src/lib/runtime/gr_buffer.cc | 11 ++++----- gnuradio-core/src/lib/runtime/gr_buffer.h | 6 +++-- 8 files changed, 72 insertions(+), 48 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 778344769..52be37e3b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -152,19 +152,21 @@ gr_block::add_item_tag(unsigned int which_output, d_detail->add_item_tag(which_output, offset, key, value, srcid); } -std::vector -gr_block::get_tags_in_range(unsigned int which_output, +void +gr_block::get_tags_in_range(std::vector &v, + unsigned int which_output, uint64_t start, uint64_t end) { - return d_detail->get_tags_in_range(which_output, start, end); + d_detail->get_tags_in_range(v, which_output, start, end); } -std::vector -gr_block::get_tags_in_range(unsigned int which_output, +void +gr_block::get_tags_in_range(std::vector &v, + unsigned int which_output, uint64_t start, uint64_t end, const pmt::pmt_t &key) { - return d_detail->get_tags_in_range(which_output, start, end, key); + d_detail->get_tags_in_range(v, which_output, start, end, key); } gr_block::TAG_PROPAGATION_POLICY diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index a717946d2..7caf3c34a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -268,13 +268,15 @@ class gr_block : public gr_basic_block { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::vector get_tags_in_range(unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end); + void get_tags_in_range(std::vector &v, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! * \brief Given a [start,end), returns a vector of all tags in the range @@ -285,15 +287,17 @@ class gr_block : public gr_basic_block { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest * \param key a PMT symbol key to filter only tags of this key */ - std::vector get_tags_in_range(unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end, - const pmt::pmt_t &key); + void get_tags_in_range(std::vector &v, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friends diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 4f3ffc8dc..a360240c0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -169,25 +169,29 @@ gr_block_detail::add_item_tag(unsigned int which_output, } } -std::vector -gr_block_detail::get_tags_in_range(unsigned int which_input, +void +gr_block_detail::get_tags_in_range(std::vector &v, + unsigned int which_input, uint64_t abs_start, uint64_t abs_end) { // get from gr_buffer_reader's deque of tags - return d_input[which_input]->get_tags_in_range(abs_start, abs_end); + d_input[which_input]->get_tags_in_range(v, abs_start, abs_end); } -std::vector -gr_block_detail::get_tags_in_range(unsigned int which_input, +void +gr_block_detail::get_tags_in_range(std::vector &v, + unsigned int which_input, uint64_t abs_start, uint64_t abs_end, const pmt_t &key) { - std::vector found_items, found_items_by_key; + std::vector found_items; + + v.resize(0); // get from gr_buffer_reader's deque of tags - found_items = d_input[which_input]->get_tags_in_range(abs_start, abs_end); + d_input[which_input]->get_tags_in_range(found_items, abs_start, abs_end); // Filter further by key name pmt_t itemkey; @@ -195,9 +199,7 @@ gr_block_detail::get_tags_in_range(unsigned int which_input, for(itr = found_items.begin(); itr != found_items.end(); itr++) { itemkey = pmt_tuple_ref(*itr, 2); if(pmt_eqv(key, itemkey)) { - found_items_by_key.push_back(*itr); + v.push_back(*itr); } } - - return found_items_by_key; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 5902d1559..834ef47f5 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -25,6 +25,7 @@ #include #include +#include #include /*! @@ -124,13 +125,15 @@ class gr_block_detail { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::vector get_tags_in_range(unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end); + void get_tags_in_range(std::vector &v, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end); /*! * \brief Given a [start,end), returns a vector of all tags in the range @@ -143,15 +146,17 @@ class gr_block_detail { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param which_input an integer of which input stream to pull from * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest * \param key a PMT symbol to select only tags of this key */ - std::vector get_tags_in_range(unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end, - const pmt::pmt_t &key); + void get_tags_in_range(std::vector &v, + unsigned int which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key); 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 9882c2e5d..59799069a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -89,7 +89,8 @@ min_available_space (gr_block_detail *d, int output_multiple) static bool propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, - const std::vector &start_nitems_read, double rrate) + const std::vector &start_nitems_read, double rrate, + std::vector &rtags) { // Move tags downstream // if a sink, we don't need to move downstream; @@ -105,10 +106,11 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, case(gr_block::TPP_ALL_TO_ALL): // every tag on every input propogates to everyone downstream for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], - d->nitems_read(i)); + d->get_tags_in_range(rtags, i, start_nitems_read[i], + d->nitems_read(i)); + std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { + for(t = rtags.begin(); t != rtags.end(); t++) { uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), pmt::pmt_tuple_ref(*t, 1), @@ -117,7 +119,6 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, for(int o = 0; o < d->noutputs(); o++) d->output(o)->add_item_tag(newtup); - //d->output(o)->add_item_tag(*t); } } break; @@ -127,11 +128,17 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, // type of tag-propagation system is selected in gr_block_detail if(d->ninputs() == d->noutputs()) { for(int i = 0; i < d->ninputs(); i++) { - std::vector tuple = d->get_tags_in_range(i, start_nitems_read[i], - d->nitems_read(i)); + d->get_tags_in_range(rtags, i, start_nitems_read[i], + d->nitems_read(i)); + std::vector::iterator t; - for(t = tuple.begin(); t != tuple.end(); t++ ) { - d->output(i)->add_item_tag(*t); + for(t = rtags.begin(); t != rtags.end(); t++) { + uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); + pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), + pmt::pmt_tuple_ref(*t, 1), + pmt::pmt_tuple_ref(*t, 2), + pmt::pmt_tuple_ref(*t, 3)); + d->output(i)->add_item_tag(newtup); } } } @@ -366,7 +373,8 @@ gr_block_executor::run_one_iteration() << " result = " << n << std::endl); if(!propagate_tags(m->tag_propagation_policy(), d, - d_start_nitems_read, m->relative_rate())) + d_start_nitems_read, m->relative_rate(), + d_returned_tags)) goto were_done; if (n == gr_block::WORK_DONE) diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h index 22b782883..77ace5522 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.h +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -25,6 +25,7 @@ #include #include +#include //class gr_block_executor; //typedef boost::shared_ptr gr_block_executor_sptr; @@ -48,6 +49,7 @@ protected: std::vector d_input_done; gr_vector_void_star d_output_items; std::vector d_start_nitems_read; //stores where tag counts are before work + std::vector d_returned_tags; public: gr_block_executor(gr_block_sptr block); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 84a65f921..70d57c094 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -271,13 +271,14 @@ gr_buffer_reader::update_read_pointer (int nitems) d_abs_read_offset += nitems; } -std::vector -gr_buffer_reader::get_tags_in_range(uint64_t abs_start, +void +gr_buffer_reader::get_tags_in_range(std::vector &v, + uint64_t abs_start, uint64_t abs_end) { gruel::scoped_lock guard(*mutex()); - std::vector found_items; + v.resize(0); std::deque::iterator itr = d_buffer->get_tags_begin(); uint64_t item_time; @@ -285,13 +286,11 @@ gr_buffer_reader::get_tags_in_range(uint64_t abs_start, item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); if((item_time >= abs_start) && (item_time <= abs_end)) { - found_items.push_back(*itr); + v.push_back(*itr); } itr++; } - - return found_items; } void diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 47ba4cd96..88a76fdc6 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -255,11 +255,13 @@ class gr_buffer_reader { * Tags are tuples of: * (item count, source id, key, value) * + * \param v a vector reference to return tags into * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - std::vector get_tags_in_range(uint64_t abs_start, - uint64_t abs_end); + void get_tags_in_range(std::vector &v, + uint64_t abs_start, + uint64_t abs_end); void prune_tags(uint64_t max_time); -- cgit From 2ce754d59c537b0ca395442a94c908f2b8b3dd58 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 19:44:36 -0800 Subject: Moved prune tags to gr_buffer. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 42 ++++++++++++++---------------- gnuradio-core/src/lib/runtime/gr_buffer.h | 5 ++-- 2 files changed, 22 insertions(+), 25 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 70d57c094..1488e92f6 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -162,9 +162,7 @@ gr_buffer::space_available () min_items_read = std::min(min_items_read, d_readers[i]->nitems_read()); } - for (size_t i = 0; i < d_readers.size (); i++) { - d_readers[i]->prune_tags(min_items_read); - } + prune_tags(min_items_read); // The -1 ensures that the case d_write_index == d_read_index is // unambiguous. It indicates that there is no data for the reader @@ -230,6 +228,25 @@ gr_buffer::add_item_tag(const pmt::pmt_t &tag) d_item_tags.push_back(tag); } +void +gr_buffer::prune_tags(uint64_t max_time) +{ + //gruel::scoped_lock guard(*mutex()); + + int n = 0; + uint64_t item_time; + std::deque::iterator itr = d_item_tags.begin(); + + while(itr != d_item_tags.end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + if(item_time < max_time) { + d_item_tags.pop_front(); + n++; + } + itr++; + } +} + long gr_buffer_ncurrently_allocated () { @@ -293,25 +310,6 @@ gr_buffer_reader::get_tags_in_range(std::vector &v, } } -void -gr_buffer_reader::prune_tags(uint64_t max_time) -{ - int n = 0; - uint64_t item_time; - std::deque::iterator itr = d_buffer->get_tags_begin(); - - while(itr != d_buffer->get_tags_end()) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); - if(item_time < max_time) { - d_buffer->tags_pop_front(); - n++; - } - //else - // break; - itr++; - } -} - long gr_buffer_reader_ncurrently_allocated () { diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 88a76fdc6..2d88c1722 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -99,9 +99,10 @@ class gr_buffer { */ void add_item_tag(const pmt::pmt_t &tag); + void prune_tags(uint64_t max_time); + std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } std::deque::iterator get_tags_end() { return d_item_tags.end(); } - void tags_pop_front() { d_item_tags.pop_front(); } // ------------------------------------------------------------------------- @@ -263,8 +264,6 @@ class gr_buffer_reader { uint64_t abs_start, uint64_t abs_end); - void prune_tags(uint64_t max_time); - // ------------------------------------------------------------------------- private: -- cgit From 6237fafa53938db53a3e2a82b79e80b524dd05db Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Thu, 18 Nov 2010 22:22:23 -0800 Subject: gr_msg_queue now working correctly from within guile. --- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 58 ++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 5b8fea49f..932747688 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -104,8 +104,60 @@ gr_msg_queue_sptr.delete_head = gr_py_msg_queue__delete_head gr_msg_queue_sptr.insert_tail = gr_py_msg_queue__insert_tail gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail %} -#endif +#endif // SWIGPYTHON +/* + * Similar trickery as above, only this time for Guile + */ #ifdef SWIGGUILE -#warning "gr_msg_queue.i: gr_msg_queue_sptr needs to be implemented!" -#endif + +%{ + struct arg_holder { + gr_msg_queue_sptr q; + gr_message_sptr msg; + }; + + void *insert_tail_shim(void *arg) + { + arg_holder *a = (arg_holder *)arg; + a->q->insert_tail(a->msg); + return 0; + } + + void *delete_head_shim(void *arg) + { + arg_holder *a = (arg_holder *)arg; + a->msg = a->q->delete_head(); + return 0; + } +%} + +%inline %{ + + // handle and insert_tail are equivalent + static void handle(gr_msg_queue_sptr q, gr_message_sptr msg) + { + arg_holder a; + a.q = q; + a.msg = msg; + scm_without_guile(insert_tail_shim, (void *) &a); + } + + static void insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg) + { + arg_holder a; + a.q = q; + a.msg = msg; + scm_without_guile(insert_tail_shim, (void *) &a); + } + + static gr_message_sptr delete_head(gr_msg_queue_sptr q) + { + arg_holder a; + a.q = q; + scm_without_guile(delete_head_shim, (void *) &a); + return a.msg; + } +%} + +#endif // SWIGGUILE -- cgit From 6551f537ed235bbb0ddfadb50744ea3b3fcbc2e6 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sat, 20 Nov 2010 16:30:43 -0800 Subject: Add guile shim to gr_top_block::wait that exits guile mode before blocking. --- gnuradio-core/src/lib/runtime/gr_top_block.i | 37 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index f18d8890b..90fa18b94 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -42,8 +42,8 @@ public: void start() throw (std::runtime_error); void stop(); - void wait(); - void run() throw (std::runtime_error); + //void wait(); + //void run() throw (std::runtime_error); void lock(); void unlock() throw (std::runtime_error); void dump(); @@ -71,6 +71,33 @@ void top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error) #endif -#ifdef SWIG_GUILE -#warning "gr_top_block.i: top_block_run_unlocked needs to be implemented!" +#ifdef SWIGGUILE + +%{ + struct tb_arg_holder { + gr_top_block_sptr tb; + }; + + static void * + tb_wait_shim(void *arg) + { + tb_arg_holder *a = (tb_arg_holder *)arg; + a->tb->wait(); + return 0; + } + +%} + +%inline %{ + + static void + top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error) + { + tb_arg_holder a; + a.tb = r; + scm_without_guile(tb_wait_shim, (void *) &a); + } + +%} + #endif -- cgit From 5c91f873301a6eca0895788b0b03862fc0060a19 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Sat, 20 Nov 2010 16:34:04 -0800 Subject: Minor tweaks: comments, static --- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 932747688..c9214bef3 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005,2009 Free Software Foundation, Inc. + * Copyright 2005,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -117,14 +117,16 @@ gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail gr_message_sptr msg; }; - void *insert_tail_shim(void *arg) + static void * + insert_tail_shim(void *arg) { arg_holder *a = (arg_holder *)arg; a->q->insert_tail(a->msg); return 0; } - void *delete_head_shim(void *arg) + static void * + delete_head_shim(void *arg) { arg_holder *a = (arg_holder *)arg; a->msg = a->q->delete_head(); @@ -135,7 +137,8 @@ gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail %inline %{ // handle and insert_tail are equivalent - static void handle(gr_msg_queue_sptr q, gr_message_sptr msg) + static void + handle(gr_msg_queue_sptr q, gr_message_sptr msg) { arg_holder a; a.q = q; @@ -143,7 +146,8 @@ gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail scm_without_guile(insert_tail_shim, (void *) &a); } - static void insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg) + static void + insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg) { arg_holder a; a.q = q; @@ -151,7 +155,8 @@ gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail scm_without_guile(insert_tail_shim, (void *) &a); } - static gr_message_sptr delete_head(gr_msg_queue_sptr q) + static gr_message_sptr + delete_head(gr_msg_queue_sptr q) { arg_holder a; a.q = q; -- cgit From b34360471571ea7346ab1c6cb87700a920ca5798 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 14:33:58 -0500 Subject: Fixing flowgraph dump to clean it up (via patch from eb). Also added note about mutex locking in prune_tags. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 8 ++++++++ gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 1488e92f6..0b2eb52a0 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -231,6 +231,14 @@ gr_buffer::add_item_tag(const pmt::pmt_t &tag) void gr_buffer::prune_tags(uint64_t max_time) { + /* NOTE: this function _should_ lock the mutex before editing + d_item_tags. In practice, this function is only called at + runtime by min_available_space in gr_block_executor.cc, + which locks the mutex itself. + + If this function is used elsewhere, remember to lock the + buffer's mutex al la the scoped_lock line below. + */ //gruel::scoped_lock guard(*mutex()); int n = 0; diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 031eb6dfd..5d1057e0f 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -264,16 +264,13 @@ void gr_flat_flowgraph::dump() int no = detail->noutputs(); for (int i = 0; i < no; i++) { gr_buffer_sptr buffer = detail->output(i); - std::cout << " output " << i << ": " << buffer - << " space=" << buffer->space_available() << std::endl; + std::cout << " output " << i << ": " << buffer << std::endl; } for (int i = 0; i < ni; i++) { gr_buffer_reader_sptr reader = detail->input(i); std::cout << " reader " << i << ": " << reader - << " reading from buffer=" << reader->buffer() - << " avail=" << reader->items_available() << " items" - << std::endl; + << " reading from buffer=" << reader->buffer() << std::endl; } } -- cgit From be71cffac7e1a90a1fdccdeab8bcf3697fd9ca9c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 14:43:06 -0500 Subject: Changing name of static tag keys. --- gnuradio-core/src/lib/runtime/gr_tag_info.cc | 10 +++++----- gnuradio-core/src/lib/runtime/gr_tag_info.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.cc b/gnuradio-core/src/lib/runtime/gr_tag_info.cc index 211f330e9..c64cc7eb8 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.cc +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.cc @@ -29,9 +29,9 @@ namespace gr_tags { - const pmt::pmt_t s_key_time = pmt::pmt_string_to_symbol("time"); - const pmt::pmt_t s_key_sample_rate = pmt::pmt_string_to_symbol("sample_rate"); - const pmt::pmt_t s_key_frequency = pmt::pmt_string_to_symbol("frequency"); - const pmt::pmt_t s_key_rssi = pmt::pmt_string_to_symbol("rssi"); - const pmt::pmt_t s_key_rx_gain = pmt::pmt_string_to_symbol("gain"); + const pmt::pmt_t key_time = pmt::pmt_string_to_symbol("time"); + const pmt::pmt_t key_sample_rate = pmt::pmt_string_to_symbol("sample_rate"); + const pmt::pmt_t key_frequency = pmt::pmt_string_to_symbol("frequency"); + const pmt::pmt_t key_rssi = pmt::pmt_string_to_symbol("rssi"); + const pmt::pmt_t key_rx_gain = pmt::pmt_string_to_symbol("gain"); } diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.h b/gnuradio-core/src/lib/runtime/gr_tag_info.h index af51cf6a9..0ba699a0e 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.h +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.h @@ -34,11 +34,11 @@ namespace gr_tags { TAG_VALUE_REF }; - extern const pmt::pmt_t s_key_time; - extern const pmt::pmt_t s_key_sample_rate; - extern const pmt::pmt_t s_key_frequency; - extern const pmt::pmt_t s_key_rssi; - extern const pmt::pmt_t s_key_gain; + extern const pmt::pmt_t key_time; + extern const pmt::pmt_t key_sample_rate; + extern const pmt::pmt_t key_frequency; + extern const pmt::pmt_t key_rssi; + extern const pmt::pmt_t key_gain; static inline uint64_t get_nitems(const pmt::pmt_t &tag) { -- cgit From 8f2b07591c404c78c9fc7b9532d3fb6c27165981 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 19:40:35 -0500 Subject: Tagging file source takes in sample rate and uses it to find the last time tag and adjust the time between these tags and the burst start by the sample rate. Also added a function to gr_tag_info that can be used to sort tags based on nitems using std::sort. --- gnuradio-core/src/lib/runtime/gr_tag_info.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.h b/gnuradio-core/src/lib/runtime/gr_tag_info.h index 0ba699a0e..5ed30a815 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.h +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.h @@ -40,26 +40,46 @@ namespace gr_tags { extern const pmt::pmt_t key_rssi; extern const pmt::pmt_t key_gain; + /*! + * \brief Returns the item \p tag occurred at (as a uint64_t) + */ static inline uint64_t get_nitems(const pmt::pmt_t &tag) { return pmt::pmt_to_uint64(pmt::pmt_tuple_ref(tag, TAG_NITEM_REF)); } + /*! + * \brief Returns the source ID of \p tag (as a PMT) + */ static inline pmt::pmt_t get_srcid(const pmt::pmt_t &tag) { return pmt::pmt_tuple_ref(tag, TAG_SRCID_REF); } + /*! + * \brief Returns the key of \p tag (as a PMT symbol) + */ static inline pmt::pmt_t get_key(const pmt::pmt_t &tag) { return pmt::pmt_tuple_ref(tag, TAG_KEY_REF); } + /*! + * \brief Returns the value of \p tag (as a PMT) + */ static inline pmt::pmt_t get_value(const pmt::pmt_t &tag) { return pmt::pmt_tuple_ref(tag, TAG_VALUE_REF); } + /*! + * \brief Comparison function to test which tag, \p x or \p y, came first in time + */ + static inline bool + nitems_compare(pmt::pmt_t x, pmt::pmt_t y) { + return get_nitems(x) < get_nitems(y); + } + }; /* namespace tags */ #endif /* GR_TAG_INFO */ -- cgit From 1b7b68ec2211c50de98bef7414e4ac807edf460a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 20:51:37 -0500 Subject: Doxygen comments. Fixing typos that were leading to warnings. --- gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 2 +- gnuradio-core/src/lib/runtime/gr_buffer.h | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 7caf3c34a..36eed3d10 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -247,7 +247,7 @@ class gr_block : public gr_basic_block { /*! * \brief Adds a new tag onto the given output buffer. * - * \param which_ouput an integer of which output stream to attach the tag + * \param which_output an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. * \param key the tag key as a PMT symbol diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 834ef47f5..d7ec3b136 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -103,7 +103,7 @@ class gr_block_detail { * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), * which appends the tag onto its deque. * - * \param which_ouput an integer of which output stream to attach the tag + * \param which_output an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. * \param key the tag key as a PMT symbol diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 2d88c1722..fe0e7585d 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -99,6 +99,11 @@ class gr_buffer { */ void add_item_tag(const pmt::pmt_t &tag); + /*! + * \brief Removes all tags before \p max_time from buffer + * + * \param max_time the time (item number) to trim up until. + */ void prune_tags(uint64_t max_time); std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } @@ -244,6 +249,7 @@ class gr_buffer_reader { /*! * \brief Return the block that reads via this reader. + * */ gr_block_sptr link() { return gr_block_sptr(d_link); } -- cgit From 181ad4cda3879a1760d61054ff32f8abbc9c24cf Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 22 Nov 2010 22:46:18 -0500 Subject: Check for relative rate and update tag only if not 1.0; otherwise just copy. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 59799069a..ea489d079 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -110,15 +110,23 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, d->nitems_read(i)); std::vector::iterator t; - for(t = rtags.begin(); t != rtags.end(); t++) { - uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); - pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), - pmt::pmt_tuple_ref(*t, 1), - pmt::pmt_tuple_ref(*t, 2), - pmt::pmt_tuple_ref(*t, 3)); - - for(int o = 0; o < d->noutputs(); o++) - d->output(o)->add_item_tag(newtup); + if(rrate != 1.0) { + for(t = rtags.begin(); t != rtags.end(); t++) { + uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); + pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), + pmt::pmt_tuple_ref(*t, 1), + pmt::pmt_tuple_ref(*t, 2), + pmt::pmt_tuple_ref(*t, 3)); + + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(newtup); + } + } + else { + for(t = rtags.begin(); t != rtags.end(); t++) { + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(*t); + } } } break; -- cgit From 7d14fec5653b7aa92de8ef9ba76f02b7181ee928 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 23 Nov 2010 22:57:10 -0500 Subject: Removing dependency in QA code to filters that have not necessarily been built yet. Using test block keep_one_in_n to test decimation is handled in propogating tags. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 39 ++++---------------------- 1 file changed, 5 insertions(+), 34 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 2092e48ed..14983013c 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -31,8 +31,7 @@ #include #include #include -#include -#include +#include #include #include @@ -375,18 +374,14 @@ qa_block_tags::t5 () gr_block_sptr snk0 (gr_make_null_sink(sizeof(float))); // Rate change blocks - std::vector taps = gr_firdes::low_pass_2(1, 1, 0.4, 0.1, 60); - gr_fir_filter_fff_sptr fir_dec10 (gr_make_fir_filter_fff(10, taps)); - gr_interp_fir_filter_fff_sptr fir_int2 (gr_make_interp_fir_filter_fff(2, taps)); + gr_keep_one_in_n_sptr dec10 (gr_make_keep_one_in_n(sizeof(float), 10)); tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); tb->connect(ann0, 0, ann1, 0); - tb->connect(ann1, 0, fir_dec10, 0); - tb->connect(fir_dec10, 0, ann2, 0); - tb->connect(ann2, 0, fir_int2, 0); - tb->connect(fir_int2, 0, ann3, 0); - tb->connect(ann3, 0, snk0, 0); + tb->connect(ann1, 0, dec10, 0); + tb->connect(dec10, 0, ann2, 0); + tb->connect(ann2, 0, snk0, 0); tb->run(); @@ -414,24 +409,9 @@ qa_block_tags::t5 () expected_tags2[8] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(4)); expected_tags2[9] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(4)); - pmt_t expected_tags3[12]; - expected_tags3[0] = mp(pmt_from_uint64(0), mp(str2.str()), mp("seq"), mp(0)); - expected_tags3[1] = mp(pmt_from_uint64(0), mp(str1.str()), mp("seq"), mp(0)); - expected_tags3[2] = mp(pmt_from_uint64(0), mp(str0.str()), mp("seq"), mp(0)); - expected_tags3[3] = mp(pmt_from_uint64(2000), mp(str2.str()), mp("seq"), mp(1)); - expected_tags3[4] = mp(pmt_from_uint64(2000), mp(str1.str()), mp("seq"), mp(1)); - expected_tags3[5] = mp(pmt_from_uint64(2000), mp(str0.str()), mp("seq"), mp(1)); - expected_tags3[6] = mp(pmt_from_uint64(4000), mp(str2.str()), mp("seq"), mp(2)); - expected_tags3[7] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(2)); - expected_tags3[8] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(2)); - expected_tags3[9] = mp(pmt_from_uint64(6000), mp(str2.str()), mp("seq"), mp(3)); - expected_tags3[10] = mp(pmt_from_uint64(6000), mp(str1.str()), mp("seq"), mp(3)); - expected_tags3[11] = mp(pmt_from_uint64(6000), mp(str0.str()), mp("seq"), mp(3)); - std::vector tags0 = ann0->data(); std::vector tags1 = ann1->data(); std::vector tags2 = ann2->data(); - std::vector tags3 = ann3->data(); // The first annotator does not receive any tags from the null sink upstream CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); @@ -453,14 +433,5 @@ qa_block_tags::t5 () std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); } - - // annotator 3 gets tags from annotators 0, 1, and 2 - std::cout << std::endl; - std::cout << "tags3.size(): " << tags3.size() << std::endl; - CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); - for(size_t i = 0; i < tags3.size(); i++) { - std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); - } } -- cgit From 4649aa471222351e8586b90e98bb947325d340b6 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 28 Nov 2010 19:15:27 -0500 Subject: Changing propagation policy enum type name and making a few other minor edits. --- gnuradio-core/src/lib/runtime/gr_block.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_block.h | 8 ++++---- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 52be37e3b..81a55af9d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -169,14 +169,14 @@ gr_block::get_tags_in_range(std::vector &v, d_detail->get_tags_in_range(v, which_output, start, end, key); } -gr_block::TAG_PROPAGATION_POLICY +gr_block::tag_propagation_policy_t gr_block::tag_propagation_policy() { return d_tag_propagation_policy; } void -gr_block::set_tag_propagation_policy(TAG_PROPAGATION_POLICY p) +gr_block::set_tag_propagation_policy(tag_propagation_policy_t p) { d_tag_propagation_policy = p; } diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 36eed3d10..ad7fa9555 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -63,7 +63,7 @@ class gr_block : public gr_basic_block { WORK_DONE = -1 }; - enum TAG_PROPAGATION_POLICY { + enum tag_propagation_policy_t { TPP_DONT = 0, TPP_ALL_TO_ALL = 1, TPP_ONE_TO_ONE = 2 @@ -217,12 +217,12 @@ class gr_block : public gr_basic_block { /*! * \brief Asks for the policy used by the scheduler to moved tags downstream. */ - TAG_PROPAGATION_POLICY tag_propagation_policy(); + tag_propagation_policy_t tag_propagation_policy(); /*! * \brief Set the policy by the scheduler to determine how tags are moved downstream. */ - void set_tag_propagation_policy(TAG_PROPAGATION_POLICY p); + void set_tag_propagation_policy(tag_propagation_policy_t p); // ---------------------------------------------------------------------------- @@ -233,7 +233,7 @@ class gr_block : public gr_basic_block { gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; - TAG_PROPAGATION_POLICY d_tag_propagation_policy; // policy for moving tags downstream + tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream protected: diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 59799069a..4a35e25d5 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,2009 Free Software Foundation, Inc. + * Copyright 2004,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -88,7 +88,7 @@ min_available_space (gr_block_detail *d, int output_multiple) } static bool -propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, +propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, const std::vector &start_nitems_read, double rrate, std::vector &rtags) { @@ -100,10 +100,10 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, } switch(policy) { - case(gr_block::TPP_DONT): + case gr_block::TPP_DONT: return true; break; - case(gr_block::TPP_ALL_TO_ALL): + case gr_block::TPP_ALL_TO_ALL: // every tag on every input propogates to everyone downstream for(int i = 0; i < d->ninputs(); i++) { d->get_tags_in_range(rtags, i, start_nitems_read[i], @@ -122,7 +122,7 @@ propagate_tags(gr_block::TAG_PROPAGATION_POLICY policy, gr_block_detail *d, } } break; - case(gr_block::TPP_ONE_TO_ONE): + case gr_block::TPP_ONE_TO_ONE: // tags from input i only go to output i // this requires d->ninputs() == d->noutputs; this is checked when this // type of tag-propagation system is selected in gr_block_detail @@ -362,7 +362,7 @@ gr_block_executor::run_one_iteration() for (int i = 0; i < d->noutputs (); i++) d_output_items[i] = d->output(i)->write_pointer(); - // determine where to start looking for new tags as 1 past nitems read + // determine where to start looking for new tags for (int i = 0; i < d->ninputs(); i++) d_start_nitems_read[i] = d->nitems_read(i); -- cgit From 0f2bd2c94baa43fc8626f5285c0696a379ef5efd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 28 Nov 2010 19:17:07 -0500 Subject: Swapping order of testing rrate. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 9c30b1334..112150235 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -110,7 +110,13 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, d->nitems_read(i)); std::vector::iterator t; - if(rrate != 1.0) { + if(rrate == 1.0) { + for(t = rtags.begin(); t != rtags.end(); t++) { + for(int o = 0; o < d->noutputs(); o++) + d->output(o)->add_item_tag(*t); + } + } + else { for(t = rtags.begin(); t != rtags.end(); t++) { uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), @@ -122,12 +128,6 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, d->output(o)->add_item_tag(newtup); } } - else { - for(t = rtags.begin(); t != rtags.end(); t++) { - for(int o = 0; o < d->noutputs(); o++) - d->output(o)->add_item_tag(*t); - } - } } break; case gr_block::TPP_ONE_TO_ONE: -- cgit From 34a9654fa10efcf360fde9c42c624739abaabbc5 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 29 Nov 2010 12:59:54 -0500 Subject: Removing global pmt constants. Were causing segfaults during make check. Must fix this later. --- gnuradio-core/src/lib/runtime/gr_tag_info.cc | 3 ++- gnuradio-core/src/lib/runtime/gr_tag_info.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.cc b/gnuradio-core/src/lib/runtime/gr_tag_info.cc index c64cc7eb8..f15329f9b 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.cc +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.cc @@ -28,10 +28,11 @@ #include namespace gr_tags { - +/* const pmt::pmt_t key_time = pmt::pmt_string_to_symbol("time"); const pmt::pmt_t key_sample_rate = pmt::pmt_string_to_symbol("sample_rate"); const pmt::pmt_t key_frequency = pmt::pmt_string_to_symbol("frequency"); const pmt::pmt_t key_rssi = pmt::pmt_string_to_symbol("rssi"); const pmt::pmt_t key_rx_gain = pmt::pmt_string_to_symbol("gain"); +*/ } diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.h b/gnuradio-core/src/lib/runtime/gr_tag_info.h index 5ed30a815..5a1e1555a 100644 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.h +++ b/gnuradio-core/src/lib/runtime/gr_tag_info.h @@ -34,11 +34,13 @@ namespace gr_tags { TAG_VALUE_REF }; + /* extern const pmt::pmt_t key_time; extern const pmt::pmt_t key_sample_rate; extern const pmt::pmt_t key_frequency; extern const pmt::pmt_t key_rssi; extern const pmt::pmt_t key_gain; + */ /*! * \brief Returns the item \p tag occurred at (as a uint64_t) -- cgit From 1b179f0b381cbba224674db5678e542ce34a3d2a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 29 Nov 2010 14:56:16 -0500 Subject: Modifying QA tests for the sample tags. By default, it only checks the sizes of the tags since order is not specified or guarenteed. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 131 ++++++++++++++----------- 1 file changed, 72 insertions(+), 59 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 14983013c..07ce5c276 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -40,11 +40,18 @@ using namespace pmt; +// set to 1 to turn on debug output +// The debug output fully checks that the tags seen are what are expected. While +// this behavior currently works with our implementation, there is no guarentee +// that the tags will be coming in this specific order, so it's dangerous to +// rely on this as a test of the tag system working. We would really want to +// tags we know we should see and then test that they all occur once, but in no +// particular order. +#define QA_TAGS_DEBUG 0 + void qa_block_tags::t0 () { - printf("\nqa_block_tags::t0\n"); - unsigned int N = 1000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -71,8 +78,6 @@ qa_block_tags::t0 () void qa_block_tags::t1 () { - printf("\nqa_block_tags::t1\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -98,6 +103,16 @@ qa_block_tags::t1 () tb->run(); + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); + +#if QA_TAGS_DEBUG // Kludge together the tags that we know should result from the above graph std::stringstream str0, str1, str2; str0 << ann0->name() << ann0->unique_id(); @@ -123,36 +138,27 @@ qa_block_tags::t1 () expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); - - std::vector tags0 = ann0->data(); - std::vector tags3 = ann3->data(); - std::vector tags4 = ann4->data(); - - // The first annotator does not receive any tags from the null sink upstream - CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + std::cout << std::endl << "qa_block_tags::t1" << std::endl; + // For annotator 3, we know it gets tags from ann0 and ann1, test this - CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - //pmt_equal(tags3[i], expected_tags3[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); } // For annotator 4, we know it gets tags from ann0 and ann2, test this std::cout << std::endl; - CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); } +#endif } void qa_block_tags::t2 () { - printf("\nqa_block_tags::t2\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -181,6 +187,23 @@ qa_block_tags::t2 () tb->run(); + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); + std::vector tags3 = ann4->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)8); + + // Make sure the rest all have 12 tags + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)12); + + +#if QA_TAGS_DEBUG // Kludge together the tags that we know should result from the above graph std::stringstream str0, str1; str0 << ann0->name() << ann0->unique_id(); @@ -214,20 +237,7 @@ qa_block_tags::t2 () expected_tags4[10] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(6)); expected_tags4[11] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); - std::vector tags0 = ann0->data(); - std::vector tags1 = ann1->data(); - std::vector tags2 = ann2->data(); - std::vector tags3 = ann4->data(); - std::vector tags4 = ann4->data(); - - // The first annotator does not receive any tags from the null sink upstream - CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); - CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)8); - - // Make sure the rest all have 12 tags - CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)12); - CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)12); - CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)12); + std::cout << std::endl << "qa_block_tags::t2" << std::endl; // For annotator[2-4], we know it gets tags from ann0 and ann1 // but the tags from the different outputs of ann1 are different for each. @@ -235,24 +245,21 @@ qa_block_tags::t2 () // inconceivable for ann3 to have it wrong. for(size_t i = 0; i < tags2.size(); i++) { std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; - //pmt_equal(tags2[i], expected_tags2[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); } std::cout << std::endl; for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags2[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; - //pmt_equal(tags4[i], expected_tags4[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); } +#endif } void qa_block_tags::t3 () { - printf("\nqa_block_tags::t3\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -279,6 +286,17 @@ qa_block_tags::t3 () tb->run(); + + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); + CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); + +#if QA_TAGS_DEBUG // Kludge together the tags that we know should result from the above graph std::stringstream str0, str1, str2; str0 << ann0->name() << ann0->unique_id(); @@ -304,37 +322,28 @@ qa_block_tags::t3 () expected_tags4[5] = mp(pmt_from_uint64(20000), mp(str0.str()), mp("seq"), mp(5)); expected_tags4[6] = mp(pmt_from_uint64(30000), mp(str2.str()), mp("seq"), mp(3)); expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); - - std::vector tags0 = ann0->data(); - std::vector tags3 = ann3->data(); - std::vector tags4 = ann4->data(); - - // The first annotator does not receive any tags from the null sink upstream - CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + std::cout << std::endl << "qa_block_tags::t3" << std::endl; + // For annotator 3, we know it gets tags from ann0 and ann1, test this - CPPUNIT_ASSERT_EQUAL(tags3.size(), (size_t)8); for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; - //pmt_equal(tags3[i], expected_tags3[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags3[i]), pmt_write_string(expected_tags3[i])); } // For annotator 4, we know it gets tags from ann0 and ann2, test this std::cout << std::endl; - CPPUNIT_ASSERT_EQUAL(tags4.size(), (size_t)8); for(size_t i = 0; i < tags4.size(); i++) { std::cout << "tags4[" << i << "] = " << tags4[i] << "\t\t" << expected_tags4[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags4[i]), pmt_write_string(expected_tags4[i])); } +#endif } void qa_block_tags::t4 () { - printf("\nqa_block_tags::t4\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(int))); @@ -354,6 +363,9 @@ qa_block_tags::t4 () tb->connect(ann1, 0, snk0, 0); tb->connect(ann2, 0, snk1, 0); + std::cerr << std::endl + << "NOTE: This is supposed to produce an error from gr_block_executor" + << std::endl; tb->run(); } @@ -361,16 +373,13 @@ qa_block_tags::t4 () void qa_block_tags::t5 () { - printf("\nqa_block_tags::t5\n"); - int N = 40000; gr_top_block_sptr tb = gr_make_top_block("top"); gr_block_sptr src (gr_make_null_source(sizeof(float))); gr_block_sptr head (gr_make_head(sizeof(float), N)); gr_annotator_alltoall_sptr ann0 (gr_make_annotator_alltoall(10000, sizeof(float))); - gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(float))); + gr_annotator_alltoall_sptr ann1 (gr_make_annotator_alltoall(10000, sizeof(float))); gr_annotator_alltoall_sptr ann2 (gr_make_annotator_alltoall(1000, sizeof(float))); - gr_annotator_alltoall_sptr ann3 (gr_make_annotator_alltoall(2000, sizeof(float))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(float))); // Rate change blocks @@ -385,6 +394,17 @@ qa_block_tags::t5 () tb->run(); + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); + + // The first annotator does not receive any tags from the null sink upstream + CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); + CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); + + +#if QA_TAGS_DEBUG // Kludge together the tags that we know should result from the above graph std::stringstream str0, str1, str2; str0 << ann0->name() << ann0->unique_id(); @@ -409,29 +429,22 @@ qa_block_tags::t5 () expected_tags2[8] = mp(pmt_from_uint64(4000), mp(str1.str()), mp("seq"), mp(4)); expected_tags2[9] = mp(pmt_from_uint64(4000), mp(str0.str()), mp("seq"), mp(4)); - std::vector tags0 = ann0->data(); - std::vector tags1 = ann1->data(); - std::vector tags2 = ann2->data(); - - // The first annotator does not receive any tags from the null sink upstream - CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); + std::cout << std::endl << "qa_block_tags::t5" << std::endl; // annotator 1 gets tags from annotator 0 std::cout << "tags1.size(): " << tags1.size() << std::endl; - CPPUNIT_ASSERT_EQUAL(tags1.size(), (size_t)4); for(size_t i = 0; i < tags1.size(); i++) { std::cout << "tags1[" << i << "] = " << tags1[i] << "\t\t" << expected_tags1[i] << std::endl; - //pmt_equal(tags1[i], expected_tags1[i]) CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags1[i]), pmt_write_string(expected_tags1[i])); } // annotator 2 gets tags from annotators 0 and 1 std::cout << std::endl; std::cout << "tags2.size(): " << tags2.size() << std::endl; - CPPUNIT_ASSERT_EQUAL(tags2.size(), (size_t)8); for(size_t i = 0; i < tags2.size(); i++) { std::cout << "tags2[" << i << "] = " << tags2[i] << "\t\t" << expected_tags2[i] << std::endl; CPPUNIT_ASSERT_EQUAL(pmt_write_string(tags2[i]), pmt_write_string(expected_tags2[i])); } +#endif } -- cgit From 9911a8d9edcde54b9a18810f37799a58a6895310 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 7 Dec 2010 13:35:54 -0800 Subject: Remove incorrect if PYTHON around swiginclude_HEADERS --- gnuradio-core/src/lib/runtime/Makefile.am | 2 -- 1 file changed, 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index dd9a8ea64..0fdb58aff 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -142,7 +142,6 @@ noinst_HEADERS = \ qa_block_tags.h \ qa_runtime.h -if PYTHON swiginclude_HEADERS = \ gr_basic_block.i \ gr_block.i \ @@ -162,4 +161,3 @@ swiginclude_HEADERS = \ gr_sync_interpolator.i \ gr_top_block.i \ runtime.i -endif -- cgit From 153de8c41caa9c478bec2f10b8a1167952809eed Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 23 Dec 2010 18:31:28 -0500 Subject: Modifying the unittest output. XML files are no longer written outside of the build tree. --- gnuradio-core/src/lib/runtime/gr_unittests.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_unittests.h b/gnuradio-core/src/lib/runtime/gr_unittests.h index 680e59ca4..70aa6f294 100644 --- a/gnuradio-core/src/lib/runtime/gr_unittests.h +++ b/gnuradio-core/src/lib/runtime/gr_unittests.h @@ -45,14 +45,13 @@ */ static void -ensure_unittest_path (const char *grpath, const char *path) +ensure_unittest_path (const char *path) { struct stat statbuf; if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) return; // blindly try to make it // FIXME make this robust. C++ SUCKS! - gr_mkdir (grpath, 0750); gr_mkdir (path, 0750); } @@ -60,11 +59,9 @@ static void get_unittest_path (const char *filename, char *fullpath, size_t pathsize) { char path[200]; - char grpath[200]; - snprintf (grpath, sizeof(grpath), "%s/.gnuradio", getenv ("HOME")); - snprintf (path, sizeof(path), "%s/unittests", grpath); + snprintf (path, sizeof(path), "./.unittests"); snprintf (fullpath, pathsize, "%s/%s", path, filename); - ensure_unittest_path(grpath, path); + ensure_unittest_path(path); } -- cgit From 9c07c99147955574354d9d2a36c18f7aa8988130 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 2 Jan 2011 11:29:38 -0500 Subject: Fixing a comment. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 112150235..a8d0bc1c8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -93,8 +93,7 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, std::vector &rtags) { // Move tags downstream - // if a sink, we don't need to move downstream; - // and do not bother if block uses TAGS_NONE attribute + // if a sink, we don't need to move downstream if(d->sink_p()) { return true; } -- cgit From c11a431055c1e84ed16a6567cc9b2f3b821ad5e7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 2 Jan 2011 11:31:56 -0500 Subject: Buffers now hold on to all tags from both this window and the last window of items instead of just this window. This protects against the rare times when one block is called twice before another block is, thereby pruning the tags before they can be passed downstream. The same thing will happen if a block is called 3 times in a row, which is highly unlikely. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 9 +++++---- gnuradio-core/src/lib/runtime/gr_buffer.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 0b2eb52a0..0bff0271a 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -80,7 +80,8 @@ minimum_buffer_items (long type_size, long page_size) gr_buffer::gr_buffer (int nitems, size_t sizeof_item, gr_block_sptr link) : d_base (0), d_bufsize (0), d_vmcircbuf (0), d_sizeof_item (sizeof_item), d_link(link), - d_write_index (0), d_abs_write_offset(0), d_done (false) + d_write_index (0), d_abs_write_offset(0), d_done (false), + d_last_min_items_read(0) { if (!allocate_buffer (nitems, sizeof_item)) throw std::bad_alloc (); @@ -162,7 +163,9 @@ gr_buffer::space_available () min_items_read = std::min(min_items_read, d_readers[i]->nitems_read()); } - prune_tags(min_items_read); + //prune_tags(min_items_read); + prune_tags(d_last_min_items_read); + d_last_min_items_read = min_items_read; // The -1 ensures that the case d_write_index == d_read_index is // unambiguous. It indicates that there is no data for the reader @@ -241,7 +244,6 @@ gr_buffer::prune_tags(uint64_t max_time) */ //gruel::scoped_lock guard(*mutex()); - int n = 0; uint64_t item_time; std::deque::iterator itr = d_item_tags.begin(); @@ -249,7 +251,6 @@ gr_buffer::prune_tags(uint64_t max_time) item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); if(item_time < max_time) { d_item_tags.pop_front(); - n++; } itr++; } diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index fe0e7585d..aa26f1e09 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -135,7 +135,7 @@ class gr_buffer { uint64_t d_abs_write_offset; // num items written since the start bool d_done; std::deque d_item_tags; - + uint64_t d_last_min_items_read; unsigned index_add (unsigned a, unsigned b) -- cgit From 9c0bfe8920ec66b5b9f1f287d63ee66b4d208862 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 2 Jan 2011 11:37:01 -0500 Subject: Not using an iterator to prune the tags to see if this fixes a problem in Windows. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 0bff0271a..da1d8b542 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -245,14 +245,11 @@ gr_buffer::prune_tags(uint64_t max_time) //gruel::scoped_lock guard(*mutex()); uint64_t item_time; - std::deque::iterator itr = d_item_tags.begin(); - - while(itr != d_item_tags.end()) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + for(size_t i = 0; i < d_item_tags.size(); i++) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(d_item_tags[i], 0)); if(item_time < max_time) { d_item_tags.pop_front(); } - itr++; } } -- cgit From 6925ccc667c8278c7b250fb4f7225e01680c62ea Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 2 Jan 2011 13:49:08 -0500 Subject: Going back to iterators for use in erasing items from the deque. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index da1d8b542..3c935b960 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -243,13 +243,23 @@ gr_buffer::prune_tags(uint64_t max_time) buffer's mutex al la the scoped_lock line below. */ //gruel::scoped_lock guard(*mutex()); + std::deque::iterator itr = d_item_tags.begin(); uint64_t item_time; - for(size_t i = 0; i < d_item_tags.size(); i++) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(d_item_tags[i], 0)); + + // Since tags are not guarenteed to be in any particular order, + // we need to erase here instead of pop_front. An erase in the + // middle invalidates all iterators; so this resets the iterator + // to find more. Mostly, we wil be erasing from the front and + // therefore lose little time this way. + while(itr != d_item_tags.end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); if(item_time < max_time) { - d_item_tags.pop_front(); + d_item_tags.erase(itr); + itr = d_item_tags.begin(); } + else + itr++; } } -- cgit From 99c2b220675f3ca73ef5cf0a9ebe03706f813d61 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 4 Jan 2011 11:10:27 -0500 Subject: Only prune if we've moved on in the number of items read. Fixes the problem or premature pruning. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 3c935b960..624ca78a8 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -163,9 +163,10 @@ gr_buffer::space_available () min_items_read = std::min(min_items_read, d_readers[i]->nitems_read()); } - //prune_tags(min_items_read); - prune_tags(d_last_min_items_read); - d_last_min_items_read = min_items_read; + if(min_items_read != d_last_min_items_read) { + prune_tags(d_last_min_items_read); + d_last_min_items_read = min_items_read; + } // The -1 ensures that the case d_write_index == d_read_index is // unambiguous. It indicates that there is no data for the reader -- cgit From 7c78b8501ac6e9f386c9d4c0315913f6d3c72617 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 4 Jan 2011 12:48:49 -0500 Subject: Fixing how far get_tags_in_range looks; should be exclusive of end point. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 624ca78a8..03d5a8738 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -319,7 +319,7 @@ gr_buffer_reader::get_tags_in_range(std::vector &v, while(itr != d_buffer->get_tags_end()) { item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); - if((item_time >= abs_start) && (item_time <= abs_end)) { + if((item_time >= abs_start) && (item_time < abs_end)) { v.push_back(*itr); } -- cgit From b6005d9e5823d871c091f3b4a048ca67cd885821 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Thu, 6 Jan 2011 21:39:10 -0800 Subject: Change pmt message handling interface in gr_basic_block.h Change the API such that the message handler is now implemented with a callback, not an overridden virtual function. The callback is now set using gr_basic_block::set_msg_handler, which will accept pretty much any kind of callable. This change allows us to split the machinery for message handling out from the block inheritance hierarchy, and provides a foundation that can be used to build or experiment with arbitrary message dispatching techniques. --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 54 ++++++++++++++++++---- .../src/lib/runtime/gr_tpb_thread_body.cc | 8 ++-- 2 files changed, 50 insertions(+), 12 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index d059a4bd3..ce7a1aa1d 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. + * Copyright 2006,2008,2009,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -42,9 +43,27 @@ class gr_basic_block : public gr_msg_accepter, public boost::enable_shared_from_this { + typedef boost::function msg_handler_t; + +private: + /* + * This function is called by the runtime system to dispatch messages. + * + * The thread-safety guarantees mentioned in set_msg_handler are implemented + * by the callers of this method. + */ + void dispatch_msg(pmt::pmt_t msg) + { + if (d_msg_handler) // Is there a handler? + d_msg_handler(msg); // Yes, invoke it. + }; + + msg_handler_t d_msg_handler; + protected: friend class gr_flowgraph; friend class gr_flat_flowgraph; // TODO: will be redundant + friend class gr_tpb_thread_body; enum vcolor { WHITE, GREY, BLACK }; @@ -99,15 +118,34 @@ public: virtual bool check_topology(int ninputs, int noutputs) { return true; } /*! - * \brief Block message handler. - * - * \param msg Arbitrary message encapsulated as pmt::pmt_t + * \brief Set the callback that is fired when messages are available. * - * This function is called by the runtime system whenever there are - * messages in its queue. Blocks should override this to receive - * messages; the default behavior is to drop them on the floor. + * \p msg_handler can be any kind of function pointer or function object + * that has the signature: + *
+     *    void msg_handler(pmt::pmt msg);
+     * 
+ * + * (You may want to use boost::bind to massage your callable into the + * correct form. See gr_nop.{h,cc} for an example that sets up a class + * method as the callback.) + * + * Blocks that desire to handle messages must call this method in their + * constructors to register the handler that will be invoked when messages + * are available. + * + * If the block inherits from gr_block, the runtime system will ensure that + * msg_handler is called in a thread-safe manner, such that work and + * msg_handler will never be called concurrently. This allows msg_handler + * to update state variables without having to worry about thread-safety + * issues with work, general_work or another invocation of msg_handler. + * + * If the block inherits from gr_hier_block2, the runtime system will + * ensure that no reentrant calls are made to msg_handler. */ - virtual void handle_msg(pmt::pmt_t msg) { }; + template void set_msg_handler(T msg_handler){ + d_msg_handler = msg_handler_t(msg_handler); + } }; inline bool operator<(gr_basic_block_sptr lhs, gr_basic_block_sptr rhs) diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index 03eef17d9..faa888697 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008,2009 Free Software Foundation, Inc. + * Copyright 2008,2009,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -43,7 +43,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) // handle any queued up messages while ((msg = d->d_tpb.delete_head_nowait())) - block->handle_msg(msg); + block->dispatch_msg(msg); d->d_tpb.clear_changed(); s = d_exec.run_one_iteration(); @@ -73,7 +73,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) // handle all pending messages while ((msg = d->d_tpb.delete_head_nowait_already_holding_mutex())){ guard.unlock(); // release lock while processing msg - block->handle_msg(msg); + block->dispatch_msg(msg); guard.lock(); } } @@ -93,7 +93,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) // handle all pending messages while ((msg = d->d_tpb.delete_head_nowait_already_holding_mutex())){ guard.unlock(); // release lock while processing msg - block->handle_msg(msg); + block->dispatch_msg(msg); guard.lock(); } } -- cgit From bb438e7d12c5767123f8abed5810f284a5f18bf8 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Thu, 6 Jan 2011 21:48:12 -0800 Subject: Add QA code for gr_basic_block::set_msg_handler. --- gnuradio-core/src/lib/runtime/Makefile.am | 2 + gnuradio-core/src/lib/runtime/qa_runtime.cc | 4 +- .../src/lib/runtime/qa_set_msg_handler.cc | 85 ++++++++++++++++++++++ gnuradio-core/src/lib/runtime/qa_set_msg_handler.h | 43 +++++++++++ 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc create mode 100644 gnuradio-core/src/lib/runtime/qa_set_msg_handler.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 0fdb58aff..3dd2b42f5 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -81,6 +81,7 @@ libruntime_qa_la_SOURCES = \ qa_gr_io_signature.cc \ qa_gr_vmcircbuf.cc \ qa_block_tags.cc \ + qa_set_msg_handler.cc \ qa_runtime.cc grinclude_HEADERS = \ @@ -140,6 +141,7 @@ noinst_HEADERS = \ qa_gr_top_block.h \ qa_gr_vmcircbuf.h \ qa_block_tags.h \ + qa_set_msg_handler.h \ qa_runtime.h swiginclude_HEADERS = \ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 967d4bfa8..c0bee8ea0 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -1,5 +1,5 @@ /* - * Copyright 2002,2007 Free Software Foundation, Inc. + * Copyright 2002,2007,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -39,6 +39,7 @@ #include #include #include +#include CppUnit::TestSuite * qa_runtime::suite () @@ -54,6 +55,7 @@ qa_runtime::suite () s->addTest (qa_gr_hier_block2_derived::suite ()); s->addTest (qa_gr_buffer::suite ()); s->addTest (qa_block_tags::suite ()); + s->addTest (qa_set_msg_handler::suite ()); return s; } diff --git a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc new file mode 100644 index 000000000..d52ca78b9 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc @@ -0,0 +1,85 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2011 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define VERBOSE 0 + +using namespace pmt; + +/* + * The gr_nop block has been instrumented so that it counts + * the number of messages sent to it. We use this feature + * to confirm that gr_nop's call to set_msg_handler is working + * correctly. + */ + +void qa_set_msg_handler::t0() +{ + static const int NMSGS = 10; + + if (VERBOSE) std::cout << "qa_set_msg_handler::t0()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_nop_sptr nop = gr_make_nop(sizeof(int)); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + tb->connect(src, 0, nop, 0); + tb->connect(nop, 0, dst, 0); + + // Must start graph before sending messages + tb->start(); + + // Send them... + for (int i = 0; i < NMSGS; i++){ + send(nop, mp(mp("example-msg"), mp(i))); + } + + // And send a message to null_source to confirm that the default + // message handling action (which should be a nop) doesn't dump + // core. + send(src, mp(mp("example-msg"), mp(0))); + + // Surrender our CPU for a bit + boost::this_thread::yield(); + + tb->stop(); + tb->wait(); + + // Confirm that the nop block received the right number of messages. + CPPUNIT_ASSERT_EQUAL(NMSGS, nop->nmsgs_received()); +} diff --git a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.h b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.h new file mode 100644 index 000000000..e73fffbcd --- /dev/null +++ b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.h @@ -0,0 +1,43 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2011 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_QA_SET_MSG_HANDLER_H +#define INCLUDED_QA_SET_MSG_HANDLER_H + +#include +#include +#include + +class qa_set_msg_handler : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(qa_set_msg_handler); + + CPPUNIT_TEST(t0); + + CPPUNIT_TEST_SUITE_END(); + +private: + + void t0(); +}; + +#endif /* INCLUDED_QA_SET_MSG_HANDLER_H */ -- cgit From a2262b6bb70923d89e96ca0d597d96a8a01e4b67 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Mon, 10 Jan 2011 23:05:18 -0800 Subject: qa_set_msg_handler: Use sleep instead of yield. Confirmed to fix problem on 32-bit CoreDuo. Probably fixes problem on Arm too. --- gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc index d52ca78b9..35ef5527e 100644 --- a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc +++ b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc @@ -74,8 +74,8 @@ void qa_set_msg_handler::t0() // core. send(src, mp(mp("example-msg"), mp(0))); - // Surrender our CPU for a bit - boost::this_thread::yield(); + // Give the messages a chance to be processed + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); tb->stop(); tb->wait(); -- cgit From 48f9ca90e0cbcbfe67b0e10889c60928d9be5c49 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 17 Jan 2011 16:37:45 -0800 Subject: gr math simplification: Replaces gr_gcd, gr_isnan, and gr_signbit one-time instances with boot math calls. No point in wrapping these utility math functions into gnuradio when they are 1) provided by boost 2) only called once Removes gr_math.cc, and configure checks for isnan. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 03d5a8738..fa3722714 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -31,6 +31,7 @@ #include #include #include +#include static long s_buffer_count = 0; // counts for debugging storage mgmt static long s_buffer_reader_count = 0; @@ -73,7 +74,7 @@ static long s_buffer_reader_count = 0; static long minimum_buffer_items (long type_size, long page_size) { - return page_size / gr_gcd (type_size, page_size); + return page_size / boost::math::gcd (type_size, page_size); } -- cgit From 05cc02cec03507c47846a668c92e6dcc4ba2e71e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 18 Jan 2011 01:00:15 -0800 Subject: cleanup mkdir usage with boost filesystem: Replaced copy/pasted code and MKDIR_TAKES_ONE_ARG #ifdefs with portable boost filesystem path and directory creation. Gets the correct home directory on windows systems: APPDATA. Replaces large amounts of copypasta with single lines of code. Removes MKDIR_TAKES_ONE_ARG configuration checks from m4 files. Adds boost filesystem and system library as build dependencies. --- gnuradio-core/src/lib/runtime/gr_preferences.cc | 39 ++++++++++++------------- gnuradio-core/src/lib/runtime/gr_unittests.h | 38 ++++-------------------- 2 files changed, 24 insertions(+), 53 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index 5f7412248..21934677b 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -33,12 +33,17 @@ #include #include - -#ifdef MKDIR_TAKES_ONE_ARG -#define gr_mkdir(pathname, mode) mkdir(pathname) -#else -#define gr_mkdir(pathname, mode) mkdir((pathname), (mode)) -#endif +#include +#include +namespace fs = boost::filesystem; + +static std::string get_home_dir(void){ + #if defined(BOOST_WINDOWS) + return getenv ("APPDATA"); + #else + return getenv ("HOME"); + #endif +} /* * The simplest thing that could possibly work: @@ -48,27 +53,19 @@ static const char * pathname (const char *key) { - static char buf[200]; - snprintf (buf, sizeof (buf), "%s/.gnuradio/prefs/%s", getenv ("HOME"), key); - return buf; + static fs::path path; + path = fs::path(get_home_dir()) / ".gnuradio" / "prefs" / key; + return path.string().c_str(); } static void ensure_dir_path () { - char path[200]; - struct stat statbuf; - - snprintf (path, sizeof (path), "%s/.gnuradio/prefs", getenv ("HOME")); - if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) - return; - - // blindly try to make it // FIXME make this robust. C++ SUCKS! + fs::path path = fs::path(get_home_dir()) / ".gnuradio"; + if (!fs::is_directory(path)) fs::create_directory(path); - snprintf (path, sizeof (path), "%s/.gnuradio", getenv ("HOME")); - gr_mkdir (path, 0750); - snprintf (path, sizeof (path), "%s/.gnuradio/prefs", getenv ("HOME")); - gr_mkdir (path, 0750); + path = path / "prefs"; + if (!fs::is_directory(path)) fs::create_directory(path); } const char * diff --git a/gnuradio-core/src/lib/runtime/gr_unittests.h b/gnuradio-core/src/lib/runtime/gr_unittests.h index 70aa6f294..6e62bc7c1 100644 --- a/gnuradio-core/src/lib/runtime/gr_unittests.h +++ b/gnuradio-core/src/lib/runtime/gr_unittests.h @@ -31,37 +31,11 @@ #include #include +#include +#include -#ifdef MKDIR_TAKES_ONE_ARG -#define gr_mkdir(pathname, mode) mkdir(pathname) -#else -#define gr_mkdir(pathname, mode) mkdir((pathname), (mode)) -#endif - -/* - * Mostly taken from gr_preferences.cc/h - * The simplest thing that could possibly work: - * the key is the filename; the value is the file contents. - */ - -static void -ensure_unittest_path (const char *path) -{ - struct stat statbuf; - if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) - return; - - // blindly try to make it // FIXME make this robust. C++ SUCKS! - gr_mkdir (path, 0750); +static std::string get_unittest_path(const std::string &filename){ + boost::filesystem::path path = boost::filesystem::current_path() / ".unittests"; + if (!boost::filesystem::is_directory(path)) boost::filesystem::create_directory(path); + return (path / filename).string(); } - -static void -get_unittest_path (const char *filename, char *fullpath, size_t pathsize) -{ - char path[200]; - snprintf (path, sizeof(path), "./.unittests"); - snprintf (fullpath, pathsize, "%s/%s", path, filename); - - ensure_unittest_path(path); -} - -- cgit From ebb0f56da62e9ff16928b32cc525f24c93a99e0b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 22 Jan 2011 14:54:20 -0500 Subject: Updating copyright. --- gnuradio-core/src/lib/runtime/gr_preferences.cc | 2 +- gnuradio-core/src/lib/runtime/gr_unittests.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index 21934677b..e9216e4ac 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2003,2010 Free Software Foundation, Inc. + * Copyright 2003,2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/runtime/gr_unittests.h b/gnuradio-core/src/lib/runtime/gr_unittests.h index 6e62bc7c1..59149bb2e 100644 --- a/gnuradio-core/src/lib/runtime/gr_unittests.h +++ b/gnuradio-core/src/lib/runtime/gr_unittests.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2010 Free Software Foundation, Inc. + * Copyright 2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * -- cgit From d65ae4249bf709d0e4062ef2825bef28ff77492a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 22 Jan 2011 22:47:08 -0800 Subject: created gr_sys_paths.h to house functions for getting system paths gr_sys_paths.h has gr_tmp_path() and gr_appdata_path() this replaces gr_tmp_path.h --- gnuradio-core/src/lib/runtime/Makefile.am | 6 +-- gnuradio-core/src/lib/runtime/gr_preferences.cc | 15 ++---- gnuradio-core/src/lib/runtime/gr_sys_paths.cc | 55 ++++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_sys_paths.h | 31 ++++++++++++ gnuradio-core/src/lib/runtime/gr_tmp_path.cc | 52 -------------------- gnuradio-core/src/lib/runtime/gr_tmp_path.h | 31 ------------ .../lib/runtime/gr_vmcircbuf_createfilemapping.cc | 3 +- .../src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc | 4 +- .../src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc | 4 +- 9 files changed, 98 insertions(+), 103 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/gr_sys_paths.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_sys_paths.h delete mode 100644 gnuradio-core/src/lib/runtime/gr_tmp_path.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_tmp_path.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index 3dd2b42f5..eca92e526 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2003,2004,2007,2008,2009,2010 Free Software Foundation, Inc. +# Copyright 2003,2004,2007,2008,2009,2010,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -58,7 +58,7 @@ libruntime_la_SOURCES = \ gr_sync_block.cc \ gr_sync_decimator.cc \ gr_sync_interpolator.cc \ - gr_tmp_path.cc \ + gr_sys_paths.cc \ gr_top_block.cc \ gr_top_block_impl.cc \ gr_tpb_detail.cc \ @@ -121,7 +121,7 @@ grinclude_HEADERS = \ gr_tpb_detail.h \ gr_tpb_thread_body.h \ gr_timer.h \ - gr_tmp_path.h \ + gr_sys_paths.h \ gr_types.h \ gr_unittests.h \ gr_vmcircbuf.h \ diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index 21934677b..c2ca047a8 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2003,2010 Free Software Foundation, Inc. + * Copyright 2003,2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,6 +25,7 @@ #endif #include +#include #include #include #include @@ -37,14 +38,6 @@ #include namespace fs = boost::filesystem; -static std::string get_home_dir(void){ - #if defined(BOOST_WINDOWS) - return getenv ("APPDATA"); - #else - return getenv ("HOME"); - #endif -} - /* * The simplest thing that could possibly work: * the key is the filename; the value is the file contents. @@ -54,14 +47,14 @@ static const char * pathname (const char *key) { static fs::path path; - path = fs::path(get_home_dir()) / ".gnuradio" / "prefs" / key; + path = fs::path(gr_appdata_path()) / ".gnuradio" / "prefs" / key; return path.string().c_str(); } static void ensure_dir_path () { - fs::path path = fs::path(get_home_dir()) / ".gnuradio"; + fs::path path = fs::path(gr_appdata_path()) / ".gnuradio"; if (!fs::is_directory(path)) fs::create_directory(path); path = path / "prefs"; diff --git a/gnuradio-core/src/lib/runtime/gr_sys_paths.cc b/gnuradio-core/src/lib/runtime/gr_sys_paths.cc new file mode 100644 index 000000000..9d10a3ccd --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sys_paths.cc @@ -0,0 +1,55 @@ +/* + * Copyright 2011 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include +#include //getenv +#include //P_tmpdir (maybe) + +const char *gr_tmp_path(){ + const char *path; + + //first case, try TMP environment variable + path = getenv("TMP"); + if (path) return path; + + //second case, try P_tmpdir when its defined + #ifdef P_tmpdir + if (P_tmpdir) return P_tmpdir; + #endif /*P_tmpdir*/ + + //fall-through case, nothing worked + return "/tmp"; +} + +const char *gr_appdata_path(){ + const char *path; + + //first case, try HOME environment variable (unix) + path = getenv("HOME"); + if (path) return path; + + //second case, try APPDATA environment variable (windows) + path = getenv("APPDATA"); + if (path) return path; + + //fall-through case, nothing worked + return gr_tmp_path(); +} diff --git a/gnuradio-core/src/lib/runtime/gr_sys_paths.h b/gnuradio-core/src/lib/runtime/gr_sys_paths.h new file mode 100644 index 000000000..aa8249775 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_sys_paths.h @@ -0,0 +1,31 @@ +/* + * Copyright 2011 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GR_SYS_PATHS_H_ +#define _GR_SYS_PATHS_H_ + +//! directory to create temporary files +const char *gr_tmp_path(); + +//! directory to store application data +const char *gr_appdata_path(); + +#endif /* _GR_SYS_PATHS_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc b/gnuradio-core/src/lib/runtime/gr_tmp_path.cc deleted file mode 100644 index 1f0c830cd..000000000 --- a/gnuradio-core/src/lib/runtime/gr_tmp_path.cc +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include - -const char * -gr_tmp_path () -{ - static char *pp = 0; - - if (pp) - return pp; - - char *s = getenv ("TMP"); - if (s){ - pp = strdup (s); - return pp; - } - -#ifdef P_tmpdir - if (P_tmpdir){ - pp = strdup (P_tmpdir); - return pp; - } -#endif - - pp = strdup ("/tmp"); - return pp; -} - diff --git a/gnuradio-core/src/lib/runtime/gr_tmp_path.h b/gnuradio-core/src/lib/runtime/gr_tmp_path.h deleted file mode 100644 index 3d02043c7..000000000 --- a/gnuradio-core/src/lib/runtime/gr_tmp_path.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _GR_TMP_PATH_H_ -#define _GR_TMP_PATH_H_ - -/*! - * \brief return directory portion of pathname used for temporary files. - */ -const char *gr_tmp_path (); - -#endif /* _GR_TMP_PATH_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc index 65fe0c488..42c459484 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2003,2005 Free Software Foundation, Inc. + * Copyright 2003,2005,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -36,7 +36,6 @@ #include #include #include -#include #include #ifdef HAVE_CREATEFILEMAPPING diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc index 3017036ef..4f7ae39cd 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2003 Free Software Foundation, Inc. + * Copyright 2003,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -37,7 +37,7 @@ #include #include #include -#include +#include gr_vmcircbuf_mmap_shm_open::gr_vmcircbuf_mmap_shm_open (int size) diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc index faae4b396..ee8b0c485 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2003 Free Software Foundation, Inc. + * Copyright 2003,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -39,7 +39,7 @@ #include #include #include -#include +#include gr_vmcircbuf_mmap_tmpfile::gr_vmcircbuf_mmap_tmpfile (int size) : gr_vmcircbuf (size) -- cgit From aedfa8ec254f1def125167a77a50bb0eec4ab00c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 24 Jan 2011 12:23:58 -0800 Subject: gr_flowgraph.cc explicit include of Added explicit include of , which was implicitly included by . Affects platforms where vector does not automatically pull in iterator. --- gnuradio-core/src/lib/runtime/gr_flowgraph.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc index 27f6257cc..0d3bbb011 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -28,6 +28,7 @@ #include #include #include +#include #define GR_FLOWGRAPH_DEBUG 0 -- cgit From e73c25fb9226029f0e50052b1ffacedb3a78622b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 24 Jan 2011 00:34:28 -0800 Subject: gruel thread simplification: Removed get_new_timeout from thread.h (usrp2_vrt carryover) Basically it was created because of a misunderstanding of the time types; and its only ever called once. This also removes thread.cc Call posix_time::milliseconds in usrp2 control.cc. Notice that it passes a time_duration rather than a ptime (aka system time). Added #include to gr_buffer.h. It turns out that boost posix_time.hpp implicitly included the deque header which was missing from gr_buffer.h Replaced the include for thread.hpp with only the includes for the boost thread types mentioned in gruel/thread.h. Also, making use of the scoped_lock typedef that comes with boost thread locks. boost 3.5 safe. --- gnuradio-core/src/lib/runtime/gr_buffer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index aa26f1e09..e5725d386 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009,2010 Free Software Foundation, Inc. + * Copyright 2004,2009,2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,6 +27,7 @@ #include #include #include +#include class gr_vmcircbuf; -- cgit From 64dac6a1f62fb8484e879f0d20ee60bc02da179c Mon Sep 17 00:00:00 2001 From: Don Ward Date: Fri, 25 Mar 2011 11:53:04 -0400 Subject: Fixing missing include files and various other patches for Windows build issues. --- gnuradio-core/src/lib/runtime/gr_error_handler.cc | 1 - gnuradio-core/src/lib/runtime/gr_error_handler.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.cc b/gnuradio-core/src/lib/runtime/gr_error_handler.cc index 6dbb0a5d2..4b4cdacef 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.cc @@ -48,7 +48,6 @@ #include #include #include -#include #ifdef HAVE_IO_H #include diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.h b/gnuradio-core/src/lib/runtime/gr_error_handler.h index 530a2c23c..aedb6f41f 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.h @@ -45,6 +45,7 @@ #include #include +#include // for FILE /*! * \brief abstract error handler -- cgit From a111deb45559296d6eadded9226df68af21c0477 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 16 Mar 2011 14:51:58 -0700 Subject: runtime: changes to block headers to allow pure virtual sub-classes (interfaces) --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 2 ++ gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_sync_block.h | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index ce7a1aa1d..3b0cd51dd 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -73,6 +73,8 @@ protected: long d_unique_id; vcolor d_color; + gr_basic_block(void){} //allows pure virtual interface sub-classes + //! Protected constructor prevents instantiation by non-derived classes gr_basic_block(const std::string &name, gr_io_signature_sptr input_signature, diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index ad7fa9555..fc22f9ea8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -236,7 +236,7 @@ class gr_block : public gr_basic_block { tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream protected: - + gr_block (void){} //allows pure virtual interface sub-classes gr_block (const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index 3a5d89d19..c5a6a50f1 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -34,7 +34,7 @@ class gr_sync_block : public gr_block { protected: - + gr_sync_block (void){} //allows pure virtual interface sub-classes gr_sync_block (const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); -- cgit From add65c9ceae949592a9719175575f88da217790a Mon Sep 17 00:00:00 2001 From: Don Ward Date: Sat, 11 Jun 2011 14:46:18 -0700 Subject: Allow disabling shm vmcircbuf tests at configure time --- gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc index abcf5b2a6..3b8a6e617 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc @@ -100,8 +100,10 @@ gr_vmcircbuf_sysconfig::all_factories () std::vector result; result.push_back (gr_vmcircbuf_createfilemapping_factory::singleton ()); +#ifdef TRY_SHM_VMCIRCBUF result.push_back (gr_vmcircbuf_sysv_shm_factory::singleton ()); result.push_back (gr_vmcircbuf_mmap_shm_open_factory::singleton ()); +#endif result.push_back (gr_vmcircbuf_mmap_tmpfile_factory::singleton ()); return result; -- cgit From 2ed243a36f9f19d10a552a350f856726e8e64b30 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 12:20:40 -0700 Subject: gr: replaced uses of snprintf with boost format in common code build by MSVC --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 6 +++--- gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc | 25 +++++++++++----------- .../lib/runtime/gr_vmcircbuf_createfilemapping.cc | 13 ++++++----- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index a8d0bc1c8..b3f987f72 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -165,9 +166,8 @@ gr_block_executor::gr_block_executor (gr_block_sptr block) : d_block(block), d_log(0) { if (ENABLE_LOGGING){ - char name[100]; - snprintf(name, sizeof(name), "sst-%03d.log", which_scheduler++); - d_log = new std::ofstream(name); + std::string name = str(boost::format("sst-%03d.log") % which_scheduler++); + d_log = new std::ofstream(name.c_str()); std::unitbuf(*d_log); // make it unbuffered... *d_log << "gr_block_executor: " << d_block << std::endl; diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc index 3b8a6e617..7138605c9 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc @@ -30,6 +30,8 @@ #include #include #include +#include +#include // all the factories we know about #include @@ -130,7 +132,7 @@ init_buffer (gr_vmcircbuf *c, int counter, int size) } static bool -check_mapping (gr_vmcircbuf *c, int counter, int size, char *msg, bool verbose) +check_mapping (gr_vmcircbuf *c, int counter, int size, const char *msg, bool verbose) { bool ok = true; @@ -163,28 +165,28 @@ check_mapping (gr_vmcircbuf *c, int counter, int size, char *msg, bool verbose) return ok; } -static char * +static const char * memsize (int size) { - static char buf[100]; + static std::string buf; if (size >= (1 << 20)){ - snprintf (buf, sizeof (buf), "%dMB", size / (1 << 20)); + buf = str(boost::format("%dMB") % (size / (1 << 20))); } else if (size >= (1 << 10)){ - snprintf (buf, sizeof (buf), "%dKB", size / (1 << 10)); + buf = str(boost::format("%dKB") % (size / (1 << 10))); } else { - snprintf (buf, sizeof (buf), "%d", size); + buf = str(boost::format("%d") % size); } - return buf; + return buf.c_str(); } static bool test_a_bunch (gr_vmcircbuf_factory *factory, int n, int size, int *start_ptr, bool verbose) { bool ok = true; - int counter[n]; - gr_vmcircbuf *c[n]; + std::vector counter(n); + std::vector c(n); int cum_size = 0; for (int i = 0; i < n; i++){ @@ -202,9 +204,8 @@ test_a_bunch (gr_vmcircbuf_factory *factory, int n, int size, int *start_ptr, bo } for (int i = 0; i < n; i++){ - char msg[100]; - snprintf (msg, sizeof (msg), "test_a_bunch_%dx%s[%d]", n, memsize (size), i); - ok &= check_mapping (c[i], counter[i], size, msg, verbose); + std::string msg = str(boost::format("test_a_bunch_%dx%s[%d]") % n % memsize (size) % i); + ok &= check_mapping (c[i], counter[i], size, msg.c_str(), verbose); } for (int i = 0; i < n; i++){ diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc index 42c459484..1b4d9700a 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.cc @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef HAVE_CREATEFILEMAPPING // Print Windows error (could/should be global?) @@ -72,23 +73,21 @@ gr_vmcircbuf_createfilemapping::gr_vmcircbuf_createfilemapping (int size) throw std::runtime_error ("gr_vmcircbuf_createfilemapping"); } - char seg_name[1024]; - snprintf (seg_name, sizeof (seg_name), "/gnuradio-%d-%d", getpid (), s_seg_counter); + std::string seg_name = str(boost::format("/gnuradio-%d-%d") % getpid () % s_seg_counter); d_handle = CreateFileMapping(INVALID_HANDLE_VALUE, // use paging file NULL, // default security PAGE_READWRITE, // read/write access 0, // max. object size size, // buffer size - seg_name); // name of mapping object + seg_name.c_str()); // name of mapping object s_seg_counter++; if (d_handle == NULL || d_handle == INVALID_HANDLE_VALUE){ - char msg[1024]; - snprintf( msg, sizeof(msg), - "gr_vmcircbuf_mmap_createfilemapping: CreateFileMapping [%s]", + std::string msg = str(boost::format( + "gr_vmcircbuf_mmap_createfilemapping: CreateFileMapping [%s]") % seg_name ); - werror( msg, GetLastError() ); + werror((char *) msg.c_str(), GetLastError() ); throw std::runtime_error ("gr_vmcircbuf_mmap_createfilemapping"); } -- cgit From ed34b5a0c7daea43bfac330350bc0c7334b36c77 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 18:06:14 -0700 Subject: gr: replaced uses of snprintf with boost format in common code build by MSVC --- gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc index 7f1b40641..ae04e4a65 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -57,9 +58,8 @@ gr_single_threaded_scheduler::gr_single_threaded_scheduler ( : d_blocks (blocks), d_enabled (true), d_log(0) { if (ENABLE_LOGGING){ - char name[100]; - snprintf(name, sizeof(name), "sst-%d.log", which_scheduler++); - d_log = new std::ofstream(name); + std::string name = str(boost::format("sst-%d.log") % which_scheduler++); + d_log = new std::ofstream(name.c_str()); *d_log << "gr_single_threaded_scheduler: " << d_blocks.size () << " blocks\n"; -- cgit From f914499f4a96fe69ab9cd8dba48f8e3bfc7a54e5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 18:38:36 -0700 Subject: core: API declaration macros for core class and function symbols --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 5 +++-- gnuradio-core/src/lib/runtime/gr_block.h | 5 +++-- gnuradio-core/src/lib/runtime/gr_block_detail.h | 11 ++++++----- gnuradio-core/src/lib/runtime/gr_block_executor.h | 3 ++- gnuradio-core/src/lib/runtime/gr_buffer.h | 19 ++++++++++--------- gnuradio-core/src/lib/runtime/gr_dispatcher.h | 9 +++++---- gnuradio-core/src/lib/runtime/gr_error_handler.h | 7 ++++--- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 7 ++++--- gnuradio-core/src/lib/runtime/gr_flowgraph.h | 11 ++++++----- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 7 ++++--- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h | 3 ++- gnuradio-core/src/lib/runtime/gr_io_signature.h | 13 +++++++------ gnuradio-core/src/lib/runtime/gr_local_sighandler.h | 5 +++-- gnuradio-core/src/lib/runtime/gr_message.h | 13 +++++++------ gnuradio-core/src/lib/runtime/gr_msg_accepter.h | 3 ++- gnuradio-core/src/lib/runtime/gr_msg_handler.h | 3 ++- gnuradio-core/src/lib/runtime/gr_msg_queue.h | 5 +++-- gnuradio-core/src/lib/runtime/gr_pagesize.h | 6 ++++-- gnuradio-core/src/lib/runtime/gr_preferences.h | 6 ++++-- gnuradio-core/src/lib/runtime/gr_realtime.h | 3 ++- gnuradio-core/src/lib/runtime/gr_runtime_types.h | 1 + gnuradio-core/src/lib/runtime/gr_scheduler.h | 3 ++- gnuradio-core/src/lib/runtime/gr_scheduler_sts.h | 3 ++- gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h | 3 ++- gnuradio-core/src/lib/runtime/gr_select_handler.h | 3 ++- .../src/lib/runtime/gr_single_threaded_scheduler.h | 7 ++++--- gnuradio-core/src/lib/runtime/gr_sptr_magic.h | 3 ++- gnuradio-core/src/lib/runtime/gr_sync_block.h | 3 ++- gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 3 ++- gnuradio-core/src/lib/runtime/gr_sync_interpolator.h | 3 ++- gnuradio-core/src/lib/runtime/gr_sys_paths.h | 6 ++++-- gnuradio-core/src/lib/runtime/gr_timer.h | 9 +++++---- gnuradio-core/src/lib/runtime/gr_top_block.h | 7 ++++--- gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 3 ++- gnuradio-core/src/lib/runtime/gr_tpb_detail.h | 3 ++- gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h | 3 ++- gnuradio-core/src/lib/runtime/gr_types.h | 1 + gnuradio-core/src/lib/runtime/gr_unittests.h | 2 ++ gnuradio-core/src/lib/runtime/gr_vmcircbuf.h | 7 ++++--- .../src/lib/runtime/gr_vmcircbuf_createfilemapping.h | 5 +++-- .../src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h | 5 +++-- .../src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h | 5 +++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h | 5 +++-- gnuradio-core/src/lib/runtime/qa_runtime.h | 3 ++- 44 files changed, 144 insertions(+), 96 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 3b0cd51dd..2adca8ccb 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_BASIC_BLOCK_H #define INCLUDED_GR_BASIC_BLOCK_H +#include #include #include #include @@ -41,7 +42,7 @@ * signal processing functions. */ -class gr_basic_block : public gr_msg_accepter, public boost::enable_shared_from_this +class GR_CORE_API gr_basic_block : public gr_msg_accepter, public boost::enable_shared_from_this { typedef boost::function msg_handler_t; @@ -158,7 +159,7 @@ inline bool operator<(gr_basic_block_sptr lhs, gr_basic_block_sptr rhs) typedef std::vector gr_basic_block_vector_t; typedef std::vector::iterator gr_basic_block_viter_t; -long gr_basic_block_ncurrently_allocated(); +GR_CORE_API long gr_basic_block_ncurrently_allocated(); inline std::ostream &operator << (std::ostream &os, gr_basic_block_sptr basic_block) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index fc22f9ea8..2453e97b8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_BLOCK_H #define INCLUDED_GR_BLOCK_H +#include #include /*! @@ -53,7 +54,7 @@ * It reads the input items and writes the output items. */ -class gr_block : public gr_basic_block { +class GR_CORE_API gr_block : public gr_basic_block { public: @@ -300,7 +301,7 @@ class gr_block : public gr_basic_block { const pmt::pmt_t &key); // These are really only for internal use, but leaving them public avoids - // having to work up an ever-varying list of friends + // having to work up an ever-varying list of friend GR_CORE_APIs public: gr_block_detail_sptr detail () const { return d_detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index d7ec3b136..633da1b0c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_BLOCK_DETAIL_H #define INCLUDED_GR_BLOCK_DETAIL_H +#include #include #include #include @@ -36,7 +37,7 @@ * 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 { +class GR_CORE_API gr_block_detail { public: ~gr_block_detail (); @@ -172,16 +173,16 @@ class gr_block_detail { gr_block_detail (unsigned int ninputs, unsigned int noutputs); - friend class gr_tpb_detail; + friend struct gr_tpb_detail; - friend gr_block_detail_sptr + friend GR_CORE_API gr_block_detail_sptr gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); }; -gr_block_detail_sptr +GR_CORE_API gr_block_detail_sptr gr_make_block_detail (unsigned int ninputs, unsigned int noutputs); -long +GR_CORE_API long gr_block_detail_ncurrently_allocated (); #endif /* INCLUDED_GR_BLOCK_DETAIL_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h index 77ace5522..cd93212e1 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.h +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_BLOCK_EXECUTOR_H #define INCLUDED_GR_BLOCK_EXECUTOR_H +#include #include #include #include @@ -36,7 +37,7 @@ * \ingroup internal */ -class gr_block_executor { +class GR_CORE_API gr_block_executor { protected: gr_block_sptr d_block; // The block we're trying to run std::ofstream *d_log; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index e5725d386..e7c0a06a5 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_BUFFER_H #define INCLUDED_GR_BUFFER_H +#include #include #include #include @@ -42,14 +43,14 @@ class gr_vmcircbuf; * \param sizeof_item is the size of an item in bytes. * \param link is the block that writes to this buffer. */ -gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr link=gr_block_sptr()); +GR_CORE_API gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr link=gr_block_sptr()); /*! * \brief Single writer, multiple reader fifo. * \ingroup internal */ -class gr_buffer { +class GR_CORE_API gr_buffer { public: virtual ~gr_buffer (); @@ -115,8 +116,8 @@ class gr_buffer { private: friend class gr_buffer_reader; - friend gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr link); - friend gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link); + friend GR_CORE_API gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr link); + friend GR_CORE_API gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link); protected: char *d_base; // base address of buffer @@ -192,11 +193,11 @@ class gr_buffer { * \param nzero_preload -- number of zero items to "preload" into buffer. * \param link is the block that reads from the buffer using this gr_buffer_reader. */ -gr_buffer_reader_sptr +GR_CORE_API gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link=gr_block_sptr()); //! returns # of gr_buffers currently allocated -long gr_buffer_ncurrently_allocated (); +GR_CORE_API long gr_buffer_ncurrently_allocated (); // --------------------------------------------------------------------------- @@ -206,7 +207,7 @@ long gr_buffer_ncurrently_allocated (); * \ingroup internal */ -class gr_buffer_reader { +class GR_CORE_API gr_buffer_reader { public: ~gr_buffer_reader (); @@ -276,7 +277,7 @@ class gr_buffer_reader { private: friend class gr_buffer; - friend gr_buffer_reader_sptr + friend GR_CORE_API gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link); @@ -290,7 +291,7 @@ class gr_buffer_reader { }; //! returns # of gr_buffer_readers currently allocated -long gr_buffer_reader_ncurrently_allocated (); +GR_CORE_API long gr_buffer_reader_ncurrently_allocated (); #endif /* INCLUDED_GR_BUFFER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.h b/gnuradio-core/src/lib/runtime/gr_dispatcher.h index 34f825102..735974766 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.h +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.h @@ -23,14 +23,15 @@ #ifndef INCLUDED_GR_DISPATCHER_H #define INCLUDED_GR_DISPATCHER_H +#include #include #include class gr_dispatcher; typedef boost::shared_ptr gr_dispatcher_sptr; -gr_dispatcher_sptr gr_dispatcher_singleton(); -gr_dispatcher_sptr gr_make_dispatcher(); +GR_CORE_API gr_dispatcher_sptr gr_dispatcher_singleton(); +GR_CORE_API gr_dispatcher_sptr gr_make_dispatcher(); /*! * \brief invoke callbacks based on select. @@ -38,10 +39,10 @@ gr_dispatcher_sptr gr_make_dispatcher(); * * \sa gr_select_handler */ -class gr_dispatcher +class GR_CORE_API gr_dispatcher { gr_dispatcher(); - friend gr_dispatcher_sptr gr_make_dispatcher(); + friend GR_CORE_API gr_dispatcher_sptr gr_make_dispatcher(); std::vector d_handler; int d_max_index; diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.h b/gnuradio-core/src/lib/runtime/gr_error_handler.h index aedb6f41f..4c30791f2 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.h @@ -43,6 +43,7 @@ #ifndef INCLUDED_GR_ERROR_HANDLER_H #define INCLUDED_GR_ERROR_HANDLER_H +#include #include #include #include // for FILE @@ -51,7 +52,7 @@ * \brief abstract error handler * \ingroup base */ -class gr_error_handler { +class GR_CORE_API gr_error_handler { public: enum seriousness { ERR_DEBUG = 0x00000000, @@ -90,7 +91,7 @@ protected: }; -class gr_base_error_handler : public gr_error_handler { +class GR_CORE_API gr_base_error_handler : public gr_error_handler { int d_nwarnings; int d_nerrors; @@ -102,7 +103,7 @@ public: void count_error(seriousness s); }; -class gr_file_error_handler : public gr_base_error_handler { +class GR_CORE_API gr_file_error_handler : public gr_base_error_handler { FILE *d_file; int d_fd; public: diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h index 8e9834337..2cc883686 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h @@ -23,22 +23,23 @@ #ifndef INCLUDED_GR_FLAT_FLOWGRAPH_H #define INCLUDED_GR_FLAT_FLOWGRAPH_H +#include #include #include // Create a shared pointer to a heap allocated gr_flat_flowgraph // (types defined in gr_runtime_types.h) -gr_flat_flowgraph_sptr gr_make_flat_flowgraph(); +GR_CORE_API gr_flat_flowgraph_sptr gr_make_flat_flowgraph(); /*! *\brief Class specializing gr_flat_flowgraph that has all nodes * as gr_blocks, with no hierarchy * \ingroup internal */ -class gr_flat_flowgraph : public gr_flowgraph +class GR_CORE_API gr_flat_flowgraph : public gr_flowgraph { public: - friend gr_flat_flowgraph_sptr gr_make_flat_flowgraph(); + friend GR_CORE_API gr_flat_flowgraph_sptr gr_make_flat_flowgraph(); // Destruct an arbitrary gr_flat_flowgraph ~gr_flat_flowgraph(); diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flowgraph.h index 8e988506b..8f9a8ba71 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_FLOWGRAPH_H #define INCLUDED_GR_FLOWGRAPH_H +#include #include #include @@ -30,7 +31,7 @@ * \brief Class representing a specific input or output graph endpoint * \ingroup internal */ -class gr_endpoint +class GR_CORE_API gr_endpoint { private: gr_basic_block_sptr d_basic_block; @@ -59,7 +60,7 @@ typedef std::vector::iterator gr_endpoint_viter_t; *\brief Class representing a connection between to graph endpoints * */ -class gr_edge +class GR_CORE_API gr_edge { public: gr_edge() : d_src(), d_dst() { }; @@ -81,16 +82,16 @@ typedef std::vector::iterator gr_edge_viter_t; // Create a shared pointer to a heap allocated flowgraph // (types defined in gr_runtime_types.h) -gr_flowgraph_sptr gr_make_flowgraph(); +GR_CORE_API gr_flowgraph_sptr gr_make_flowgraph(); /*! * \brief Class representing a directed, acyclic graph of basic blocks * \ingroup internal */ -class gr_flowgraph +class GR_CORE_API gr_flowgraph { public: - friend gr_flowgraph_sptr gr_make_flowgraph(); + friend GR_CORE_API gr_flowgraph_sptr gr_make_flowgraph(); // Destruct an arbitrary flowgraph ~gr_flowgraph(); diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 0a40c36b7..8687b7d99 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -22,13 +22,14 @@ #ifndef INCLUDED_GR_HIER_BLOCK2_H #define INCLUDED_GR_HIER_BLOCK2_H +#include #include /*! * \brief public constructor for gr_hier_block2 */ -gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, +GR_CORE_API gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); @@ -40,11 +41,11 @@ class gr_hier_block2_detail; * \ingroup base_blk * */ -class gr_hier_block2 : public gr_basic_block +class GR_CORE_API gr_hier_block2 : public gr_basic_block { private: friend class gr_hier_block2_detail; - friend gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, + friend GR_CORE_API gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index 6f5384e5a..5a77d6a03 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -22,6 +22,7 @@ #ifndef INCLUDED_GR_HIER_BLOCK2_DETAIL_H #define INCLUDED_GR_HIER_BLOCK2_DETAIL_H +#include #include #include #include @@ -29,7 +30,7 @@ /*! * \ingroup internal */ -class gr_hier_block2_detail : boost::noncopyable +class GR_CORE_API gr_hier_block2_detail : boost::noncopyable { public: gr_hier_block2_detail(gr_hier_block2 *owner); diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index 5d194cf55..11c6b7f13 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_IO_SIGNATURE_H #define INCLUDED_IO_SIGNATURE_H +#include #include /*! @@ -33,7 +34,7 @@ * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) * \param sizeof_stream_item specify the size of the items in each stream */ -gr_io_signature_sptr +GR_CORE_API gr_io_signature_sptr gr_make_io_signature(int min_streams, int max_streams, int sizeof_stream_item); @@ -45,7 +46,7 @@ gr_make_io_signature(int min_streams, int max_streams, * \param sizeof_stream_item1 specify the size of the items in the first stream * \param sizeof_stream_item2 specify the size of the items in the second and subsequent streams */ -gr_io_signature_sptr +GR_CORE_API gr_io_signature_sptr gr_make_io_signature2(int min_streams, int max_streams, int sizeof_stream_item1, int sizeof_stream_item2 @@ -60,7 +61,7 @@ gr_make_io_signature2(int min_streams, int max_streams, * \param sizeof_stream_item2 specify the size of the items in the second stream * \param sizeof_stream_item3 specify the size of the items in the third and subsequent streams */ -gr_io_signature_sptr +GR_CORE_API gr_io_signature_sptr gr_make_io_signature3(int min_streams, int max_streams, int sizeof_stream_item1, int sizeof_stream_item2, @@ -78,7 +79,7 @@ gr_make_io_signature3(int min_streams, int max_streams, * value of the last entry in sizeof_stream_items is used for the missing values. * sizeof_stream_items must contain at least 1 entry. */ -gr_io_signature_sptr +GR_CORE_API gr_io_signature_sptr gr_make_io_signaturev(int min_streams, int max_streams, const std::vector &sizeof_stream_items); @@ -87,7 +88,7 @@ gr_make_io_signaturev(int min_streams, int max_streams, * \brief i/o signature for input and output ports. * \brief misc */ -class gr_io_signature { +class GR_CORE_API gr_io_signature { int d_min_streams; int d_max_streams; std::vector d_sizeof_stream_item; @@ -95,7 +96,7 @@ class gr_io_signature { gr_io_signature(int min_streams, int max_streams, const std::vector &sizeof_stream_items); - friend gr_io_signature_sptr + friend GR_CORE_API gr_io_signature_sptr gr_make_io_signaturev(int min_streams, int max_streams, const std::vector &sizeof_stream_items); diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h index 6b60cf09a..9e4eacc47 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h @@ -27,6 +27,7 @@ #include #endif +#include #include /*! @@ -36,7 +37,7 @@ * Constructor installs new handler, destructor reinstalls * original value. */ -class gr_local_sighandler { +class GR_CORE_API gr_local_sighandler { int d_signum; #ifdef HAVE_SIGACTION struct sigaction d_old_action; @@ -52,7 +53,7 @@ public: /*! * \brief Representation of signal. */ -class gr_signal +class GR_CORE_API gr_signal { int d_signum; public: diff --git a/gnuradio-core/src/lib/runtime/gr_message.h b/gnuradio-core/src/lib/runtime/gr_message.h index 179f7d9bc..ead002616 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.h +++ b/gnuradio-core/src/lib/runtime/gr_message.h @@ -22,6 +22,7 @@ #ifndef INCLUDED_GR_MESSAGE_H #define INCLUDED_GR_MESSAGE_H +#include #include #include @@ -31,10 +32,10 @@ typedef boost::shared_ptr gr_message_sptr; /*! * \brief public constructor for gr_message */ -gr_message_sptr +GR_CORE_API gr_message_sptr gr_make_message(long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0); -gr_message_sptr +GR_CORE_API gr_message_sptr gr_make_message_from_string(const std::string s, long type = 0, double arg1 = 0, double arg2 = 0); /*! @@ -44,7 +45,7 @@ gr_make_message_from_string(const std::string s, long type = 0, double arg1 = 0, * The ideas and method names for adjustable message length were * lifted from the click modular router "Packet" class. */ -class gr_message { +class GR_CORE_API gr_message { gr_message_sptr d_next; // link field for msg queue long d_type; // type of the message double d_arg1; // optional arg1 @@ -57,10 +58,10 @@ class gr_message { gr_message (long type, double arg1, double arg2, size_t length); - friend gr_message_sptr + friend GR_CORE_API gr_message_sptr gr_make_message (long type, double arg1, double arg2, size_t length); - friend gr_message_sptr + friend GR_CORE_API gr_message_sptr gr_make_message_from_string (const std::string s, long type, double arg1, double arg2); friend class gr_msg_queue; @@ -85,6 +86,6 @@ public: }; -long gr_message_ncurrently_allocated (); +GR_CORE_API long gr_message_ncurrently_allocated (); #endif /* INCLUDED_GR_MESSAGE_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h index 79a631f3a..4aec127a9 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h @@ -22,6 +22,7 @@ #ifndef INCLUDED_GR_MSG_ACCEPTER_H #define INCLUDED_GR_MSG_ACCEPTER_H +#include #include #include @@ -29,7 +30,7 @@ * \brief Accepts messages and inserts them into a message queue, then notifies * subclass gr_basic_block there is a message pending. */ -class gr_msg_accepter : public gruel::msg_accepter +class GR_CORE_API gr_msg_accepter : public gruel::msg_accepter { public: gr_msg_accepter(); diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.h b/gnuradio-core/src/lib/runtime/gr_msg_handler.h index 774dce73e..ebe3ffe37 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.h @@ -22,6 +22,7 @@ #ifndef INCLUDED_GR_MSG_HANDLER_H #define INCLUDED_GR_MSG_HANDLER_H +#include #include class gr_msg_handler; @@ -31,7 +32,7 @@ typedef boost::shared_ptr gr_msg_handler_sptr; * \brief abstract class of message handlers * \ingroup base */ -class gr_msg_handler { +class GR_CORE_API gr_msg_handler { public: virtual ~gr_msg_handler (); diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.h b/gnuradio-core/src/lib/runtime/gr_msg_queue.h index 477b1ddf1..bf7b89882 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.h @@ -22,19 +22,20 @@ #ifndef INCLUDED_GR_MSG_QUEUE_H #define INCLUDED_GR_MSG_QUEUE_H +#include #include #include class gr_msg_queue; typedef boost::shared_ptr gr_msg_queue_sptr; -gr_msg_queue_sptr gr_make_msg_queue(unsigned int limit=0); +GR_CORE_API gr_msg_queue_sptr gr_make_msg_queue(unsigned int limit=0); /*! * \brief thread-safe message queue * \ingroup misc */ -class gr_msg_queue : public gr_msg_handler { +class GR_CORE_API gr_msg_queue : public gr_msg_handler { gruel::mutex d_mutex; gruel::condition_variable d_not_empty; diff --git a/gnuradio-core/src/lib/runtime/gr_pagesize.h b/gnuradio-core/src/lib/runtime/gr_pagesize.h index 3c1b8eb6b..60dad42c9 100644 --- a/gnuradio-core/src/lib/runtime/gr_pagesize.h +++ b/gnuradio-core/src/lib/runtime/gr_pagesize.h @@ -22,11 +22,13 @@ #ifndef _GR_PAGESIZE_H_ #define _GR_PAGESIZE_H_ +#include + /*! * \brief return the page size in bytes */ -int gr_pagesize (); +GR_CORE_API int gr_pagesize (); -#endif /* _GR_PAGESIZE_H_ */ +#endif /* _GR_PAGESIZE_H_ */ \ No newline at end of file diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.h b/gnuradio-core/src/lib/runtime/gr_preferences.h index 7f2a25e6b..ab4dc0cb0 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.h +++ b/gnuradio-core/src/lib/runtime/gr_preferences.h @@ -23,10 +23,12 @@ #ifndef _GR_PREFERENCES_H_ #define _GR_PREFERENCES_H_ -class gr_preferences { +#include + +class GR_CORE_API gr_preferences { public: static const char *get (const char *key); static void set (const char *key, const char *value); }; -#endif /* _GR_PREFERENCES_H_ */ +#endif /* _GR_PREFERENCES_H_ */ \ No newline at end of file diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.h b/gnuradio-core/src/lib/runtime/gr_realtime.h index 830c201d7..58db83086 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.h +++ b/gnuradio-core/src/lib/runtime/gr_realtime.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_REALTIME_H #define INCLUDED_GR_REALTIME_H +#include #include typedef gruel::rt_status_t gr_rt_status_t; @@ -31,6 +32,6 @@ typedef gruel::rt_status_t gr_rt_status_t; * \brief If possible, enable high-priority "real time" scheduling. * \ingroup misc */ -gr_rt_status_t gr_enable_realtime_scheduling(); +GR_CORE_API gr_rt_status_t gr_enable_realtime_scheduling(); #endif /* INCLUDED_GR_REALTIME_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_types.h b/gnuradio-core/src/lib/runtime/gr_runtime_types.h index 74d2614a8..98f08b417 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_types.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_types.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_RUNTIME_TYPES_H #define INCLUDED_GR_RUNTIME_TYPES_H +#include #include /* diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler.h b/gnuradio-core/src/lib/runtime/gr_scheduler.h index 13bc1ff14..4e97b5881 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler.h @@ -22,6 +22,7 @@ #ifndef INCLUDED_GR_SCHEDULER_H #define INCLUDED_GR_SCHEDULER_H +#include #include #include #include @@ -36,7 +37,7 @@ typedef boost::shared_ptr gr_scheduler_sptr; * * Preconditions: details, buffers and buffer readers have been assigned. */ -class gr_scheduler : boost::noncopyable +class GR_CORE_API gr_scheduler : boost::noncopyable { public: diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h index 4cf835156..9b73b68c1 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h @@ -21,13 +21,14 @@ #ifndef INCLUDED_GR_SCHEDULER_STS_H #define INCLUDED_GR_SCHEDULER_STS_H +#include #include #include /*! * \brief Concrete scheduler that uses the single_threaded_scheduler */ -class gr_scheduler_sts : public gr_scheduler +class GR_CORE_API gr_scheduler_sts : public gr_scheduler { gruel::thread_group d_threads; diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h index 16a0c0204..f97ab2e7f 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h @@ -21,13 +21,14 @@ #ifndef INCLUDED_GR_SCHEDULER_TPB_H #define INCLUDED_GR_SCHEDULER_TPB_H +#include #include #include /*! * \brief Concrete scheduler that uses a kernel thread-per-block */ -class gr_scheduler_tpb : public gr_scheduler +class GR_CORE_API gr_scheduler_tpb : public gr_scheduler { gruel::thread_group d_threads; diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.h b/gnuradio-core/src/lib/runtime/gr_select_handler.h index c3808995b..532707a02 100644 --- a/gnuradio-core/src/lib/runtime/gr_select_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_SELECT_HANDLER_H #define INCLUDED_GR_SELECT_HANDLER_H +#include #include class gr_select_handler; @@ -35,7 +36,7 @@ typedef boost::shared_ptr gr_select_handler_sptr; * * \sa gr_dispatcher */ -class gr_select_handler +class GR_CORE_API gr_select_handler { int d_fd; diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h index 060d3017d..17f4a1c54 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_SINGLE_THREADED_SCHEDULER_H #define INCLUDED_GR_SINGLE_THREADED_SCHEDULER_H +#include #include #include @@ -35,7 +36,7 @@ typedef boost::shared_ptr gr_single_threaded_sched * \ingroup internal */ -class gr_single_threaded_scheduler { +class GR_CORE_API gr_single_threaded_scheduler { public: ~gr_single_threaded_scheduler (); @@ -51,11 +52,11 @@ class gr_single_threaded_scheduler { void main_loop (); - friend gr_single_threaded_scheduler_sptr + friend GR_CORE_API gr_single_threaded_scheduler_sptr gr_make_single_threaded_scheduler (const std::vector &blocks); }; -gr_single_threaded_scheduler_sptr +GR_CORE_API gr_single_threaded_scheduler_sptr gr_make_single_threaded_scheduler (const std::vector &blocks); #endif /* INCLUDED_GR_SINGLE_THREADED_SCHEDULER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.h b/gnuradio-core/src/lib/runtime/gr_sptr_magic.h index 872374ab6..4b7f9899d 100644 --- a/gnuradio-core/src/lib/runtime/gr_sptr_magic.h +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.h @@ -21,6 +21,7 @@ #ifndef INCLUDED_GR_SPTR_MAGIC_H #define INCLUDED_GR_SPTR_MAGIC_H +#include #include class gr_basic_block; @@ -30,7 +31,7 @@ namespace gnuradio { namespace detail { - class sptr_magic { + class GR_CORE_API sptr_magic { public: static boost::shared_ptr fetch_initial_sptr(gr_basic_block *p); static void create_and_stash_initial_sptr(gr_hier_block2 *p); diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index c5a6a50f1..808c1c18a 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_SYNC_BLOCK_H #define INCLUDED_GR_SYNC_BLOCK_H +#include #include /*! @@ -31,7 +32,7 @@ * * Override work to provide the signal processing implementation. */ -class gr_sync_block : public gr_block +class GR_CORE_API gr_sync_block : public gr_block { protected: gr_sync_block (void){} //allows pure virtual interface sub-classes diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h index 12cd54195..b2ed3c4fe 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_SYNC_DECIMATOR_H #define INCLUDED_GR_SYNC_DECIMATOR_H +#include #include /*! @@ -31,7 +32,7 @@ * * Override work to provide the signal processing implementation. */ -class gr_sync_decimator : public gr_sync_block +class GR_CORE_API gr_sync_decimator : public gr_sync_block { private: unsigned d_decimation; diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index 0363bc55c..d65b3da1e 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_SYNC_INTERPOLATOR_H #define INCLUDED_GR_SYNC_INTERPOLATOR_H +#include #include /*! @@ -31,7 +32,7 @@ * * Override work to provide the signal processing implementation. */ -class gr_sync_interpolator : public gr_sync_block +class GR_CORE_API gr_sync_interpolator : public gr_sync_block { private: unsigned d_interpolation; diff --git a/gnuradio-core/src/lib/runtime/gr_sys_paths.h b/gnuradio-core/src/lib/runtime/gr_sys_paths.h index aa8249775..1f1759c36 100644 --- a/gnuradio-core/src/lib/runtime/gr_sys_paths.h +++ b/gnuradio-core/src/lib/runtime/gr_sys_paths.h @@ -22,10 +22,12 @@ #ifndef _GR_SYS_PATHS_H_ #define _GR_SYS_PATHS_H_ +#include + //! directory to create temporary files -const char *gr_tmp_path(); +GR_CORE_API const char *gr_tmp_path(); //! directory to store application data -const char *gr_appdata_path(); +GR_CORE_API const char *gr_appdata_path(); #endif /* _GR_SYS_PATHS_H_ */ diff --git a/gnuradio-core/src/lib/runtime/gr_timer.h b/gnuradio-core/src/lib/runtime/gr_timer.h index ff14e315d..fa3c06ece 100644 --- a/gnuradio-core/src/lib/runtime/gr_timer.h +++ b/gnuradio-core/src/lib/runtime/gr_timer.h @@ -22,13 +22,14 @@ #ifndef INCLUDED_GR_TIMER_H #define INCLUDED_GR_TIMER_H +#include #include class gr_timer; typedef boost::shared_ptr gr_timer_sptr; -typedef void (*gr_timer_hook)(gr_timer *, void *); +GR_CORE_API typedef void (*gr_timer_hook)(gr_timer *, void *); /*! * \brief create a timeout. @@ -36,18 +37,18 @@ typedef void (*gr_timer_hook)(gr_timer *, void *); * \ingroup misc * gr_timer_hook is called when timer fires. */ -gr_timer_sptr gr_make_timer (gr_timer_hook, void *); +GR_CORE_API gr_timer_sptr gr_make_timer (gr_timer_hook, void *); /*! * \brief implement timeouts */ -class gr_timer { +class GR_CORE_API gr_timer { double d_expiry; double d_period; gr_timer_hook d_hook; void *d_hook_arg; - friend gr_timer_sptr gr_make_timer (gr_timer_hook, void *); + friend GR_CORE_API gr_timer_sptr gr_make_timer (gr_timer_hook, void *); gr_timer (...); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index ed244cb7c..fca68ae71 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -23,21 +23,22 @@ #ifndef INCLUDED_GR_TOP_BLOCK_H #define INCLUDED_GR_TOP_BLOCK_H +#include #include class gr_top_block_impl; -gr_top_block_sptr gr_make_top_block(const std::string &name); +GR_CORE_API gr_top_block_sptr gr_make_top_block(const std::string &name); /*! *\brief Top-level hierarchical block representing a flowgraph * \ingroup container_blk * */ -class gr_top_block : public gr_hier_block2 +class GR_CORE_API gr_top_block : public gr_hier_block2 { private: - friend gr_top_block_sptr gr_make_top_block(const std::string &name); + friend GR_CORE_API gr_top_block_sptr gr_make_top_block(const std::string &name); gr_top_block_impl *d_impl; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index ef28dd829..904443be5 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_TOP_BLOCK_IMPL_H #define INCLUDED_GR_TOP_BLOCK_IMPL_H +#include #include #include @@ -34,7 +35,7 @@ * decoupling of changes from dependent classes. * */ -class gr_top_block_impl +class GR_CORE_API gr_top_block_impl { public: gr_top_block_impl(gr_top_block *owner); diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h index acfa264c7..90908c2f5 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h @@ -21,6 +21,7 @@ #ifndef INCLUDED_GR_TPB_DETAIL_H #define INCLUDED_GR_TPB_DETAIL_H +#include #include #include #include @@ -30,7 +31,7 @@ class gr_block_detail; /*! * \brief used by thread-per-block scheduler */ -struct gr_tpb_detail { +struct GR_CORE_API gr_tpb_detail { gruel::mutex mutex; //< protects all vars bool input_changed; diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h index a630b1be9..548cfedfb 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h @@ -21,6 +21,7 @@ #ifndef INCLUDED_GR_TPB_THREAD_BODY_H #define INCLUDED_GR_TPB_THREAD_BODY_H +#include #include #include #include @@ -33,7 +34,7 @@ * done or is interrupted. */ -class gr_tpb_thread_body { +class GR_CORE_API gr_tpb_thread_body { gr_block_executor d_exec; public: diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h index ad8f145b8..fd5ca7758 100644 --- a/gnuradio-core/src/lib/runtime/gr_types.h +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_TYPES_H #define INCLUDED_GR_TYPES_H +#include #include #include #include // size_t diff --git a/gnuradio-core/src/lib/runtime/gr_unittests.h b/gnuradio-core/src/lib/runtime/gr_unittests.h index 59149bb2e..7161b31e7 100644 --- a/gnuradio-core/src/lib/runtime/gr_unittests.h +++ b/gnuradio-core/src/lib/runtime/gr_unittests.h @@ -24,12 +24,14 @@ #include "config.h" #endif +#include #include #include #include #include #include #include +#include #include #include diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h index a73a1559c..0e67d405b 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h @@ -23,13 +23,14 @@ #ifndef _GR_VMCIRCBUF_H_ #define _GR_VMCIRCBUF_H_ +#include #include /*! * \brief abstract class to implement doubly mapped virtual memory circular buffers * \ingroup internal */ -class gr_vmcircbuf { +class GR_CORE_API gr_vmcircbuf { protected: int d_size; char *d_base; @@ -48,7 +49,7 @@ class gr_vmcircbuf { /*! * \brief abstract factory for creating circular buffers */ -class gr_vmcircbuf_factory { +class GR_CORE_API gr_vmcircbuf_factory { protected: gr_vmcircbuf_factory () {}; virtual ~gr_vmcircbuf_factory (); @@ -76,7 +77,7 @@ class gr_vmcircbuf_factory { /* * \brief pulls together all implementations of gr_vmcircbuf */ -class gr_vmcircbuf_sysconfig { +class GR_CORE_API gr_vmcircbuf_sysconfig { public: /* diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h index 9276ae98b..5ef31f5c6 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_createfilemapping.h @@ -23,6 +23,7 @@ #ifndef _GR_VMCIRCBUF_CREATEFILEMAPPING_H_ #define _GR_VMCIRCBUF_CREATEFILEMAPPING_H_ +#include #include #ifdef HAVE_CREATEFILEMAPPING @@ -32,7 +33,7 @@ * \brief concrete class to implement circular buffers with mmap and shm_open * \ingroup internal */ -class gr_vmcircbuf_createfilemapping : public gr_vmcircbuf +class GR_CORE_API gr_vmcircbuf_createfilemapping : public gr_vmcircbuf { public: // CREATORS @@ -49,7 +50,7 @@ class gr_vmcircbuf_createfilemapping : public gr_vmcircbuf /*! * \brief concrete factory for circular buffers built using mmap and shm_open */ -class gr_vmcircbuf_createfilemapping_factory : public gr_vmcircbuf_factory +class GR_CORE_API gr_vmcircbuf_createfilemapping_factory : public gr_vmcircbuf_factory { private: static gr_vmcircbuf_factory *s_the_factory; diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h index 238f44414..002f5b434 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h @@ -23,13 +23,14 @@ #ifndef _GR_VMCIRCBUF_MMAP_SHM_OPEN_H_ #define _GR_VMCIRCBUF_MMAP_SHM_OPEN_H_ +#include #include /*! * \brief concrete class to implement circular buffers with mmap and shm_open * \ingroup internal */ -class gr_vmcircbuf_mmap_shm_open : public gr_vmcircbuf { +class GR_CORE_API gr_vmcircbuf_mmap_shm_open : public gr_vmcircbuf { public: // CREATORS @@ -41,7 +42,7 @@ class gr_vmcircbuf_mmap_shm_open : public gr_vmcircbuf { /*! * \brief concrete factory for circular buffers built using mmap and shm_open */ -class gr_vmcircbuf_mmap_shm_open_factory : public gr_vmcircbuf_factory { +class GR_CORE_API gr_vmcircbuf_mmap_shm_open_factory : public gr_vmcircbuf_factory { private: static gr_vmcircbuf_factory *s_the_factory; diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h index e5be52768..a2ed6b87b 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h @@ -23,13 +23,14 @@ #ifndef _GR_VMCIRCBUF_MMAP_TMPFILE_H_ #define _GR_VMCIRCBUF_MMAP_TMPFILE_H_ +#include #include /*! * \brief concrete class to implement circular buffers with mmap and shm_open * \ingroup internal */ -class gr_vmcircbuf_mmap_tmpfile : public gr_vmcircbuf { +class GR_CORE_API gr_vmcircbuf_mmap_tmpfile : public gr_vmcircbuf { public: // CREATORS @@ -41,7 +42,7 @@ class gr_vmcircbuf_mmap_tmpfile : public gr_vmcircbuf { /*! * \brief concrete factory for circular buffers built using mmap and shm_open */ -class gr_vmcircbuf_mmap_tmpfile_factory : public gr_vmcircbuf_factory { +class GR_CORE_API gr_vmcircbuf_mmap_tmpfile_factory : public gr_vmcircbuf_factory { private: static gr_vmcircbuf_factory *s_the_factory; diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h index cc87f8fe6..c7a008581 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h @@ -23,13 +23,14 @@ #ifndef _GR_VMCIRCBUF_SYSV_SHM_H_ #define _GR_VMCIRCBUF_SYSV_SHM_H_ +#include #include /*! * \brief concrete class to implement circular buffers with mmap and shm_open * \ingroup internal */ -class gr_vmcircbuf_sysv_shm : public gr_vmcircbuf { +class GR_CORE_API gr_vmcircbuf_sysv_shm : public gr_vmcircbuf { public: // CREATORS @@ -41,7 +42,7 @@ class gr_vmcircbuf_sysv_shm : public gr_vmcircbuf { /*! * \brief concrete factory for circular buffers built using mmap and shm_open */ -class gr_vmcircbuf_sysv_shm_factory : public gr_vmcircbuf_factory { +class GR_CORE_API gr_vmcircbuf_sysv_shm_factory : public gr_vmcircbuf_factory { private: static gr_vmcircbuf_factory *s_the_factory; diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.h b/gnuradio-core/src/lib/runtime/qa_runtime.h index c55208c39..e1038aaf6 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.h +++ b/gnuradio-core/src/lib/runtime/qa_runtime.h @@ -23,11 +23,12 @@ #ifndef _QA_RUNTIME_H_ #define _QA_RUNTIME_H_ +#include #include //! collect all the tests for the runtime directory -class qa_runtime { +class __GR_ATTR_EXPORT qa_runtime { public: //! return suite of tests for all of runtime directory static CppUnit::TestSuite *suite (); -- cgit From accb9f2fe8fd8f6a1e114adac5b15304b0e0012d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 19:04:32 -0700 Subject: gr: squashed cmakelists.txt into one commit --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 162 +++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 gnuradio-core/src/lib/runtime/CMakeLists.txt (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt new file mode 100644 index 000000000..4b1f85bbe --- /dev/null +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -0,0 +1,162 @@ +# Copyright 2010-2010 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 GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +######################################################################## +# This file included, use CMake directory variables +######################################################################## + +######################################################################## +# Append gnuradio-core library sources +######################################################################## +LIST(APPEND gnuradio_core_sources + ${CMAKE_CURRENT_SOURCE_DIR}/gr_basic_block.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_flowgraph.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_flat_flowgraph.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_detail.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_executor.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2_detail.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_buffer.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_dispatcher.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_local_sighandler.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_queue.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_pagesize.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_preferences.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_realtime.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler_sts.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler_tpb.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_single_threaded_scheduler.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sptr_magic.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_decimator.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_interpolator.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sys_paths.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block_impl.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_detail.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_thread_body.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf_mmap_shm_open.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf_mmap_tmpfile.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf_createfilemapping.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf_sysv_shm.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_select_handler.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_tag_info.cc +) + +######################################################################## +# Append gnuradio-core test sources +######################################################################## +LIST(APPEND test_gnuradio_core_sources + ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_block.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_hier_block2.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_hier_block2_derived.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_buffer.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_flowgraph.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_top_block.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_io_signature.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_vmcircbuf.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_block_tags.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_runtime.cc + ${CMAKE_CURRENT_SOURCE_DIR}/qa_set_msg_handler.cc +) + +######################################################################## +# Install runtime headers +######################################################################## +INSTALL(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/gr_basic_block.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_flowgraph.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_flat_flowgraph.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_detail.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_executor.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2_detail.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_buffer.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_complex.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_dispatcher.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_local_sighandler.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_queue.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_pagesize.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_preferences.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_realtime.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_runtime_types.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler_sts.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler_tpb.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_select_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_single_threaded_scheduler.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sptr_magic.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_decimator.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_interpolator.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block_impl.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_detail.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_thread_body.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_timer.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sys_paths.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_types.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_unittests.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_tag_info.h + DESTINATION ${GR_INCLUDE_DIR}/gnuradio + COMPONENT "core_devel" +) + +######################################################################## +# Install swig headers +######################################################################## +IF(ENABLE_PYTHON) +INSTALL(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/gr_basic_block.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_detail.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_buffer.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_dispatcher.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_queue.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_realtime.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_single_threaded_scheduler.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_decimator.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_interpolator.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.i + ${CMAKE_CURRENT_SOURCE_DIR}/runtime.i + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig + COMPONENT "core_swig" +) +ENDIF(ENABLE_PYTHON) -- cgit From 71c0f14a46f85027b95f2f5f6d3d219cc9e3783e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 8 Oct 2011 17:11:12 -0700 Subject: gr: the CMakeLists.txt took a chill pill --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 4b1f85bbe..52cb39c40 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -24,7 +24,7 @@ ######################################################################## # Append gnuradio-core library sources ######################################################################## -LIST(APPEND gnuradio_core_sources +list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gr_basic_block.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_flowgraph.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_flat_flowgraph.cc @@ -70,7 +70,7 @@ LIST(APPEND gnuradio_core_sources ######################################################################## # Append gnuradio-core test sources ######################################################################## -LIST(APPEND test_gnuradio_core_sources +list(APPEND test_gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_block.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_hier_block2.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_hier_block2_derived.cc @@ -87,7 +87,7 @@ LIST(APPEND test_gnuradio_core_sources ######################################################################## # Install runtime headers ######################################################################## -INSTALL(FILES +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr_basic_block.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_flowgraph.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_flat_flowgraph.h @@ -136,8 +136,8 @@ INSTALL(FILES ######################################################################## # Install swig headers ######################################################################## -IF(ENABLE_PYTHON) -INSTALL(FILES +if(ENABLE_PYTHON) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr_basic_block.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_detail.i @@ -159,4 +159,4 @@ INSTALL(FILES DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "core_swig" ) -ENDIF(ENABLE_PYTHON) +endif(ENABLE_PYTHON) -- cgit From c1721c76bd67962a1d29e520dfea0789a14d0aa9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 19 Oct 2011 13:35:46 -0700 Subject: tags: made tags object oriented --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 3 +- gnuradio-core/src/lib/runtime/Makefile.am | 3 +- gnuradio-core/src/lib/runtime/gr_block.cc | 11 +-- gnuradio-core/src/lib/runtime/gr_block.h | 25 ++++++- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 28 +++---- gnuradio-core/src/lib/runtime/gr_block_detail.h | 18 ++--- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 25 +++---- gnuradio-core/src/lib/runtime/gr_block_executor.h | 4 +- gnuradio-core/src/lib/runtime/gr_buffer.cc | 12 +-- gnuradio-core/src/lib/runtime/gr_buffer.h | 14 ++-- gnuradio-core/src/lib/runtime/gr_tag_info.cc | 38 ---------- gnuradio-core/src/lib/runtime/gr_tag_info.h | 87 ---------------------- gnuradio-core/src/lib/runtime/gr_tags.h | 55 ++++++++++++++ gnuradio-core/src/lib/runtime/qa_block_tags.cc | 28 +++---- 14 files changed, 135 insertions(+), 216 deletions(-) delete mode 100644 gnuradio-core/src/lib/runtime/gr_tag_info.cc delete mode 100644 gnuradio-core/src/lib/runtime/gr_tag_info.h create mode 100644 gnuradio-core/src/lib/runtime/gr_tags.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 52cb39c40..e0774154e 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -64,7 +64,6 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf_createfilemapping.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf_sysv_shm.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_select_handler.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_tag_info.cc ) ######################################################################## @@ -128,7 +127,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr_types.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_unittests.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf.h - ${CMAKE_CURRENT_SOURCE_DIR}/gr_tag_info.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_tags.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio COMPONENT "core_devel" ) diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index eca92e526..b4a59337e 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -69,7 +69,6 @@ libruntime_la_SOURCES = \ gr_vmcircbuf_createfilemapping.cc \ gr_vmcircbuf_sysv_shm.cc \ gr_select_handler.cc \ - gr_tag_info.cc libruntime_qa_la_SOURCES = \ qa_gr_block.cc \ @@ -125,7 +124,7 @@ grinclude_HEADERS = \ gr_types.h \ gr_unittests.h \ gr_vmcircbuf.h \ - gr_tag_info.h + gr_tags.h noinst_HEADERS = \ gr_vmcircbuf_mmap_shm_open.h \ diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 81a55af9d..9463869f5 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -144,16 +144,13 @@ gr_block::nitems_written(unsigned int which_output) void gr_block::add_item_tag(unsigned int which_output, - uint64_t offset, - const pmt::pmt_t &key, - const pmt::pmt_t &value, - const pmt::pmt_t &srcid) + const gr_tag_t &tag) { - d_detail->add_item_tag(which_output, offset, key, value, srcid); + d_detail->add_item_tag(which_output, tag); } void -gr_block::get_tags_in_range(std::vector &v, +gr_block::get_tags_in_range(std::vector &v, unsigned int which_output, uint64_t start, uint64_t end) { @@ -161,7 +158,7 @@ gr_block::get_tags_in_range(std::vector &v, } void -gr_block::get_tags_in_range(std::vector &v, +gr_block::get_tags_in_range(std::vector &v, unsigned int which_output, uint64_t start, uint64_t end, const pmt::pmt_t &key) diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 2453e97b8..86e0583e9 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -25,6 +25,7 @@ #include #include +#include /*! * \brief The abstract base class for all 'terminal' processing blocks. @@ -255,11 +256,27 @@ class GR_CORE_API gr_block : public gr_basic_block { * \param value any PMT holding any value for the given key * \param srcid optional source ID specifier; defaults to PMT_F */ - void add_item_tag(unsigned int which_output, + inline void add_item_tag(unsigned int which_output, uint64_t abs_offset, const pmt::pmt_t &key, const pmt::pmt_t &value, - const pmt::pmt_t &srcid=pmt::PMT_F); + const pmt::pmt_t &srcid=pmt::PMT_F) + { + gr_tag_t tag; + tag.offset = abs_offset; + tag.key = key; + tag.value = value; + tag.srcid = srcid; + this->add_item_tag(which_output, tag); + } + + /*! + * \brief Adds a new tag onto the given output buffer. + * + * \param which_output an integer of which output stream to attach the tag + * \param tag the tag object to add + */ + void add_item_tag(unsigned int which_output, const gr_tag_t &tag); /*! * \brief Given a [start,end), returns a vector of all tags in the range. @@ -274,7 +291,7 @@ class GR_CORE_API gr_block : public gr_basic_block { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - void get_tags_in_range(std::vector &v, + void get_tags_in_range(std::vector &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end); @@ -294,7 +311,7 @@ class GR_CORE_API gr_block : public gr_basic_block { * \param abs_end a uint64 count of the end of the range of interest * \param key a PMT symbol key to filter only tags of this key */ - void get_tags_in_range(std::vector &v, + void get_tags_in_range(std::vector &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end, diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index a360240c0..cbd4239f3 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -150,27 +150,19 @@ gr_block_detail::nitems_written(unsigned int which_output) } void -gr_block_detail::add_item_tag(unsigned int which_output, - uint64_t abs_offset, - const pmt_t &key, - const pmt_t &value, - const pmt_t &srcid) -{ - if(!pmt_is_symbol(key)) { - throw pmt_wrong_type("gr_block_detail::add_item_tag key", key); +gr_block_detail::add_item_tag(unsigned int which_output, const gr_tag_t &tag) +{ + if(!pmt_is_symbol(tag.key)) { + throw pmt_wrong_type("gr_block_detail::add_item_tag key", tag.key); } else { - // build tag tuple - pmt_t nitem = pmt_from_uint64(abs_offset); - pmt_t tuple = pmt_make_tuple(nitem, srcid, key, value); - // Add tag to gr_buffer's deque tags - d_output[which_output]->add_item_tag(tuple); + d_output[which_output]->add_item_tag(tag); } } void -gr_block_detail::get_tags_in_range(std::vector &v, +gr_block_detail::get_tags_in_range(std::vector &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end) @@ -180,13 +172,13 @@ gr_block_detail::get_tags_in_range(std::vector &v, } void -gr_block_detail::get_tags_in_range(std::vector &v, +gr_block_detail::get_tags_in_range(std::vector &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end, const pmt_t &key) { - std::vector found_items; + std::vector found_items; v.resize(0); @@ -195,9 +187,9 @@ gr_block_detail::get_tags_in_range(std::vector &v, // Filter further by key name pmt_t itemkey; - std::vector::iterator itr; + std::vector::iterator itr; for(itr = found_items.begin(); itr != found_items.end(); itr++) { - itemkey = pmt_tuple_ref(*itr, 2); + itemkey = (*itr).key; if(pmt_eqv(key, itemkey)) { v.push_back(*itr); } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 633da1b0c..89081156a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include /*! @@ -105,17 +105,9 @@ class GR_CORE_API gr_block_detail { * which appends the tag onto its deque. * * \param which_output an integer of which output stream to attach the tag - * \param abs_offset a uint64 number of the absolute item number - * assicated with the tag. Can get from nitems_written. - * \param key the tag key as a PMT symbol - * \param value any PMT holding any value for the given key - * \param srcid a PMT source ID specifier + * \param tag the tag object to add */ - void add_item_tag(unsigned int which_output, - uint64_t abs_offset, - const pmt::pmt_t &key, - const pmt::pmt_t &value, - const pmt::pmt_t &srcid); + void add_item_tag(unsigned int which_output, const gr_tag_t &tag); /*! * \brief Given a [start,end), returns a vector of all tags in the range. @@ -131,7 +123,7 @@ class GR_CORE_API gr_block_detail { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - void get_tags_in_range(std::vector &v, + void get_tags_in_range(std::vector &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end); @@ -153,7 +145,7 @@ class GR_CORE_API gr_block_detail { * \param abs_end a uint64 count of the end of the range of interest * \param key a PMT symbol to select only tags of this key */ - void get_tags_in_range(std::vector &v, + void get_tags_in_range(std::vector &v, unsigned int which_input, uint64_t abs_start, uint64_t abs_end, diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index b3f987f72..737b26f67 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -91,7 +91,7 @@ min_available_space (gr_block_detail *d, int output_multiple) static bool propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, const std::vector &start_nitems_read, double rrate, - std::vector &rtags) + std::vector &rtags) { // Move tags downstream // if a sink, we don't need to move downstream @@ -109,7 +109,7 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, d->get_tags_in_range(rtags, i, start_nitems_read[i], d->nitems_read(i)); - std::vector::iterator t; + std::vector::iterator t; if(rrate == 1.0) { for(t = rtags.begin(); t != rtags.end(); t++) { for(int o = 0; o < d->noutputs(); o++) @@ -118,14 +118,10 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, } else { for(t = rtags.begin(); t != rtags.end(); t++) { - uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); - pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), - pmt::pmt_tuple_ref(*t, 1), - pmt::pmt_tuple_ref(*t, 2), - pmt::pmt_tuple_ref(*t, 3)); - + gr_tag_t new_tag = *t; + new_tag.offset *= rrate; for(int o = 0; o < d->noutputs(); o++) - d->output(o)->add_item_tag(newtup); + d->output(o)->add_item_tag(new_tag); } } } @@ -139,14 +135,11 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, d->get_tags_in_range(rtags, i, start_nitems_read[i], d->nitems_read(i)); - std::vector::iterator t; + std::vector::iterator t; for(t = rtags.begin(); t != rtags.end(); t++) { - uint64_t newcount = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*t, 0)); - pmt::pmt_t newtup = pmt::mp(pmt::pmt_from_uint64(newcount * rrate), - pmt::pmt_tuple_ref(*t, 1), - pmt::pmt_tuple_ref(*t, 2), - pmt::pmt_tuple_ref(*t, 3)); - d->output(i)->add_item_tag(newtup); + gr_tag_t new_tag = *t; + new_tag.offset *= rrate; + d->output(i)->add_item_tag(new_tag); } } } diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h index cd93212e1..15279f273 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.h +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include //class gr_block_executor; //typedef boost::shared_ptr gr_block_executor_sptr; @@ -50,7 +50,7 @@ protected: std::vector d_input_done; gr_vector_void_star d_output_items; std::vector d_start_nitems_read; //stores where tag counts are before work - std::vector d_returned_tags; + std::vector d_returned_tags; public: gr_block_executor(gr_block_sptr block); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index fa3722714..8ccc9db32 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -227,7 +227,7 @@ gr_buffer::drop_reader (gr_buffer_reader *reader) } void -gr_buffer::add_item_tag(const pmt::pmt_t &tag) +gr_buffer::add_item_tag(const gr_tag_t &tag) { gruel::scoped_lock guard(*mutex()); d_item_tags.push_back(tag); @@ -245,7 +245,7 @@ gr_buffer::prune_tags(uint64_t max_time) buffer's mutex al la the scoped_lock line below. */ //gruel::scoped_lock guard(*mutex()); - std::deque::iterator itr = d_item_tags.begin(); + std::deque::iterator itr = d_item_tags.begin(); uint64_t item_time; @@ -255,7 +255,7 @@ gr_buffer::prune_tags(uint64_t max_time) // to find more. Mostly, we wil be erasing from the front and // therefore lose little time this way. while(itr != d_item_tags.end()) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + item_time = (*itr).offset; if(item_time < max_time) { d_item_tags.erase(itr); itr = d_item_tags.begin(); @@ -307,18 +307,18 @@ gr_buffer_reader::update_read_pointer (int nitems) } void -gr_buffer_reader::get_tags_in_range(std::vector &v, +gr_buffer_reader::get_tags_in_range(std::vector &v, uint64_t abs_start, uint64_t abs_end) { gruel::scoped_lock guard(*mutex()); v.resize(0); - std::deque::iterator itr = d_buffer->get_tags_begin(); + std::deque::iterator itr = d_buffer->get_tags_begin(); uint64_t item_time; while(itr != d_buffer->get_tags_end()) { - item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + item_time = (*itr).offset; if((item_time >= abs_start) && (item_time < abs_end)) { v.push_back(*itr); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index e7c0a06a5..e8e393756 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include class gr_vmcircbuf; @@ -97,9 +97,9 @@ class GR_CORE_API gr_buffer { /*! * \brief Adds a new tag to the buffer. * - * \param tag a PMT tuple containing the new tag + * \param tag the new tag */ - void add_item_tag(const pmt::pmt_t &tag); + void add_item_tag(const gr_tag_t &tag); /*! * \brief Removes all tags before \p max_time from buffer @@ -108,8 +108,8 @@ class GR_CORE_API gr_buffer { */ void prune_tags(uint64_t max_time); - std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } - std::deque::iterator get_tags_end() { return d_item_tags.end(); } + std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } + std::deque::iterator get_tags_end() { return d_item_tags.end(); } // ------------------------------------------------------------------------- @@ -136,7 +136,7 @@ class GR_CORE_API gr_buffer { unsigned int d_write_index; // in items [0,d_bufsize) uint64_t d_abs_write_offset; // num items written since the start bool d_done; - std::deque d_item_tags; + std::deque d_item_tags; uint64_t d_last_min_items_read; unsigned @@ -268,7 +268,7 @@ class GR_CORE_API gr_buffer_reader { * \param abs_start a uint64 count of the start of the range of interest * \param abs_end a uint64 count of the end of the range of interest */ - void get_tags_in_range(std::vector &v, + void get_tags_in_range(std::vector &v, uint64_t abs_start, uint64_t abs_end); diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.cc b/gnuradio-core/src/lib/runtime/gr_tag_info.cc deleted file mode 100644 index f15329f9b..000000000 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.cc +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -namespace gr_tags { -/* - const pmt::pmt_t key_time = pmt::pmt_string_to_symbol("time"); - const pmt::pmt_t key_sample_rate = pmt::pmt_string_to_symbol("sample_rate"); - const pmt::pmt_t key_frequency = pmt::pmt_string_to_symbol("frequency"); - const pmt::pmt_t key_rssi = pmt::pmt_string_to_symbol("rssi"); - const pmt::pmt_t key_rx_gain = pmt::pmt_string_to_symbol("gain"); -*/ -} diff --git a/gnuradio-core/src/lib/runtime/gr_tag_info.h b/gnuradio-core/src/lib/runtime/gr_tag_info.h deleted file mode 100644 index 5a1e1555a..000000000 --- a/gnuradio-core/src/lib/runtime/gr_tag_info.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_TAG_INFO_H -#define INCLUDED_GR_TAG_INFO_H - -#include - -namespace gr_tags { - - enum { - TAG_NITEM_REF = 0, - TAG_SRCID_REF, - TAG_KEY_REF, - TAG_VALUE_REF - }; - - /* - extern const pmt::pmt_t key_time; - extern const pmt::pmt_t key_sample_rate; - extern const pmt::pmt_t key_frequency; - extern const pmt::pmt_t key_rssi; - extern const pmt::pmt_t key_gain; - */ - - /*! - * \brief Returns the item \p tag occurred at (as a uint64_t) - */ - static inline uint64_t - get_nitems(const pmt::pmt_t &tag) { - return pmt::pmt_to_uint64(pmt::pmt_tuple_ref(tag, TAG_NITEM_REF)); - } - - /*! - * \brief Returns the source ID of \p tag (as a PMT) - */ - static inline pmt::pmt_t - get_srcid(const pmt::pmt_t &tag) { - return pmt::pmt_tuple_ref(tag, TAG_SRCID_REF); - } - - /*! - * \brief Returns the key of \p tag (as a PMT symbol) - */ - static inline pmt::pmt_t - get_key(const pmt::pmt_t &tag) { - return pmt::pmt_tuple_ref(tag, TAG_KEY_REF); - } - - /*! - * \brief Returns the value of \p tag (as a PMT) - */ - static inline pmt::pmt_t - get_value(const pmt::pmt_t &tag) { - return pmt::pmt_tuple_ref(tag, TAG_VALUE_REF); - } - - /*! - * \brief Comparison function to test which tag, \p x or \p y, came first in time - */ - static inline bool - nitems_compare(pmt::pmt_t x, pmt::pmt_t y) { - return get_nitems(x) < get_nitems(y); - } - -}; /* namespace tags */ - -#endif /* GR_TAG_INFO */ diff --git a/gnuradio-core/src/lib/runtime/gr_tags.h b/gnuradio-core/src/lib/runtime/gr_tags.h new file mode 100644 index 000000000..e410e76a4 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tags.h @@ -0,0 +1,55 @@ +/* + * Copyright 2011 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TAGS_H +#define INCLUDED_GR_TAGS_H + +#include +#include + +//dummy namespace so the line below makes swig happy +namespace pmt{} +//stupid using namespace because pmt::pmt_t confuses swig +using namespace pmt; + +struct GR_CORE_API gr_tag_t{ + + //! the item \p tag occurred at (as a uint64_t) + uint64_t offset; + + //! the key of \p tag (as a PMT symbol) + pmt_t key; + + //! the value of \p tag (as a PMT) + pmt_t value; + + //! the source ID of \p tag (as a PMT) + pmt_t srcid; + + //! Comparison function to test which tag, \p x or \p y, came first in time + static inline bool offset_compare( + const gr_tag_t &x, const gr_tag_t &y + ){ + return x.offset < y.offset; + } +}; + +#endif /*INCLUDED_GR_TAGS_H*/ diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 07ce5c276..ab5840c6d 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -103,9 +103,9 @@ qa_block_tags::t1 () tb->run(); - std::vector tags0 = ann0->data(); - std::vector tags3 = ann3->data(); - std::vector tags4 = ann4->data(); + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); // The first annotator does not receive any tags from the null sink upstream CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); @@ -187,11 +187,11 @@ qa_block_tags::t2 () tb->run(); - std::vector tags0 = ann0->data(); - std::vector tags1 = ann1->data(); - std::vector tags2 = ann2->data(); - std::vector tags3 = ann4->data(); - std::vector tags4 = ann4->data(); + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); + std::vector tags3 = ann4->data(); + std::vector tags4 = ann4->data(); // The first annotator does not receive any tags from the null sink upstream CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); @@ -287,9 +287,9 @@ qa_block_tags::t3 () tb->run(); - std::vector tags0 = ann0->data(); - std::vector tags3 = ann3->data(); - std::vector tags4 = ann4->data(); + std::vector tags0 = ann0->data(); + std::vector tags3 = ann3->data(); + std::vector tags4 = ann4->data(); // The first annotator does not receive any tags from the null sink upstream CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); @@ -394,9 +394,9 @@ qa_block_tags::t5 () tb->run(); - std::vector tags0 = ann0->data(); - std::vector tags1 = ann1->data(); - std::vector tags2 = ann2->data(); + std::vector tags0 = ann0->data(); + std::vector tags1 = ann1->data(); + std::vector tags2 = ann2->data(); // The first annotator does not receive any tags from the null sink upstream CPPUNIT_ASSERT_EQUAL(tags0.size(), (size_t)0); -- cgit From b0748f4a1605c74c473c434d0a366d2e72c152ce Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 19 Oct 2011 17:37:19 -0700 Subject: Fixed Makefile.am trailing backslash for autofoo build. --- gnuradio-core/src/lib/runtime/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index b4a59337e..d4233e1ba 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -68,7 +68,7 @@ libruntime_la_SOURCES = \ gr_vmcircbuf_mmap_tmpfile.cc \ gr_vmcircbuf_createfilemapping.cc \ gr_vmcircbuf_sysv_shm.cc \ - gr_select_handler.cc \ + gr_select_handler.cc libruntime_qa_la_SOURCES = \ qa_gr_block.cc \ -- cgit From 9789365e056ccf1373a59f0e63f6f94f83f5073f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 20 Oct 2011 22:38:57 -0700 Subject: tags: added swigging for gr_tags header --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 1 + gnuradio-core/src/lib/runtime/Makefile.am | 1 + gnuradio-core/src/lib/runtime/gr_tags.h | 11 +++------- gnuradio-core/src/lib/runtime/gr_tags.i | 32 ++++++++++++++++++++++++++++ gnuradio-core/src/lib/runtime/runtime.i | 3 +++ 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/gr_tags.i (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index e0774154e..105fc0e06 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -153,6 +153,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_decimator.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_interpolator.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_tags.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.i ${CMAKE_CURRENT_SOURCE_DIR}/runtime.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am index d4233e1ba..38da3d5fd 100644 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ b/gnuradio-core/src/lib/runtime/Makefile.am @@ -160,5 +160,6 @@ swiginclude_HEADERS = \ gr_sync_block.i \ gr_sync_decimator.i \ gr_sync_interpolator.i \ + gr_tags.i \ gr_top_block.i \ runtime.i diff --git a/gnuradio-core/src/lib/runtime/gr_tags.h b/gnuradio-core/src/lib/runtime/gr_tags.h index e410e76a4..5fff6f15b 100644 --- a/gnuradio-core/src/lib/runtime/gr_tags.h +++ b/gnuradio-core/src/lib/runtime/gr_tags.h @@ -25,24 +25,19 @@ #include #include -//dummy namespace so the line below makes swig happy -namespace pmt{} -//stupid using namespace because pmt::pmt_t confuses swig -using namespace pmt; - struct GR_CORE_API gr_tag_t{ //! the item \p tag occurred at (as a uint64_t) uint64_t offset; //! the key of \p tag (as a PMT symbol) - pmt_t key; + pmt::pmt_t key; //! the value of \p tag (as a PMT) - pmt_t value; + pmt::pmt_t value; //! the source ID of \p tag (as a PMT) - pmt_t srcid; + pmt::pmt_t srcid; //! Comparison function to test which tag, \p x or \p y, came first in time static inline bool offset_compare( diff --git a/gnuradio-core/src/lib/runtime/gr_tags.i b/gnuradio-core/src/lib/runtime/gr_tags.i new file mode 100644 index 000000000..828d0147c --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_tags.i @@ -0,0 +1,32 @@ +/* + * Copyright 2011 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +%{ +#include +%} + +%include //for pmt support + +%include + +//gives support for a vector of tags (get tags in range) +%include "std_vector.i" +%template(tags_vector_t) std::vector; diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index ca89b8fbd..e08693a0c 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -20,6 +20,8 @@ * Boston, MA 02110-1301, USA. */ +#define GR_CORE_API + %{ #include #include @@ -64,4 +66,5 @@ %include %include %include +%include %include -- cgit From 31268cfb68965dbcf3df4912059f0c5b6d744626 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 21 Oct 2011 12:40:43 -0700 Subject: core: runtime.i dont include gr_tag.i, avoids pmt dependency --- gnuradio-core/src/lib/runtime/runtime.i | 1 - 1 file changed, 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index e08693a0c..9bf2df31e 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -66,5 +66,4 @@ %include %include %include -%include %include -- cgit From 00420d32081d8252bb37142b2be19a8a7c4dc4c4 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 8 Dec 2011 13:48:48 -0800 Subject: Removed autotools, gr-waveform, some cleanup Nick Foster owes Nick Corgan a six-pack of beer! --- gnuradio-core/src/lib/runtime/.gitignore | 8 -- gnuradio-core/src/lib/runtime/Makefile.am | 165 ------------------------------ 2 files changed, 173 deletions(-) delete mode 100644 gnuradio-core/src/lib/runtime/.gitignore delete mode 100644 gnuradio-core/src/lib/runtime/Makefile.am (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/.gitignore b/gnuradio-core/src/lib/runtime/.gitignore deleted file mode 100644 index a02b6ff73..000000000 --- a/gnuradio-core/src/lib/runtime/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo diff --git a/gnuradio-core/src/lib/runtime/Makefile.am b/gnuradio-core/src/lib/runtime/Makefile.am deleted file mode 100644 index 38da3d5fd..000000000 --- a/gnuradio-core/src/lib/runtime/Makefile.am +++ /dev/null @@ -1,165 +0,0 @@ -# -# Copyright 2003,2004,2007,2008,2009,2010,2011 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -AM_CPPFLAGS = $(GRUEL_INCLUDES) $(STD_DEFINES_AND_INCLUDES) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) - -noinst_LTLIBRARIES = libruntime.la libruntime-qa.la - -libruntime_la_LIBADD = \ - $(SHM_OPEN_LIBS) - - -libruntime_la_SOURCES = \ - gr_basic_block.cc \ - gr_flowgraph.cc \ - gr_flat_flowgraph.cc \ - gr_block.cc \ - gr_block_detail.cc \ - gr_block_executor.cc \ - gr_hier_block2.cc \ - gr_hier_block2_detail.cc \ - gr_buffer.cc \ - gr_dispatcher.cc \ - gr_error_handler.cc \ - gr_io_signature.cc \ - gr_local_sighandler.cc \ - gr_message.cc \ - gr_msg_accepter.cc \ - gr_msg_handler.cc \ - gr_msg_queue.cc \ - gr_pagesize.cc \ - gr_preferences.cc \ - gr_realtime.cc \ - gr_scheduler.cc \ - gr_scheduler_sts.cc \ - gr_scheduler_tpb.cc \ - gr_single_threaded_scheduler.cc \ - gr_sptr_magic.cc \ - gr_sync_block.cc \ - gr_sync_decimator.cc \ - gr_sync_interpolator.cc \ - gr_sys_paths.cc \ - gr_top_block.cc \ - gr_top_block_impl.cc \ - gr_tpb_detail.cc \ - gr_tpb_thread_body.cc \ - gr_vmcircbuf.cc \ - gr_vmcircbuf_mmap_shm_open.cc \ - gr_vmcircbuf_mmap_tmpfile.cc \ - gr_vmcircbuf_createfilemapping.cc \ - gr_vmcircbuf_sysv_shm.cc \ - gr_select_handler.cc - -libruntime_qa_la_SOURCES = \ - qa_gr_block.cc \ - qa_gr_hier_block2.cc \ - qa_gr_hier_block2_derived.cc \ - qa_gr_buffer.cc \ - qa_gr_flowgraph.cc \ - qa_gr_top_block.cc \ - qa_gr_io_signature.cc \ - qa_gr_vmcircbuf.cc \ - qa_block_tags.cc \ - qa_set_msg_handler.cc \ - qa_runtime.cc - -grinclude_HEADERS = \ - gr_basic_block.h \ - gr_flowgraph.h \ - gr_flat_flowgraph.h \ - gr_block.h \ - gr_block_detail.h \ - gr_block_executor.h \ - gr_hier_block2.h \ - gr_hier_block2_detail.h \ - gr_buffer.h \ - gr_complex.h \ - gr_dispatcher.h \ - gr_error_handler.h \ - gr_io_signature.h \ - gr_local_sighandler.h \ - gr_message.h \ - gr_msg_accepter.h \ - gr_msg_handler.h \ - gr_msg_queue.h \ - gr_pagesize.h \ - gr_preferences.h \ - gr_realtime.h \ - gr_runtime_types.h \ - gr_scheduler.h \ - gr_scheduler_sts.h \ - gr_scheduler_tpb.h \ - gr_select_handler.h \ - gr_single_threaded_scheduler.h \ - gr_sptr_magic.h \ - gr_sync_block.h \ - gr_sync_decimator.h \ - 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_sys_paths.h \ - gr_types.h \ - gr_unittests.h \ - gr_vmcircbuf.h \ - gr_tags.h - -noinst_HEADERS = \ - gr_vmcircbuf_mmap_shm_open.h \ - gr_vmcircbuf_mmap_tmpfile.h \ - gr_vmcircbuf_sysv_shm.h \ - gr_vmcircbuf_createfilemapping.h \ - qa_gr_block.h \ - qa_gr_flowgraph.h \ - qa_gr_hier_block2.h \ - qa_gr_hier_block2_derived.h \ - qa_gr_buffer.h \ - qa_gr_io_signature.h \ - qa_gr_top_block.h \ - qa_gr_vmcircbuf.h \ - qa_block_tags.h \ - qa_set_msg_handler.h \ - qa_runtime.h - -swiginclude_HEADERS = \ - gr_basic_block.i \ - gr_block.i \ - gr_block_detail.i \ - gr_hier_block2.i \ - gr_buffer.i \ - gr_dispatcher.i \ - gr_error_handler.i \ - gr_io_signature.i \ - gr_message.i \ - gr_msg_handler.i \ - gr_msg_queue.i \ - gr_realtime.i \ - gr_single_threaded_scheduler.i \ - gr_sync_block.i \ - gr_sync_decimator.i \ - gr_sync_interpolator.i \ - gr_tags.i \ - gr_top_block.i \ - runtime.i -- cgit From 543f8390edcab0201a68fabe86803b0d6f63ee34 Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Tue, 13 Dec 2011 14:05:55 -0800 Subject: runtime: improve hier_block2 error messages --- gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 877e240c2..1d0c66fb8 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -318,13 +318,14 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) if (is_input) { if (port < 0 || port >= (signed)d_inputs.size()) { - msg << "resolve_port: input " << port << " is out of range"; + msg << "resolve_port: hierarchical block '" << d_owner->name() + << "': input " << port << " is out of range"; throw std::runtime_error(msg.str()); } if (d_inputs[port].empty()) { - msg << "hierarchical block '" << d_owner->name() << "' input " << port - << " is not connected internally"; + msg << "resolve_port: hierarchical block '" << d_owner->name() + << "': input " << port << " is not connected internally"; throw std::runtime_error(msg.str()); } @@ -337,13 +338,14 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) } else { if (port < 0 || port >= (signed)d_outputs.size()) { - msg << "resolve_port: output " << port << " is out of range"; + msg << "resolve_port: hierarchical block '" << d_owner->name() + << "': output " << port << " is out of range"; throw std::runtime_error(msg.str()); } if (d_outputs[port] == gr_endpoint()) { - msg << "hierarchical block '" << d_owner->name() << "' output " << port - << " is not connected internally"; + msg << "resolve_port: hierarchical block '" << d_owner->name() + << "': output " << port << " is not connected internally"; throw std::runtime_error(msg.str()); } @@ -351,7 +353,8 @@ gr_hier_block2_detail::resolve_port(int port, bool is_input) } if (result.empty()) { - msg << "unable to resolve " + msg << "resolve_port: hierarchical block '" << d_owner->name() + << "': unable to resolve " << (is_input ? "input port " : "output port ") << port; throw std::runtime_error(msg.str()); -- cgit From 9716da257dcc3acbbc7ff8d9d79c1bc52c85b874 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 1 Jan 2012 21:24:00 -0500 Subject: scheduler: first attempt at being able to set an upper limit on the noutput_items for all blocks in a flowgraph. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 7 ++++-- gnuradio-core/src/lib/runtime/gr_block_executor.h | 3 ++- gnuradio-core/src/lib/runtime/gr_scheduler.cc | 2 +- gnuradio-core/src/lib/runtime/gr_scheduler.h | 2 +- gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc | 8 +++---- gnuradio-core/src/lib/runtime/gr_scheduler_sts.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc | 17 ++++++++------ gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h | 4 ++-- gnuradio-core/src/lib/runtime/gr_top_block.cc | 16 +++++++++++-- gnuradio-core/src/lib/runtime/gr_top_block.h | 13 ++++++++++- gnuradio-core/src/lib/runtime/gr_top_block.i | 5 +++- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 27 +++++++++++++++++----- gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 9 +++++++- .../src/lib/runtime/gr_tpb_thread_body.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h | 2 +- 15 files changed, 89 insertions(+), 34 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 737b26f67..0403ce138 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -155,8 +155,8 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, return true; } -gr_block_executor::gr_block_executor (gr_block_sptr block) - : d_block(block), d_log(0) +gr_block_executor::gr_block_executor (gr_block_sptr block, int max_noutput_items) + : d_block(block), d_log(0), d_max_noutput_items(max_noutput_items) { if (ENABLE_LOGGING){ std::string name = str(boost::format("sst-%03d.log") % which_scheduler++); @@ -203,6 +203,7 @@ gr_block_executor::run_one_iteration() // determine the minimum available output space noutput_items = min_available_space (d, m->output_multiple ()); + noutput_items = std::min(noutput_items, d_max_noutput_items); LOG(*d_log << " source\n noutput_items = " << noutput_items << std::endl); if (noutput_items == -1) // we're done goto were_done; @@ -247,6 +248,7 @@ gr_block_executor::run_one_iteration() // take a swag at how much output we can sink noutput_items = (int) (max_items_avail * m->relative_rate ()); noutput_items = round_down (noutput_items, m->output_multiple ()); + noutput_items = std::min(noutput_items, d_max_noutput_items); LOG(*d_log << " max_items_avail = " << max_items_avail << std::endl); LOG(*d_log << " noutput_items = " << noutput_items << std::endl); @@ -308,6 +310,7 @@ gr_block_executor::run_one_iteration() if (reqd_noutput_items > 0 && reqd_noutput_items <= noutput_items) noutput_items = reqd_noutput_items; } + noutput_items = std::min(noutput_items, d_max_noutput_items); // ask the block how much input they need to produce noutput_items m->forecast (noutput_items, d_ninput_items_required); diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h index 15279f273..e022d8273 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.h +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -51,9 +51,10 @@ protected: gr_vector_void_star d_output_items; std::vector d_start_nitems_read; //stores where tag counts are before work std::vector d_returned_tags; + int d_max_noutput_items; public: - gr_block_executor(gr_block_sptr block); + gr_block_executor(gr_block_sptr block, int max_noutput_items=100000); ~gr_block_executor (); enum state { diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_scheduler.cc index e4d8b3dd9..3ae08a7a3 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler.cc @@ -24,7 +24,7 @@ #endif #include -gr_scheduler::gr_scheduler(gr_flat_flowgraph_sptr ffg) +gr_scheduler::gr_scheduler(gr_flat_flowgraph_sptr ffg, int max_noutput_items) { } diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler.h b/gnuradio-core/src/lib/runtime/gr_scheduler.h index 4e97b5881..92af8d1cb 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler.h @@ -47,7 +47,7 @@ public: * The scheduler will continue running until all blocks until they * report that they are done or the stop method is called. */ - gr_scheduler(gr_flat_flowgraph_sptr ffg); + gr_scheduler(gr_flat_flowgraph_sptr ffg, int max_noutput_items); virtual ~gr_scheduler(); diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc index fefc0dc70..3cc1d4d45 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc @@ -43,13 +43,13 @@ public: gr_scheduler_sptr -gr_scheduler_sts::make(gr_flat_flowgraph_sptr ffg) +gr_scheduler_sts::make(gr_flat_flowgraph_sptr ffg, int max_noutput_items) { - return gr_scheduler_sptr(new gr_scheduler_sts(ffg)); + return gr_scheduler_sptr(new gr_scheduler_sts(ffg, max_noutput_items)); } -gr_scheduler_sts::gr_scheduler_sts(gr_flat_flowgraph_sptr ffg) - : gr_scheduler(ffg) +gr_scheduler_sts::gr_scheduler_sts(gr_flat_flowgraph_sptr ffg, int max_noutput_items) + : gr_scheduler(ffg, max_noutput_items) { // Split the flattened flow graph into discrete partitions, each // of which is topologically sorted. diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h index 9b73b68c1..08c68d88a 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h @@ -39,10 +39,10 @@ protected: * The scheduler will continue running until all blocks until they * report that they are done or the stop method is called. */ - gr_scheduler_sts(gr_flat_flowgraph_sptr ffg); + gr_scheduler_sts(gr_flat_flowgraph_sptr ffg, int max_noutput_items); public: - static gr_scheduler_sptr make(gr_flat_flowgraph_sptr ffg); + static gr_scheduler_sptr make(gr_flat_flowgraph_sptr ffg, int max_noutput_items); ~gr_scheduler_sts(); diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc index af0338570..0a7ff4556 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc @@ -33,25 +33,27 @@ class tpb_container { gr_block_sptr d_block; + int d_max_noutput_items; public: - tpb_container(gr_block_sptr block) : d_block(block) {} + tpb_container(gr_block_sptr block, int max_noutput_items) + : d_block(block), d_max_noutput_items(max_noutput_items) {} void operator()() { - gr_tpb_thread_body body(d_block); + gr_tpb_thread_body body(d_block, d_max_noutput_items); } }; gr_scheduler_sptr -gr_scheduler_tpb::make(gr_flat_flowgraph_sptr ffg) +gr_scheduler_tpb::make(gr_flat_flowgraph_sptr ffg, int max_noutput_items) { - return gr_scheduler_sptr(new gr_scheduler_tpb(ffg)); + return gr_scheduler_sptr(new gr_scheduler_tpb(ffg, max_noutput_items)); } -gr_scheduler_tpb::gr_scheduler_tpb(gr_flat_flowgraph_sptr ffg) - : gr_scheduler(ffg) +gr_scheduler_tpb::gr_scheduler_tpb(gr_flat_flowgraph_sptr ffg, int max_noutput_items) + : gr_scheduler(ffg, max_noutput_items) { // Get a topologically sorted vector of all the blocks in use. // Being topologically sorted probably isn't going to matter, but @@ -73,7 +75,8 @@ gr_scheduler_tpb::gr_scheduler_tpb(gr_flat_flowgraph_sptr ffg) std::stringstream name; name << "thread-per-block[" << i << "]: " << blocks[i]; d_threads.create_thread( - gruel::thread_body_wrapper(tpb_container(blocks[i]), name.str())); + gruel::thread_body_wrapper(tpb_container(blocks[i], max_noutput_items), + name.str())); } } diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h index f97ab2e7f..ab74fa84d 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h @@ -39,10 +39,10 @@ protected: * 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); + gr_scheduler_tpb(gr_flat_flowgraph_sptr ffg, int max_noutput_items); public: - static gr_scheduler_sptr make(gr_flat_flowgraph_sptr ffg); + static gr_scheduler_sptr make(gr_flat_flowgraph_sptr ffg, int max_noutput_items=100000); ~gr_scheduler_tpb(); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index f341525c0..55e4bb895 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -54,9 +54,9 @@ gr_top_block::~gr_top_block() } void -gr_top_block::start() +gr_top_block::start(int max_noutput_items) { - d_impl->start(); + d_impl->start(max_noutput_items); } void @@ -96,6 +96,18 @@ gr_top_block::dump() d_impl->dump(); } +int +gr_top_block::max_noutput_items() +{ + return d_impl->max_noutput_items(); +} + +void +gr_top_block::set_max_noutput_items(int nmax) +{ + d_impl->set_max_noutput_items(nmax); +} + gr_top_block_sptr gr_top_block::to_top_block() { diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index fca68ae71..f01372fc2 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -61,8 +61,13 @@ public: * execute the flow graph. Returns to the caller once the threads * are created. Calling start() on a top_block that is already * started IS an error. + * + * \param max_noutput_items the maximum number of output items + * allowed for any block in the flowgraph; the noutput_items can + * always be less than this, but this will cap it as a maximum. Use + * this to adjust the maximum latency a flowgraph can exhibit. */ - void start(); + void start(int max_noutput_items=100000); /*! * Stop the running flowgraph. Notifies each thread created by the @@ -107,6 +112,12 @@ public: */ void dump(); + //! Get the number of max noutput_items in the flowgraph + int max_noutput_items(); + + //! Set the maximum number of noutput_items in the flowgraph + void set_max_noutput_items(int nmax); + gr_top_block_sptr to_top_block(); // Needed for Python/Guile type coercion }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 90fa18b94..70c627ffd 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -40,7 +40,7 @@ private: public: ~gr_top_block(); - void start() throw (std::runtime_error); + void start(int max_noutput_items=100000) throw (std::runtime_error); void stop(); //void wait(); //void run() throw (std::runtime_error); @@ -48,6 +48,9 @@ public: void unlock() throw (std::runtime_error); void dump(); + int max_noutput_items(); + void set_max_noutput_items(int nmax); + gr_top_block_sptr to_top_block(); // Needed for Python/Guile type coercion }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 9cad687fb..0227d789c 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -39,7 +39,8 @@ #define GR_TOP_BLOCK_IMPL_DEBUG 0 -typedef gr_scheduler_sptr (*scheduler_maker)(gr_flat_flowgraph_sptr ffg); +typedef gr_scheduler_sptr (*scheduler_maker)(gr_flat_flowgraph_sptr ffg, + int max_noutput_items); static struct scheduler_table { const char *name; @@ -50,7 +51,7 @@ static struct scheduler_table { }; static gr_scheduler_sptr -make_scheduler(gr_flat_flowgraph_sptr ffg) +make_scheduler(gr_flat_flowgraph_sptr ffg, int max_noutput_items) { static scheduler_maker factory = 0; @@ -72,7 +73,7 @@ make_scheduler(gr_flat_flowgraph_sptr ffg) } } } - return factory(ffg); + return factory(ffg, max_noutput_items); } @@ -88,10 +89,12 @@ gr_top_block_impl::~gr_top_block_impl() } void -gr_top_block_impl::start() +gr_top_block_impl::start(int max_noutput_items) { gruel::scoped_lock l(d_mutex); + d_max_noutput_items = max_noutput_items; + if (d_state != IDLE) throw std::runtime_error("top_block::start: top block already running or wait() not called after previous stop()"); @@ -105,7 +108,7 @@ gr_top_block_impl::start() d_ffg->validate(); d_ffg->setup_connections(); - d_scheduler = make_scheduler(d_ffg); + d_scheduler = make_scheduler(d_ffg, d_max_noutput_items); d_state = RUNNING; } @@ -168,7 +171,7 @@ gr_top_block_impl::restart() d_ffg = new_ffg; // Create a new scheduler to execute it - d_scheduler = make_scheduler(d_ffg); + d_scheduler = make_scheduler(d_ffg, d_max_noutput_items); d_state = RUNNING; } @@ -178,3 +181,15 @@ gr_top_block_impl::dump() if (d_ffg) d_ffg->dump(); } + +int +gr_top_block_impl::max_noutput_items() +{ + return d_max_noutput_items; +} + +void +gr_top_block_impl::set_max_noutput_items(int nmax) +{ + d_max_noutput_items = nmax; +} diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index 904443be5..d804e3f30 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -42,7 +42,7 @@ public: ~gr_top_block_impl(); // Create and start scheduler threads - void start(); + void start(int max_noutput_items=100000); // Signal scheduler threads to stop void stop(); @@ -58,6 +58,12 @@ public: // Dump the flowgraph to stdout void dump(); + + // Get the number of max noutput_items in the flowgraph + int max_noutput_items(); + + // Set the maximum number of noutput_items in the flowgraph + void set_max_noutput_items(int nmax); protected: @@ -70,6 +76,7 @@ protected: gruel::mutex d_mutex; // protects d_state and d_lock_count tb_state d_state; int d_lock_count; + int d_max_noutput_items; private: void restart(); diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index faa888697..d44c09aa6 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -28,8 +28,8 @@ using namespace pmt; -gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) - : d_exec(block) +gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_items) + : d_exec(block, max_noutput_items) { // std::cerr << "gr_tpb_thread_body: " << block << std::endl; diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h index 548cfedfb..3170b402e 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h @@ -38,7 +38,7 @@ class GR_CORE_API gr_tpb_thread_body { gr_block_executor d_exec; public: - gr_tpb_thread_body(gr_block_sptr block); + gr_tpb_thread_body(gr_block_sptr block, int max_noutput_items=100000); ~gr_tpb_thread_body(); }; -- cgit From 10d65867b80f796da27c82443734cc20e99b672e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 2 Jan 2012 19:27:29 -0500 Subject: scheduler: if the block is an interpolator that needs a minimum of some number of outputs based on the inputs, let it. This is an acceptable (actually, necessary) exception to the specified limit. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 0403ce138..ef53baf78 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -182,6 +182,7 @@ gr_block_executor::run_one_iteration() { int noutput_items; int max_items_avail; + int max_noutput_items = d_max_noutput_items; gr_block *m = d_block.get(); gr_block_detail *d = m->detail().get(); @@ -309,8 +310,11 @@ gr_block_executor::run_one_iteration() reqd_noutput_items = round_up(reqd_noutput_items, m->output_multiple()); if (reqd_noutput_items > 0 && reqd_noutput_items <= noutput_items) noutput_items = reqd_noutput_items; + + // if we need this many outputs, overrule the max_noutput_items setting + max_noutput_items = std::max(m->output_multiple(), max_noutput_items); } - noutput_items = std::min(noutput_items, d_max_noutput_items); + noutput_items = std::min(noutput_items, max_noutput_items); // ask the block how much input they need to produce noutput_items m->forecast (noutput_items, d_ninput_items_required); -- cgit From 0644c4bf65b35b6494553cd75623f65e8e4a4ba3 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 2 Jan 2012 19:50:35 -0500 Subject: scheduler: add default (large) max noutput_items to C++ run function. --- gnuradio-core/src/lib/runtime/gr_top_block.cc | 4 ++-- gnuradio-core/src/lib/runtime/gr_top_block.h | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 55e4bb895..56d1352cd 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -72,9 +72,9 @@ gr_top_block::wait() } void -gr_top_block::run() +gr_top_block::run(int max_noutput_items) { - start(); + start(max_noutput_items); wait(); } diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index f01372fc2..9d01ba3ef 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -53,8 +53,12 @@ public: * * Calls start() then wait(). Used to run a flowgraph that will stop * on its own, or when another thread will call stop(). + * + * \param max_noutput_items the maximum number of output items + * allowed for any block in the flowgraph. This passes through to + * the start function; see that function for more details. */ - void run(); + void run(int max_noutput_items=100000); /*! * Start the contained flowgraph. Creates one or more threads to -- cgit From 6ac7576d32b8be601843c871327856ebd2b965d6 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 22 Jan 2012 17:44:04 -0500 Subject: sched: first attempt at working with aligned data sets. A block has an indicator on whether or not the buffers are aligned; they can use this to determine which Volk function to use or if to use Volk at all. --- gnuradio-core/src/lib/runtime/gr_block.cc | 30 ++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 28 +++++++++++++++ gnuradio-core/src/lib/runtime/gr_block_executor.cc | 41 ++++++++++++++++++++-- 3 files changed, 96 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 9463869f5..78f77486b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -34,6 +34,9 @@ gr_block::gr_block (const std::string &name, gr_io_signature_sptr output_signature) : gr_basic_block(name, input_signature, output_signature), d_output_multiple (1), + d_output_multiple_set(false), + d_unaligned(0), + d_is_unaligned(false), d_relative_rate (1.0), d_history(1), d_fixed_rate(false), @@ -75,9 +78,36 @@ gr_block::set_output_multiple (int multiple) if (multiple < 1) throw std::invalid_argument ("gr_block::set_output_multiple"); + d_output_multiple_set = true; d_output_multiple = multiple; } +void +gr_block::set_alignment (int multiple) +{ + if (multiple < 1) + throw std::invalid_argument ("gr_block::set_alignment_multiple"); + + d_output_multiple = multiple; +} + +void +gr_block::set_unaligned (int na) +{ + // unaligned value must be less than 0 and it doesn't make sense + // that it's larger than the alignment value. + if ((na < 0) || (na > d_output_multiple)) + throw std::invalid_argument ("gr_block::set_unaligned"); + + d_unaligned = na; +} + +void +gr_block::set_is_unaligned (bool u) +{ + d_is_unaligned = u; +} + void gr_block::set_relative_rate (double relative_rate) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 86e0583e9..9171942e0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -152,7 +152,32 @@ class GR_CORE_API gr_block : public gr_basic_block { */ void set_output_multiple (int multiple); int output_multiple () const { return d_output_multiple; } + bool output_multiple_set () const { return d_output_multiple_set; } + /*! + * \brief Constrains buffers to work on a set item alignment (for SIMD) + * + * set_alignment_multiple causes the scheduler to ensure that the noutput_items + * argument passed to forecast and general_work will be an integer multiple + * of \param multiple The default value is 1. + * + * This control is similar to the output_multiple setting, except + * that if the number of items passed to the block is less than the + * output_multiple, this value is ignored and the block can produce + * like normal. The d_unaligned value is set to the number of items + * the block is off by. In the next call to general_work, the + * noutput_items is set to d_unaligned or less until + * d_unaligned==0. The buffers are now aligned again and the aligned + * calls can be performed again. + */ + void set_alignment (int multiple); + int alignment () const { return d_output_multiple; } + + void set_unaligned (int na); + int unaligned () const { return d_unaligned; } + void set_is_unaligned (bool u); + bool is_unaligned () const { return d_is_unaligned; } + /*! * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed. */ @@ -231,6 +256,9 @@ class GR_CORE_API gr_block : public gr_basic_block { private: int d_output_multiple; + bool d_output_multiple_set; + int d_unaligned; + bool d_is_unaligned; double d_relative_rate; // approx output_rate / input_rate gr_block_detail_sptr d_detail; // implementation details unsigned d_history; diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index ef53baf78..1c52c0e13 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -36,7 +36,7 @@ #include // must be defined to either 0 or 1 -#define ENABLE_LOGGING 0 +#define ENABLE_LOGGING 1 #if (ENABLE_LOGGING) #define LOG(x) do { x; } while(0) @@ -183,6 +183,7 @@ gr_block_executor::run_one_iteration() int noutput_items; int max_items_avail; int max_noutput_items = d_max_noutput_items; + int new_alignment; gr_block *m = d_block.get(); gr_block_detail *d = m->detail().get(); @@ -284,7 +285,7 @@ gr_block_executor::run_one_iteration() } // determine the minimum available output space - noutput_items = min_available_space (d, m->output_multiple ()); + noutput_items = min_available_space (d, m->output_multiple ()) - m->output_multiple(); if (ENABLE_LOGGING){ *d_log << " regular "; if (m->relative_rate() >= 1.0) @@ -307,7 +308,11 @@ gr_block_executor::run_one_iteration() // try to work it forward starting with max_items_avail. // We want to try to consume all the input we've got. int reqd_noutput_items = m->fixed_rate_ninput_to_noutput(max_items_avail); - reqd_noutput_items = round_up(reqd_noutput_items, m->output_multiple()); + + // only test this if we specifically set the output_multiple + if(m->output_multiple_set()) + reqd_noutput_items = round_up(reqd_noutput_items, m->output_multiple()); + if (reqd_noutput_items > 0 && reqd_noutput_items <= noutput_items) noutput_items = reqd_noutput_items; @@ -316,6 +321,30 @@ gr_block_executor::run_one_iteration() } noutput_items = std::min(noutput_items, max_noutput_items); + // Check if we're still unaligned; only use up items until we're + // aligned again. Otherwise, make sure we set the alignment + // requirement. + if(m->is_unaligned()) { + if(noutput_items >= m->unaligned()) { + noutput_items = round_up(noutput_items, m->alignment()) \ + - (m->alignment() - m->unaligned()); + new_alignment = 0; + } + else { + new_alignment = m->unaligned() - noutput_items; + } + } + else if(noutput_items < m->alignment()) { + //m->set_unaligned(m->alignment()); + new_alignment = m->alignment() - noutput_items; + m->set_unaligned(new_alignment); + m->set_is_unaligned(true); + } + else { + noutput_items = round_down(noutput_items, m->alignment()); + m->set_is_unaligned(false); + } + // ask the block how much input they need to produce noutput_items m->forecast (noutput_items, d_ninput_items_required); @@ -379,6 +408,12 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); + // Adjust number of unaligned items left to process + if(m->is_unaligned()) { + m->set_unaligned(new_alignment); + m->set_is_unaligned(m->unaligned() != 0); + } + if(!propagate_tags(m->tag_propagation_policy(), d, d_start_nitems_read, m->relative_rate(), d_returned_tags)) -- cgit From 06f40e8dbef0b082e23703bc22775ec3458faf5b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 22 Jan 2012 17:51:13 -0500 Subject: sched: forgot to turn debugging off. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 1c52c0e13..350518e4c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -36,7 +36,7 @@ #include // must be defined to either 0 or 1 -#define ENABLE_LOGGING 1 +#define ENABLE_LOGGING 0 #if (ENABLE_LOGGING) #define LOG(x) do { x; } while(0) -- cgit From 09be95bb8da5f41aff2fd2207fcdb6bb8f92c8cf Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 23 Jan 2012 16:41:32 -0500 Subject: sched: better comments. Handling of noutput_items adjustment done better and documented. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 350518e4c..3191246a7 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -36,7 +36,7 @@ #include // must be defined to either 0 or 1 -#define ENABLE_LOGGING 0 +#define ENABLE_LOGGING 1 #if (ENABLE_LOGGING) #define LOG(x) do { x; } while(0) @@ -83,6 +83,11 @@ min_available_space (gr_block_detail *d, int output_multiple) } return 0; } + else if (n > output_multiple) { + // adjust this or we often ask for too many, + // causing a re-calc for fewer items. + n = n-output_multiple; + } min_space = std::min (min_space, n); } return min_space; @@ -285,7 +290,7 @@ gr_block_executor::run_one_iteration() } // determine the minimum available output space - noutput_items = min_available_space (d, m->output_multiple ()) - m->output_multiple(); + noutput_items = min_available_space (d, m->output_multiple ()); if (ENABLE_LOGGING){ *d_log << " regular "; if (m->relative_rate() >= 1.0) @@ -321,10 +326,14 @@ gr_block_executor::run_one_iteration() } noutput_items = std::min(noutput_items, max_noutput_items); - // Check if we're still unaligned; only use up items until we're + // Check if we're still unaligned; use up items until we're // aligned again. Otherwise, make sure we set the alignment // requirement. if(m->is_unaligned()) { + // When unaligned, don't just set noutput_items to the remaining + // samples to meet alignment; this causes too much overhead in + // requiring a premature call back here. Set the maximum amount + // of samples to handle unalignment and get us back aligned. if(noutput_items >= m->unaligned()) { noutput_items = round_up(noutput_items, m->alignment()) \ - (m->alignment() - m->unaligned()); @@ -335,12 +344,14 @@ gr_block_executor::run_one_iteration() } } else if(noutput_items < m->alignment()) { - //m->set_unaligned(m->alignment()); + // if we don't have enough for an aligned call, keep track of + // misalignment, set unaligned flag, and proceed. new_alignment = m->alignment() - noutput_items; m->set_unaligned(new_alignment); m->set_is_unaligned(true); } else { + // enough to round down to the nearest alignment and process. noutput_items = round_down(noutput_items, m->alignment()); m->set_is_unaligned(false); } -- cgit From 83d0bf5d513e516d700e552fa2773dd852a6608a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 29 Jan 2012 17:35:09 -0500 Subject: core: minor edits. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 3191246a7..02bb4873c 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -36,7 +36,7 @@ #include // must be defined to either 0 or 1 -#define ENABLE_LOGGING 1 +#define ENABLE_LOGGING 0 #if (ENABLE_LOGGING) #define LOG(x) do { x; } while(0) -- cgit From c6519775ac7d1e9098ca2fb20c09e15ae8e60a4a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 2 Feb 2012 16:34:23 -0500 Subject: sched: better working alignment handling. Works with max_noutput_items and set_output_multiple. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 53 ++++++++++------------ 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 02bb4873c..11c6639b3 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -83,11 +83,6 @@ min_available_space (gr_block_detail *d, int output_multiple) } return 0; } - else if (n > output_multiple) { - // adjust this or we often ask for too many, - // causing a re-calc for fewer items. - n = n-output_multiple; - } min_space = std::min (min_space, n); } return min_space; @@ -316,7 +311,7 @@ gr_block_executor::run_one_iteration() // only test this if we specifically set the output_multiple if(m->output_multiple_set()) - reqd_noutput_items = round_up(reqd_noutput_items, m->output_multiple()); + reqd_noutput_items = round_down(reqd_noutput_items, m->output_multiple()); if (reqd_noutput_items > 0 && reqd_noutput_items <= noutput_items) noutput_items = reqd_noutput_items; @@ -329,32 +324,34 @@ gr_block_executor::run_one_iteration() // Check if we're still unaligned; use up items until we're // aligned again. Otherwise, make sure we set the alignment // requirement. - if(m->is_unaligned()) { - // When unaligned, don't just set noutput_items to the remaining - // samples to meet alignment; this causes too much overhead in - // requiring a premature call back here. Set the maximum amount - // of samples to handle unalignment and get us back aligned. - if(noutput_items >= m->unaligned()) { - noutput_items = round_up(noutput_items, m->alignment()) \ - - (m->alignment() - m->unaligned()); - new_alignment = 0; + if(!m->output_multiple_set()) { + if(m->is_unaligned()) { + // When unaligned, don't just set noutput_items to the remaining + // samples to meet alignment; this causes too much overhead in + // requiring a premature call back here. Set the maximum amount + // of samples to handle unalignment and get us back aligned. + if(noutput_items >= m->unaligned()) { + noutput_items = round_up(noutput_items, m->alignment()) \ + - (m->alignment() - m->unaligned()); + new_alignment = 0; + } + else { + new_alignment = m->unaligned() - noutput_items; + } + } + else if(noutput_items < m->alignment()) { + // if we don't have enough for an aligned call, keep track of + // misalignment, set unaligned flag, and proceed. + new_alignment = m->alignment() - noutput_items; + m->set_unaligned(new_alignment); + m->set_is_unaligned(true); } else { - new_alignment = m->unaligned() - noutput_items; + // enough to round down to the nearest alignment and process. + noutput_items = round_down(noutput_items, m->alignment()); + m->set_is_unaligned(false); } } - else if(noutput_items < m->alignment()) { - // if we don't have enough for an aligned call, keep track of - // misalignment, set unaligned flag, and proceed. - new_alignment = m->alignment() - noutput_items; - m->set_unaligned(new_alignment); - m->set_is_unaligned(true); - } - else { - // enough to round down to the nearest alignment and process. - noutput_items = round_down(noutput_items, m->alignment()); - m->set_is_unaligned(false); - } // ask the block how much input they need to produce noutput_items m->forecast (noutput_items, d_ninput_items_required); -- cgit From 3a21ccb8cdef50daa52f5d26293df3a03c821c99 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 4 Feb 2012 11:03:40 -0500 Subject: sched: some added protections and checks for the alignment states. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 11c6639b3..86289695a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -183,7 +183,8 @@ gr_block_executor::run_one_iteration() int noutput_items; int max_items_avail; int max_noutput_items = d_max_noutput_items; - int new_alignment; + int new_alignment=0; + int alignment_state=-1; gr_block *m = d_block.get(); gr_block_detail *d = m->detail().get(); @@ -338,6 +339,7 @@ gr_block_executor::run_one_iteration() else { new_alignment = m->unaligned() - noutput_items; } + alignment_state = 0; } else if(noutput_items < m->alignment()) { // if we don't have enough for an aligned call, keep track of @@ -345,11 +347,13 @@ gr_block_executor::run_one_iteration() new_alignment = m->alignment() - noutput_items; m->set_unaligned(new_alignment); m->set_is_unaligned(true); + alignment_state = 1; } else { // enough to round down to the nearest alignment and process. noutput_items = round_down(noutput_items, m->alignment()); m->set_is_unaligned(false); + alignment_state = 2; } } @@ -391,6 +395,12 @@ gr_block_executor::run_one_iteration() goto were_done; } + // If we were made unaligned in this round but return here without + // processing; reset the unalignment claim before next entry. + if(alignment_state == 1) { + m->set_unaligned(0); + m->set_is_unaligned(false); + } return BLKD_IN; } -- cgit From 63b05200220bc2059259af089be0b562de6a19b4 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sun, 26 Feb 2012 15:28:33 -0800 Subject: core: add null constructors to sync_* blocks --- gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 2 +- gnuradio-core/src/lib/runtime/gr_sync_interpolator.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h index b2ed3c4fe..7228d3655 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -38,7 +38,7 @@ class GR_CORE_API gr_sync_decimator : public gr_sync_block unsigned d_decimation; protected: - + gr_sync_decimator (void){} //allows pure virtual interface sub-classes gr_sync_decimator (const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index d65b3da1e..c332a5272 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -38,6 +38,7 @@ class GR_CORE_API gr_sync_interpolator : public gr_sync_block unsigned d_interpolation; protected: + gr_sync_interpolator (void){} //allows pure virtual interface sub-classes gr_sync_interpolator (const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature, -- cgit From f9a07338b9c7c0af19d64d24c47eaa9f7fe1ba38 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 16 Mar 2012 13:09:23 -0700 Subject: gruel: created common swig include file This work taken from gruel_work_squashed Common swig file includes: * Language independent exception handler * Wrapper for python calls that may block Benefits: * More common swig code, less copy pasta * Wrapper for blocking python calls handles the case where the call throws, python is not left in a bad state --- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index c9214bef3..0a4eda78a 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005,2009,2010 Free Software Foundation, Inc. + * Copyright 2005,2009,2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -85,16 +85,16 @@ public: %inline %{ gr_message_sptr gr_py_msg_queue__delete_head(gr_msg_queue_sptr q) { gr_message_sptr msg; - Py_BEGIN_ALLOW_THREADS; // release global interpreter lock - msg = q->delete_head(); // possibly blocking call - Py_END_ALLOW_THREADS; // acquire global interpreter lock + GR_PYTHON_BLOCKING_CODE( + msg = q->delete_head(); + ) return msg; } void gr_py_msg_queue__insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg) { - Py_BEGIN_ALLOW_THREADS; // release global interpreter lock - q->insert_tail(msg); // possibly blocking call - Py_END_ALLOW_THREADS; // acquire global interpreter lock + GR_PYTHON_BLOCKING_CODE( + q->insert_tail(msg); + ) } %} -- cgit From 6e379955cdd9803cb6b083bd72e7acfa494d6757 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 18 Mar 2012 01:33:57 -0700 Subject: core: empty gr_hier_block2 contructor for virtual inheritance --- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 1 + 1 file changed, 1 insertion(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 8687b7d99..9652f6bf4 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -55,6 +55,7 @@ private: gr_hier_block2_detail *d_detail; protected: + gr_hier_block2 (void){} //allows pure virtual interface sub-classes gr_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); -- cgit From 170c4ba4b39889073b2a3f129e77ca9b2f91bbf2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 27 Mar 2012 14:14:03 -0400 Subject: core: when reseting buffers, make sure that the read/write pointers are always algined. This fixes problems when disconnecting and reconnecting blocks to a flowgraph. --- gnuradio-core/src/lib/runtime/gr_buffer.h | 3 +++ gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 23 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index e8e393756..9478e1ce0 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -93,6 +93,7 @@ class GR_CORE_API gr_buffer { uint64_t nitems_written() { return d_abs_write_offset; } + size_t get_sizeof_item() { return d_sizeof_item; } /*! * \brief Adds a new tag to the buffer. @@ -249,6 +250,8 @@ class GR_CORE_API gr_buffer_reader { uint64_t nitems_read() { return d_abs_read_offset; } + size_t get_sizeof_item() { return d_buffer->get_sizeof_item(); } + /*! * \brief Return the block that reads via this reader. * diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 5d1057e0f..e97fa13a4 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -243,6 +244,28 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "new block" << std::endl; connect_block_inputs(block); + + const int alignment = volk_get_alignment(); + for(int i = 0; i < block->detail()->ninputs(); i++) { + void *r = (void*)block->detail()->input(i)->read_pointer(); + unsigned long int ri = (unsigned long int)r % alignment; + if(ri != 0) { + size_t itemsize = block->detail()->input(i)->get_sizeof_item(); + block->detail()->input(i)->update_read_pointer(ri/itemsize); + block->set_unaligned(0); + block->set_is_unaligned(false); + } + } + for(int i = 0; i < block->detail()->noutputs(); i++) { + void *w = (void*)block->detail()->output(i)->write_pointer(); + unsigned long int wi = (unsigned long int)w % alignment; + if(wi != 0) { + size_t itemsize = block->detail()->output(i)->get_sizeof_item(); + block->detail()->output(i)->update_write_pointer(wi/itemsize); + block->set_unaligned(0); + block->set_is_unaligned(false); + } + } } // Now deal with the fact that the block details might have changed numbers of -- cgit From 2bf64459036916258dcf3269cec47904fdeba8f6 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 1 Apr 2012 16:13:42 -0400 Subject: Removes all references to guile and scheme, which are no longer needed. The remaining pmt_serial_tags.scm is parsed by Python already. Future modifications could change this format to not confuse the point. --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 2 +- gnuradio-core/src/lib/runtime/gr_hier_block2.i | 2 +- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 61 -------------------------- gnuradio-core/src/lib/runtime/gr_top_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_top_block.i | 33 +------------- 6 files changed, 5 insertions(+), 97 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 2adca8ccb..7e95509e2 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -103,7 +103,7 @@ public: std::string name() const { return d_name; } gr_io_signature_sptr input_signature() const { return d_input_signature; } gr_io_signature_sptr output_signature() const { return d_output_signature; } - gr_basic_block_sptr to_basic_block(); // Needed for Python/Guile type coercion + gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion /*! * \brief Confirm that ninputs and noutputs is an acceptable combination. diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 9652f6bf4..12bcf10e7 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -150,7 +150,7 @@ public: // ignored by the user. gr_flat_flowgraph_sptr flatten() const; - gr_hier_block2_sptr to_hier_block2(); // Needed for Python/Guile type coercion + gr_hier_block2_sptr to_hier_block2(); // Needed for Python type coercion }; inline gr_hier_block2_sptr cast_to_hier_block2_sptr(gr_basic_block_sptr block) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index 32b656e24..4fa7c3bc0 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -63,5 +63,5 @@ public: void lock(); void unlock(); - gr_hier_block2_sptr to_hier_block2(); // Needed for Python/Guile type coercion + gr_hier_block2_sptr to_hier_block2(); // Needed for Python type coercion }; diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 0a4eda78a..2a78253b3 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -105,64 +105,3 @@ gr_msg_queue_sptr.insert_tail = gr_py_msg_queue__insert_tail gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail %} #endif // SWIGPYTHON - -/* - * Similar trickery as above, only this time for Guile - */ -#ifdef SWIGGUILE - -%{ - struct arg_holder { - gr_msg_queue_sptr q; - gr_message_sptr msg; - }; - - static void * - insert_tail_shim(void *arg) - { - arg_holder *a = (arg_holder *)arg; - a->q->insert_tail(a->msg); - return 0; - } - - static void * - delete_head_shim(void *arg) - { - arg_holder *a = (arg_holder *)arg; - a->msg = a->q->delete_head(); - return 0; - } -%} - -%inline %{ - - // handle and insert_tail are equivalent - static void - handle(gr_msg_queue_sptr q, gr_message_sptr msg) - { - arg_holder a; - a.q = q; - a.msg = msg; - scm_without_guile(insert_tail_shim, (void *) &a); - } - - static void - insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg) - { - arg_holder a; - a.q = q; - a.msg = msg; - scm_without_guile(insert_tail_shim, (void *) &a); - } - - static gr_message_sptr - delete_head(gr_msg_queue_sptr q) - { - arg_holder a; - a.q = q; - scm_without_guile(delete_head_shim, (void *) &a); - return a.msg; - } -%} - -#endif // SWIGGUILE diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 9d01ba3ef..e837700c3 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -122,7 +122,7 @@ public: //! Set the maximum number of noutput_items in the flowgraph void set_max_noutput_items(int nmax); - gr_top_block_sptr to_top_block(); // Needed for Python/Guile type coercion + gr_top_block_sptr to_top_block(); // Needed for Python type coercion }; inline gr_top_block_sptr cast_to_top_block_sptr(gr_basic_block_sptr block) { diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 70c627ffd..ea5534c17 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -51,7 +51,7 @@ public: int max_noutput_items(); void set_max_noutput_items(int nmax); - gr_top_block_sptr to_top_block(); // Needed for Python/Guile type coercion + gr_top_block_sptr to_top_block(); // Needed for Python type coercion }; #ifdef SWIGPYTHON @@ -73,34 +73,3 @@ void top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error) %} #endif - -#ifdef SWIGGUILE - -%{ - struct tb_arg_holder { - gr_top_block_sptr tb; - }; - - static void * - tb_wait_shim(void *arg) - { - tb_arg_holder *a = (tb_arg_holder *)arg; - a->tb->wait(); - return 0; - } - -%} - -%inline %{ - - static void - top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error) - { - tb_arg_holder a; - a.tb = r; - scm_without_guile(tb_wait_shim, (void *) &a); - } - -%} - -#endif -- cgit From 7713fca68219539e814e70f0e2302f55d645c5fa Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 7 Apr 2012 14:39:26 -0400 Subject: core: makes sure all block's buffers are aligned on start/restart and that they know it. --- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 59 ++++++++++++++-------- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 9 ++++ 2 files changed, 46 insertions(+), 22 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index e97fa13a4..adb1f5608 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -63,8 +63,13 @@ gr_flat_flowgraph::setup_connections() cast_to_block_sptr(*p)->set_detail(allocate_block_detail(*p)); // Connect inputs to outputs for each block - for(gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) + for(gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { connect_block_inputs(*p); + + gr_block_sptr block = cast_to_block_sptr(*p); + setup_buffer_alignment(block); + } + } gr_block_detail_sptr @@ -245,27 +250,8 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) std::cout << "new block" << std::endl; connect_block_inputs(block); - const int alignment = volk_get_alignment(); - for(int i = 0; i < block->detail()->ninputs(); i++) { - void *r = (void*)block->detail()->input(i)->read_pointer(); - unsigned long int ri = (unsigned long int)r % alignment; - if(ri != 0) { - size_t itemsize = block->detail()->input(i)->get_sizeof_item(); - block->detail()->input(i)->update_read_pointer(ri/itemsize); - block->set_unaligned(0); - block->set_is_unaligned(false); - } - } - for(int i = 0; i < block->detail()->noutputs(); i++) { - void *w = (void*)block->detail()->output(i)->write_pointer(); - unsigned long int wi = (unsigned long int)w % alignment; - if(wi != 0) { - size_t itemsize = block->detail()->output(i)->get_sizeof_item(); - block->detail()->output(i)->update_write_pointer(wi/itemsize); - block->set_unaligned(0); - block->set_is_unaligned(false); - } - } + // Make sure all buffers are aligned + setup_buffer_alignment(block); } // Now deal with the fact that the block details might have changed numbers of @@ -273,6 +259,35 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) } } +void +gr_flat_flowgraph::setup_buffer_alignment(gr_block_sptr block) +{ + const int alignment = volk_get_alignment(); + for(int i = 0; i < block->detail()->ninputs(); i++) { + void *r = (void*)block->detail()->input(i)->read_pointer(); + unsigned long int ri = (unsigned long int)r % alignment; + //std::cout << "reader: " << r << " alignment: " << ri << std::endl; + if(ri != 0) { + size_t itemsize = block->detail()->input(i)->get_sizeof_item(); + block->detail()->input(i)->update_read_pointer(ri/itemsize); + } + block->set_unaligned(0); + block->set_is_unaligned(false); + } + + for(int i = 0; i < block->detail()->noutputs(); i++) { + void *w = (void*)block->detail()->output(i)->write_pointer(); + unsigned long int wi = (unsigned long int)w % alignment; + size_t itemsize = block->detail()->output(i)->get_sizeof_item(); + //std::cout << "writer: " << w << " alignment: " << wi << std::endl; + if(wi != 0) { + block->detail()->output(i)->update_write_pointer(wi/itemsize); + } + block->set_unaligned(0); + block->set_is_unaligned(false); + } +} + void gr_flat_flowgraph::dump() { for (gr_edge_viter_t e = d_edges.begin(); e != d_edges.end(); e++) diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h index 2cc883686..ce863509b 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h @@ -63,6 +63,15 @@ private: gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block); gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port); void connect_block_inputs(gr_basic_block_sptr block); + + /* When reusing a flowgraph's blocks, this call makes sure all of the + * buffer's are aligned at the machine's alignment boundary and tells + * the blocks that they are aligned. + * + * Called from both setup_connections and merge_connections for + * start and restarts. + */ + void setup_buffer_alignment(gr_block_sptr block); }; #endif /* INCLUDED_GR_FLAT_FLOWGRAPH_H */ -- cgit From fdb41fe3399c2282b31297e65f7a020bf844282d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 7 Apr 2012 16:34:25 -0400 Subject: core: buffer alignments were getting confused. Just need to tell all blocks that they are aligned upon restart. --- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index adb1f5608..5c9e4bf3f 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -66,8 +66,9 @@ gr_flat_flowgraph::setup_connections() for(gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { connect_block_inputs(*p); - gr_block_sptr block = cast_to_block_sptr(*p); - setup_buffer_alignment(block); + gr_block_sptr block = cast_to_block_sptr(*p); + block->set_unaligned(0); + block->set_is_unaligned(false); } } -- cgit From f919f9dcbb54a08e6e26d6c229ce92fb784fa1b2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 13 Apr 2012 18:36:53 -0400 Subject: Removed whitespace and added dtools/bin/remove-whitespace as a tool to do this in the future. The sed script was provided by Moritz Fischer. --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 8 ++-- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 16 ++++---- gnuradio-core/src/lib/runtime/gr_basic_block.h | 10 ++--- gnuradio-core/src/lib/runtime/gr_basic_block.i | 8 ++-- gnuradio-core/src/lib/runtime/gr_block.cc | 20 +++++----- gnuradio-core/src/lib/runtime/gr_block.h | 26 ++++++------- gnuradio-core/src/lib/runtime/gr_block.i | 12 +++--- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 16 ++++---- gnuradio-core/src/lib/runtime/gr_block_detail.h | 10 ++--- gnuradio-core/src/lib/runtime/gr_block_detail.i | 8 ++-- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 20 +++++----- gnuradio-core/src/lib/runtime/gr_block_executor.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_buffer.cc | 18 ++++----- gnuradio-core/src/lib/runtime/gr_buffer.h | 20 +++++----- gnuradio-core/src/lib/runtime/gr_buffer.i | 10 ++--- gnuradio-core/src/lib/runtime/gr_complex.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_dispatcher.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_dispatcher.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_dispatcher.i | 8 ++-- gnuradio-core/src/lib/runtime/gr_error_handler.cc | 14 +++---- gnuradio-core/src/lib/runtime/gr_error_handler.h | 10 ++--- gnuradio-core/src/lib/runtime/gr_error_handler.i | 8 ++-- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 26 ++++++------- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 10 ++--- gnuradio-core/src/lib/runtime/gr_flowgraph.cc | 32 ++++++++-------- gnuradio-core/src/lib/runtime/gr_flowgraph.h | 14 +++---- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 22 +++++------ gnuradio-core/src/lib/runtime/gr_hier_block2.h | 24 ++++++------ gnuradio-core/src/lib/runtime/gr_hier_block2.i | 12 +++--- .../src/lib/runtime/gr_hier_block2_detail.cc | 44 +++++++++++----------- .../src/lib/runtime/gr_hier_block2_detail.h | 16 ++++---- gnuradio-core/src/lib/runtime/gr_io_signature.cc | 16 ++++---- gnuradio-core/src/lib/runtime/gr_io_signature.h | 16 ++++---- gnuradio-core/src/lib/runtime/gr_io_signature.i | 16 ++++---- .../src/lib/runtime/gr_local_sighandler.cc | 10 ++--- .../src/lib/runtime/gr_local_sighandler.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_message.cc | 10 ++--- gnuradio-core/src/lib/runtime/gr_message.h | 12 +++--- gnuradio-core/src/lib/runtime/gr_message.i | 8 ++-- gnuradio-core/src/lib/runtime/gr_msg_accepter.cc | 10 ++--- gnuradio-core/src/lib/runtime/gr_msg_accepter.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_msg_handler.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_msg_handler.h | 10 ++--- gnuradio-core/src/lib/runtime/gr_msg_handler.i | 10 ++--- gnuradio-core/src/lib/runtime/gr_msg_queue.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_msg_queue.h | 14 +++---- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 14 +++---- gnuradio-core/src/lib/runtime/gr_pagesize.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_pagesize.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_preferences.cc | 10 ++--- gnuradio-core/src/lib/runtime/gr_preferences.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_realtime.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_realtime.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_realtime.i | 8 ++-- gnuradio-core/src/lib/runtime/gr_runtime_types.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_scheduler.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_scheduler.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc | 10 ++--- gnuradio-core/src/lib/runtime/gr_scheduler_sts.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc | 10 ++--- gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_select_handler.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_select_handler.h | 10 ++--- .../lib/runtime/gr_single_threaded_scheduler.cc | 14 +++---- .../src/lib/runtime/gr_single_threaded_scheduler.h | 10 ++--- .../src/lib/runtime/gr_single_threaded_scheduler.i | 10 ++--- gnuradio-core/src/lib/runtime/gr_sptr_magic.cc | 10 ++--- gnuradio-core/src/lib/runtime/gr_sptr_magic.h | 12 +++--- gnuradio-core/src/lib/runtime/gr_sync_block.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_sync_block.h | 12 +++--- gnuradio-core/src/lib/runtime/gr_sync_block.i | 8 ++-- gnuradio-core/src/lib/runtime/gr_sync_decimator.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_sync_decimator.i | 8 ++-- .../src/lib/runtime/gr_sync_interpolator.cc | 8 ++-- .../src/lib/runtime/gr_sync_interpolator.h | 8 ++-- .../src/lib/runtime/gr_sync_interpolator.i | 8 ++-- gnuradio-core/src/lib/runtime/gr_sys_paths.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_sys_paths.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_tags.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_timer.h | 10 ++--- gnuradio-core/src/lib/runtime/gr_top_block.cc | 28 +++++++------- gnuradio-core/src/lib/runtime/gr_top_block.h | 14 +++---- gnuradio-core/src/lib/runtime/gr_top_block.i | 16 ++++---- gnuradio-core/src/lib/runtime/gr_top_block_impl.cc | 8 ++-- gnuradio-core/src/lib/runtime/gr_top_block_impl.h | 16 ++++---- gnuradio-core/src/lib/runtime/gr_tpb_detail.cc | 12 +++--- gnuradio-core/src/lib/runtime/gr_tpb_detail.h | 12 +++--- .../src/lib/runtime/gr_tpb_thread_body.cc | 16 ++++---- gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_types.h | 10 ++--- gnuradio-core/src/lib/runtime/gr_unittests.h | 8 ++-- gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc | 14 +++---- gnuradio-core/src/lib/runtime/gr_vmcircbuf.h | 12 +++--- .../src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc | 18 ++++----- .../src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h | 8 ++-- .../src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc | 14 +++---- .../src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h | 8 ++-- .../src/lib/runtime/gr_vmcircbuf_sysv_shm.cc | 10 ++--- .../src/lib/runtime/gr_vmcircbuf_sysv_shm.h | 8 ++-- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 22 +++++------ gnuradio-core/src/lib/runtime/qa_block_tags.h | 8 ++-- gnuradio-core/src/lib/runtime/qa_gr_block.cc | 8 ++-- gnuradio-core/src/lib/runtime/qa_gr_block.h | 8 ++-- gnuradio-core/src/lib/runtime/qa_gr_buffer.cc | 24 ++++++------ gnuradio-core/src/lib/runtime/qa_gr_buffer.h | 8 ++-- gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc | 10 ++--- gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h | 12 +++--- gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc | 12 +++--- gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h | 12 +++--- .../src/lib/runtime/qa_gr_hier_block2_derived.cc | 10 ++--- .../src/lib/runtime/qa_gr_hier_block2_derived.h | 10 ++--- .../src/lib/runtime/qa_gr_io_signature.cc | 8 ++-- gnuradio-core/src/lib/runtime/qa_gr_io_signature.h | 8 ++-- gnuradio-core/src/lib/runtime/qa_gr_top_block.cc | 8 ++-- gnuradio-core/src/lib/runtime/qa_gr_top_block.h | 12 +++--- gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc | 10 ++--- gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h | 8 ++-- gnuradio-core/src/lib/runtime/qa_runtime.cc | 10 ++--- gnuradio-core/src/lib/runtime/qa_runtime.h | 8 ++-- .../src/lib/runtime/qa_set_msg_handler.cc | 8 ++-- gnuradio-core/src/lib/runtime/qa_set_msg_handler.h | 12 +++--- gnuradio-core/src/lib/runtime/runtime.i | 8 ++-- .../src/lib/runtime/test_shared_block_ptr.cc | 14 +++---- 124 files changed, 726 insertions(+), 726 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 105fc0e06..1415ff4c6 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright 2010-2010 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 GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 0e0dad16b..d7263b92d 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -32,7 +32,7 @@ using namespace pmt; static long s_next_id = 0; static long s_ncurrently_allocated = 0; -long +long gr_basic_block_ncurrently_allocated() { return s_ncurrently_allocated; @@ -40,7 +40,7 @@ gr_basic_block_ncurrently_allocated() gr_basic_block::gr_basic_block(const std::string &name, gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature) + gr_io_signature_sptr output_signature) : d_name(name), d_input_signature(input_signature), d_output_signature(output_signature), @@ -49,13 +49,13 @@ gr_basic_block::gr_basic_block(const std::string &name, { s_ncurrently_allocated++; } - + gr_basic_block::~gr_basic_block() { s_ncurrently_allocated--; } -gr_basic_block_sptr +gr_basic_block_sptr gr_basic_block::to_basic_block() { return shared_from_this(); diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 7e95509e2..4d03b878e 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2008,2009,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -85,7 +85,7 @@ protected: void set_input_signature(gr_io_signature_sptr iosig) { d_input_signature = iosig; } - + //! may only be called during constructor void set_output_signature(gr_io_signature_sptr iosig) { d_output_signature = iosig; diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 03d4725d5..e43cc114c 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 78f77486b..9a5255a93 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2009,2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -43,7 +43,7 @@ gr_block::gr_block (const std::string &name, d_tag_propagation_policy(TPP_ALL_TO_ALL) { } - + gr_block::~gr_block () { } @@ -102,7 +102,7 @@ gr_block::set_unaligned (int na) d_unaligned = na; } -void +void gr_block::set_is_unaligned (bool u) { d_is_unaligned = u; @@ -113,7 +113,7 @@ gr_block::set_relative_rate (double relative_rate) { if (relative_rate < 0.0) throw std::invalid_argument ("gr_block::set_relative_rate"); - + d_relative_rate = relative_rate; } @@ -149,7 +149,7 @@ gr_block::fixed_rate_noutput_to_ninput(int noutput) } uint64_t -gr_block::nitems_read(unsigned int which_input) +gr_block::nitems_read(unsigned int which_input) { if(d_detail) { return d_detail->nitems_read(which_input); @@ -161,7 +161,7 @@ gr_block::nitems_read(unsigned int which_input) } uint64_t -gr_block::nitems_written(unsigned int which_output) +gr_block::nitems_written(unsigned int which_output) { if(d_detail) { return d_detail->nitems_written(which_output); @@ -186,7 +186,7 @@ gr_block::get_tags_in_range(std::vector &v, { d_detail->get_tags_in_range(v, which_output, start, end); } - + void gr_block::get_tags_in_range(std::vector &v, unsigned int which_output, diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 9171942e0..71ac8eee6 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2007,2009,2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -31,11 +31,11 @@ * \brief The abstract base class for all 'terminal' processing blocks. * \ingroup base_blk * - * A signal processing flow is constructed by creating a tree of + * A signal processing flow is constructed by creating a tree of * hierarchical blocks, which at any level may also contain terminal nodes * that actually implement signal processing functions. This is the base * class for all such leaf nodes. - + * Blocks have a set of input streams and output streams. The * input_signature and output_signature define the number of input * streams and output streams respectively, and the type of the data @@ -58,7 +58,7 @@ class GR_CORE_API gr_block : public gr_basic_block { public: - + //! Magic return values from general_work enum { WORK_CALLED_PRODUCE = -2, @@ -82,7 +82,7 @@ class GR_CORE_API gr_block : public gr_basic_block { */ unsigned history () const { return d_history; } void set_history (unsigned history) { d_history = history; } - + /*! * \brief Return true if this block has a fixed input to output rate. * @@ -177,7 +177,7 @@ class GR_CORE_API gr_block : public gr_basic_block { int unaligned () const { return d_unaligned; } void set_is_unaligned (bool u); bool is_unaligned () const { return d_is_unaligned; } - + /*! * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed. */ @@ -264,7 +264,7 @@ class GR_CORE_API gr_block : public gr_basic_block { unsigned d_history; bool d_fixed_rate; tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream - + protected: gr_block (void){} //allows pure virtual interface sub-classes gr_block (const std::string &name, @@ -273,10 +273,10 @@ class GR_CORE_API gr_block : public gr_basic_block { void set_fixed_rate(bool fixed_rate){ d_fixed_rate = fixed_rate; } - + /*! * \brief Adds a new tag onto the given output buffer. - * + * * \param which_output an integer of which output stream to attach the tag * \param abs_offset a uint64 number of the absolute item number * assicated with the tag. Can get from nitems_written. @@ -323,7 +323,7 @@ class GR_CORE_API gr_block : public gr_basic_block { unsigned int which_input, uint64_t abs_start, uint64_t abs_end); - + /*! * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index bb0c5f221..4cc260bfe 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -38,9 +38,9 @@ class gr_block : public gr_basic_block { gr_io_signature_sptr output_signature); public: - + virtual ~gr_block (); - + unsigned history () const; int output_multiple () const; diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index cbd4239f3..2792cd471 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2009,2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -87,7 +87,7 @@ gr_block_detail::set_done (bool done) d_input[i]->set_done (done); } -void +void gr_block_detail::consume (int which_input, int how_many_items) { if (how_many_items > 0) { @@ -134,7 +134,7 @@ gr_block_detail::_post(pmt_t msg) } uint64_t -gr_block_detail::nitems_read(unsigned int which_input) +gr_block_detail::nitems_read(unsigned int which_input) { if(which_input >= d_ninputs) throw std::invalid_argument ("gr_block_detail::n_input_items"); @@ -142,7 +142,7 @@ gr_block_detail::nitems_read(unsigned int which_input) } uint64_t -gr_block_detail::nitems_written(unsigned int which_output) +gr_block_detail::nitems_written(unsigned int which_output) { if(which_output >= d_noutputs) throw std::invalid_argument ("gr_block_detail::n_output_items"); @@ -179,7 +179,7 @@ gr_block_detail::get_tags_in_range(std::vector &v, const pmt_t &key) { std::vector found_items; - + v.resize(0); // get from gr_buffer_reader's deque of tags diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 89081156a..c96f00db8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -96,11 +96,11 @@ class GR_CORE_API gr_block_detail { // Return the number of items written on output stream which_output uint64_t nitems_written(unsigned int which_output); - + /*! * \brief Adds a new tag to the given output stream. - * - * This takes the input parameters and builds a PMT tuple + * + * This takes the input parameters and builds a PMT tuple * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), * which appends the tag onto its deque. * @@ -112,7 +112,7 @@ class GR_CORE_API gr_block_detail { /*! * \brief Given a [start,end), returns a vector of all tags in the range. * - * Pass-through function to gr_buffer_reader to get a vector of tags + * Pass-through function to gr_buffer_reader to get a vector of tags * in given range. Range of counts is from start to end-1. * * Tags are tuples of: @@ -127,7 +127,7 @@ class GR_CORE_API gr_block_detail { unsigned int which_input, uint64_t abs_start, uint64_t abs_end); - + /*! * \brief Given a [start,end), returns a vector of all tags in the range * with a given key. diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.i b/gnuradio-core/src/lib/runtime/gr_block_detail.i index c8600c3cf..74ff46360 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.i +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 86289695a..6fea14613 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2008,2009,2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -147,7 +147,7 @@ propagate_tags(gr_block::tag_propagation_policy_t policy, gr_block_detail *d, std::cerr << "Error: gr_block_executor: propagation_policy 'ONE-TO-ONE' requires ninputs == noutputs" << std::endl; return false; } - + break; default: return true; @@ -241,10 +241,10 @@ gr_block_executor::run_one_iteration() LOG(*d_log << " d_ninput_items[" << i << "] = " << d_ninput_items[i] << std::endl); LOG(*d_log << " d_input_done[" << i << "] = " << d_input_done[i] << std::endl); - + if (d_ninput_items[i] < m->output_multiple() && d_input_done[i]) goto were_done; - + max_items_avail = std::max (max_items_avail, d_ninput_items[i]); } @@ -309,7 +309,7 @@ gr_block_executor::run_one_iteration() // try to work it forward starting with max_items_avail. // We want to try to consume all the input we've got. int reqd_noutput_items = m->fixed_rate_ninput_to_noutput(max_items_avail); - + // only test this if we specifically set the output_multiple if(m->output_multiple_set()) reqd_noutput_items = round_down(reqd_noutput_items, m->output_multiple()); @@ -442,7 +442,7 @@ gr_block_executor::run_one_iteration() 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; @@ -461,7 +461,7 @@ gr_block_executor::run_one_iteration() return READY_NO_OUTPUT; } assert (0); - + were_done: LOG(*d_log << " were_done\n"); d->set_done (true); diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h index e022d8273..0ae5affba 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.h +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 8ccc9db32..b923ca57a 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2009,2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -90,7 +90,7 @@ gr_buffer::gr_buffer (int nitems, size_t sizeof_item, gr_block_sptr link) s_buffer_count++; } -gr_buffer_sptr +gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr link) { return gr_buffer_sptr (new gr_buffer (nitems, sizeof_item, link)); @@ -111,7 +111,7 @@ bool gr_buffer::allocate_buffer (int nitems, size_t sizeof_item) { int orig_nitems = nitems; - + // Any buffersize we come up with must be a multiple of min_nitems. int granularity = gr_vmcircbuf_sysconfig::granularity (); @@ -240,7 +240,7 @@ gr_buffer::prune_tags(uint64_t max_time) d_item_tags. In practice, this function is only called at runtime by min_available_space in gr_block_executor.cc, which locks the mutex itself. - + If this function is used elsewhere, remember to lock the buffer's mutex al la the scoped_lock line below. */ @@ -285,7 +285,7 @@ gr_buffer_reader::~gr_buffer_reader () d_buffer->drop_reader(this); s_buffer_reader_count--; } - + int gr_buffer_reader::items_available () const { @@ -315,7 +315,7 @@ gr_buffer_reader::get_tags_in_range(std::vector &v, v.resize(0); std::deque::iterator itr = d_buffer->get_tags_begin(); - + uint64_t item_time; while(itr != d_buffer->get_tags_end()) { item_time = (*itr).offset; diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 9478e1ce0..67d48fb2d 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2009,2010,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -97,14 +97,14 @@ class GR_CORE_API gr_buffer { /*! * \brief Adds a new tag to the buffer. - * + * * \param tag the new tag */ void add_item_tag(const gr_tag_t &tag); /*! * \brief Removes all tags before \p max_time from buffer - * + * * \param max_time the time (item number) to trim up until. */ void prune_tags(uint64_t max_time); @@ -130,7 +130,7 @@ class GR_CORE_API gr_buffer { boost::weak_ptr d_link; // block that writes to this buffer // - // The mutex protects d_write_index, d_abs_write_offset, d_done, d_item_tags + // The mutex protects d_write_index, d_abs_write_offset, d_done, d_item_tags // and the d_read_index's and d_abs_read_offset's in the buffer readers. // gruel::mutex d_mutex; @@ -139,7 +139,7 @@ class GR_CORE_API gr_buffer { bool d_done; std::deque d_item_tags; uint64_t d_last_min_items_read; - + unsigned index_add (unsigned a, unsigned b) { @@ -194,7 +194,7 @@ class GR_CORE_API gr_buffer { * \param nzero_preload -- number of zero items to "preload" into buffer. * \param link is the block that reads from the buffer using this gr_buffer_reader. */ -GR_CORE_API gr_buffer_reader_sptr +GR_CORE_API gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link=gr_block_sptr()); //! returns # of gr_buffers currently allocated @@ -280,7 +280,7 @@ class GR_CORE_API gr_buffer_reader { private: friend class gr_buffer; - friend GR_CORE_API gr_buffer_reader_sptr + friend GR_CORE_API gr_buffer_reader_sptr gr_buffer_add_reader (gr_buffer_sptr buf, int nzero_preload, gr_block_sptr link); diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.i b/gnuradio-core/src/lib/runtime/gr_buffer.i index 4c1c5afae..390a94e05 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.i +++ b/gnuradio-core/src/lib/runtime/gr_buffer.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -35,7 +35,7 @@ class gr_buffer { private: gr_buffer (int nitems, size_t sizeof_item, gr_block_sptr link); }; - + class gr_buffer_reader; typedef boost::shared_ptr gr_buffer_reader_sptr; diff --git a/gnuradio-core/src/lib/runtime/gr_complex.h b/gnuradio-core/src/lib/runtime/gr_complex.h index 32e996eef..758002106 100644 --- a/gnuradio-core/src/lib/runtime/gr_complex.h +++ b/gnuradio-core/src/lib/runtime/gr_complex.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.cc b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc index e165361fc..96ebe9ad8 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.cc +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.h b/gnuradio-core/src/lib/runtime/gr_dispatcher.h index 735974766..72a0b0176 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.h +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_dispatcher.i b/gnuradio-core/src/lib/runtime/gr_dispatcher.i index fc361701a..28737cd31 100644 --- a/gnuradio-core/src/lib/runtime/gr_dispatcher.i +++ b/gnuradio-core/src/lib/runtime/gr_dispatcher.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.cc b/gnuradio-core/src/lib/runtime/gr_error_handler.cc index 4b4cdacef..448682966 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -23,7 +23,7 @@ * This code is based on error.cc from the "Click Modular Router". * Original copyright follows: */ -/* +/* * error.{cc,hh} -- flexible classes for error reporting * Eddie Kohler * @@ -205,7 +205,7 @@ gr_file_error_handler::handle_text(seriousness s, const std::string &text) { if (text.length() <= 0) return; - + fwrite(text.data(), 1, text.length(), d_file); if (text[text.length()-1] != '\n') fwrite("\n", 1, 1, d_file); @@ -213,7 +213,7 @@ gr_file_error_handler::handle_text(seriousness s, const std::string &text) if (d_fd != -1) fflush(d_file); // keep synced with any other users of fd } - + // ---------------------------------------------------------------- // static error handlers diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.h b/gnuradio-core/src/lib/runtime/gr_error_handler.h index 4c30791f2..569c01c45 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -23,7 +23,7 @@ * This code is based on error.hh from the "Click Modular Router". * Original copyright follows: */ -/* +/* * error.{cc,hh} -- flexible classes for error reporting * Eddie Kohler * diff --git a/gnuradio-core/src/lib/runtime/gr_error_handler.i b/gnuradio-core/src/lib/runtime/gr_error_handler.i index b4aa1fa39..072394a72 100644 --- a/gnuradio-core/src/lib/runtime/gr_error_handler.i +++ b/gnuradio-core/src/lib/runtime/gr_error_handler.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 5c9e4bf3f..030e2d97d 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -134,11 +134,11 @@ gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) gr_block_sptr grblock = cast_to_block_sptr(block); if (!grblock) throw std::runtime_error("connect_block_inputs found non-gr_block"); - + // Get its detail and edges that feed into it gr_block_detail_sptr detail = grblock->detail(); gr_edge_vector_t in_edges = calc_upstream_edges(block); - + // For each edge that feeds into it for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) { // Set the buffer reader on the destination port to the output @@ -150,7 +150,7 @@ gr_flat_flowgraph::connect_block_inputs(gr_basic_block_sptr block) if (!src_grblock) throw std::runtime_error("connect_block_inputs found non-gr_block"); gr_buffer_sptr src_buffer = src_grblock->detail()->output(src_port); - + if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Setting input " << dst_port << " from edge " << (*e) << std::endl; @@ -166,7 +166,7 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) // already have one. for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { gr_block_sptr block = cast_to_block_sptr(*p); - + if (!block->detail()) { if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "merge: allocating new detail for block " << (*p) << std::endl; @@ -182,7 +182,7 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) for (gr_edge_viter_t old_edge = old_ffg->d_edges.begin(); old_edge != old_ffg->d_edges.end(); old_edge++) { if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "merge: testing old edge " << (*old_edge) << "..."; - + gr_edge_viter_t new_edge; for (new_edge = d_edges.begin(); new_edge != d_edges.end(); new_edge++) if (new_edge->src() == old_edge->src() && @@ -201,7 +201,7 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "found in new edge list" << std::endl; } - } + } // Now connect inputs to outputs, reusing old buffer readers if they exist for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { @@ -209,13 +209,13 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "merge: merging " << (*p) << "..."; - + if (old_ffg->has_block_p(*p)) { // Block exists in old flow graph if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "used in old flow graph" << std::endl; gr_block_detail_sptr detail = block->detail(); - + // Iterate through the inputs and see what needs to be done int ninputs = calc_used_ports(block, true).size(); // Might be different now for (int i = 0; i < ninputs; i++) { @@ -228,9 +228,9 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) gr_block_detail_sptr src_detail = src_block->detail(); gr_buffer_sptr src_buffer = src_detail->output(edge.src().port()); gr_buffer_reader_sptr old_reader; - if (i < detail->ninputs()) // Don't exceed what the original detail has + if (i < detail->ninputs()) // Don't exceed what the original detail has old_reader = detail->input(i); - + // If there's a match, use it if (old_reader && (src_buffer == old_reader->buffer())) { if (GR_FLAT_FLOWGRAPH_DEBUG) @@ -255,9 +255,9 @@ gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) setup_buffer_alignment(block); } - // Now deal with the fact that the block details might have changed numbers of + // Now deal with the fact that the block details might have changed numbers of // inputs and outputs vs. in the old flowgraph. - } + } } void @@ -298,7 +298,7 @@ void gr_flat_flowgraph::dump() std::cout << " block: " << (*p) << std::endl; gr_block_detail_sptr detail = cast_to_block_sptr(*p)->detail(); std::cout << " detail @" << detail << ":" << std::endl; - + int ni = detail->ninputs(); int no = detail->noutputs(); for (int i = 0; i < no; i++) { diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h index ce863509b..0926bcc8f 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -64,7 +64,7 @@ private: gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port); void connect_block_inputs(gr_basic_block_sptr block); - /* When reusing a flowgraph's blocks, this call makes sure all of the + /* When reusing a flowgraph's blocks, this call makes sure all of the * buffer's are aligned at the machine's alignment boundary and tells * the blocks that they are aligned. * diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc index 0d3bbb011..78e1bc99a 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -44,7 +44,7 @@ gr_flowgraph_sptr gr_make_flowgraph() gr_flowgraph::gr_flowgraph() { } - + gr_flowgraph::~gr_flowgraph() { } @@ -57,7 +57,7 @@ unique_vector(std::vector v) { std::vector result; std::insert_iterator > inserter(result, result.begin()); - + sort(v.begin(), v.end()); unique_copy(v.begin(), v.end(), inserter); return result; @@ -113,7 +113,7 @@ gr_flowgraph::validate() if (!((*p)->check_topology(ninputs, noutputs))) { std::stringstream msg; msg << "check topology failed on " << (*p) - << " using ninputs=" << ninputs + << " using ninputs=" << ninputs << ", noutputs=" << noutputs; throw std::runtime_error(msg.str()); } @@ -194,7 +194,7 @@ gr_flowgraph::calc_used_ports(gr_basic_block_sptr block, bool check_inputs) { std::vector tmp; - // Collect all seen ports + // Collect all seen ports gr_edge_vector_t edges = calc_connections(block, check_inputs); for (gr_edge_viter_t p = edges.begin(); p != edges.end(); p++) { if (check_inputs == true) @@ -259,7 +259,7 @@ gr_flowgraph::check_contiguity(gr_basic_block_sptr block, if (used_ports[nports-1]+1 != nports) { for (int i = 0; i < nports; i++) { if (used_ports[i] != i) { - msg << block << ": missing connection " + msg << block << ": missing connection " << (check_inputs ? "to input port " : "from output port ") << i; throw std::runtime_error(msg.str()); @@ -367,7 +367,7 @@ gr_flowgraph::calc_reachable_blocks(gr_basic_block_sptr block, gr_basic_block_ve } // Recursively mark all reachable blocks from given block and block list -void +void gr_flowgraph::reachable_dfs_visit(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) { // Mark the current one as visited @@ -382,18 +382,18 @@ gr_flowgraph::reachable_dfs_visit(gr_basic_block_sptr block, gr_basic_block_vect } // Return a list of block adjacent to a given block along any edge -gr_basic_block_vector_t +gr_basic_block_vector_t gr_flowgraph::calc_adjacent_blocks(gr_basic_block_sptr block, gr_basic_block_vector_t &blocks) { gr_basic_block_vector_t tmp; - + // Find any blocks that are inputs or outputs for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { if (p->src().block() == block) tmp.push_back(p->dst().block()); if (p->dst().block() == block) tmp.push_back(p->src().block()); - } + } return unique_vector(tmp); } @@ -412,7 +412,7 @@ gr_flowgraph::topological_sort(gr_basic_block_vector_t &blocks) for (gr_basic_block_viter_t p = tmp.begin(); p != tmp.end(); p++) { if ((*p)->color() == gr_basic_block::WHITE) topological_dfs_visit(*p, result); - } + } reverse(result.begin(), result.end()); return result; @@ -453,11 +453,11 @@ gr_flowgraph::topological_dfs_visit(gr_basic_block_sptr block, gr_basic_block_ve for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { switch ((*p)->color()) { - case gr_basic_block::WHITE: + case gr_basic_block::WHITE: topological_dfs_visit(*p, output); break; - case gr_basic_block::GREY: + case gr_basic_block::GREY: throw std::runtime_error("flow graph has loops!"); case gr_basic_block::BLACK: diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flowgraph.h index 8f9a8ba71..a2c1580eb 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -44,11 +44,11 @@ public: int port() const { return d_port; } bool operator==(const gr_endpoint &other) const; -}; +}; inline bool gr_endpoint::operator==(const gr_endpoint &other) const { - return (d_basic_block == other.d_basic_block && + return (d_basic_block == other.d_basic_block && d_port == other.d_port); } @@ -134,7 +134,7 @@ protected: gr_edge_vector_t d_edges; gr_flowgraph(); - std::vector calc_used_ports(gr_basic_block_sptr block, bool check_inputs); + std::vector calc_used_ports(gr_basic_block_sptr block, bool check_inputs); gr_basic_block_vector_t calc_downstream_blocks(gr_basic_block_sptr block, int port); gr_edge_vector_t calc_upstream_edges(gr_basic_block_sptr block); bool has_block_p(gr_basic_block_sptr block); diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index d6e317136..756852df8 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2007,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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -33,7 +33,7 @@ gr_hier_block2_sptr -gr_make_hier_block2(const std::string &name, +gr_make_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature) { @@ -67,27 +67,27 @@ gr_hier_block2::to_hier_block2() return cast_to_hier_block2_sptr(shared_from_this()); } -void +void gr_hier_block2::connect(gr_basic_block_sptr block) { d_detail->connect(block); } -void -gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, +void +gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { d_detail->connect(src, src_port, dst, dst_port); } -void +void gr_hier_block2::disconnect(gr_basic_block_sptr block) { d_detail->disconnect(block); } -void -gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, +void +gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { d_detail->disconnect(src, src_port, dst, dst_port); diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 12bcf10e7..123178724 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2007,2008,2009 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -48,21 +48,21 @@ private: friend GR_CORE_API gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); - + /*! * \brief Private implementation details of gr_hier_block2 */ gr_hier_block2_detail *d_detail; - -protected: + +protected: gr_hier_block2 (void){} //allows pure virtual interface sub-classes gr_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); - + public: virtual ~gr_hier_block2(); - + /*! * \brief typedef for object returned from self(). * @@ -90,11 +90,11 @@ public: /*! * \brief Add gr-blocks or hierarchical blocks to internal graph and wire together * - * This adds (if not done earlier by another connect) a pair of gr-blocks or - * hierarchical blocks to the internal flowgraph, and wires the specified output + * This adds (if not done earlier by another connect) a pair of gr-blocks or + * hierarchical blocks to the internal flowgraph, and wires the specified output * port to the specified input port. */ - void connect(gr_basic_block_sptr src, int src_port, + void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); /*! diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index 4fa7c3bc0..eefb965b4 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005,2006,2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -45,10 +45,10 @@ private: gr_hier_block2(const std::string name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); - + public: ~gr_hier_block2 (); - + void connect(gr_basic_block_sptr block) throw (std::invalid_argument); void connect(gr_basic_block_sptr src, int src_port, diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 1d0c66fb8..76c5ce06f 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -1,18 +1,18 @@ /* * Copyright 2006,2007,2009 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -31,7 +31,7 @@ #define GR_HIER_BLOCK2_DETAIL_DEBUG 0 gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : - d_owner(owner), + d_owner(owner), d_parent_detail(0), d_fg(gr_make_flowgraph()) { @@ -83,16 +83,16 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr block) std::cout << "connect: block is hierarchical, setting parent to " << this << std::endl; hblock->d_detail->d_parent_detail = this; } - + d_blocks.push_back(block); } -void -gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, +void +gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { std::stringstream msg; - + if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "connecting: " << gr_endpoint(src, src_port) << " -> " << gr_endpoint(dst, dst_port) << std::endl; @@ -108,7 +108,7 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, std::cout << "connect: src is hierarchical, setting parent to " << this << std::endl; src_block->d_detail->d_parent_detail = this; } - + if (dst_block && dst.get() != d_owner) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "connect: dst is hierarchical, setting parent to " << this << std::endl; @@ -150,14 +150,14 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr block) for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { if (*p == block) { d_blocks.erase(p); - + gr_hier_block2_sptr hblock(cast_to_hier_block2_sptr(block)); if (block && block.get() != d_owner) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "disconnect: block is hierarchical, clearing parent" << std::endl; hblock->d_detail->d_parent_detail = 0; } - + return; } } @@ -170,7 +170,7 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr block) edges.push_back(*p); if (GR_HIER_BLOCK2_DETAIL_DEBUG) - std::cout << "disconnect: block found in edge " << (*p) << std::endl; + std::cout << "disconnect: block found in edge " << (*p) << std::endl; } } @@ -186,8 +186,8 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr block) } } -void -gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, +void +gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) @@ -205,7 +205,7 @@ gr_hier_block2_detail::disconnect(gr_basic_block_sptr src, int src_port, std::cout << "disconnect: src is hierarchical, clearing parent" << std::endl; src_block->d_detail->d_parent_detail = 0; } - + if (dst_block && dst.get() != d_owner) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "disconnect: dst is hierarchical, clearing parent" << std::endl; @@ -240,7 +240,7 @@ gr_hier_block2_detail::connect_input(int my_port, int port, gr_basic_block_sptr msg << "external input port " << my_port << " already wired to " << endp; throw std::invalid_argument(msg.str()); } - + endps.push_back(endp); } @@ -281,7 +281,7 @@ gr_hier_block2_detail::disconnect_input(int my_port, int port, gr_basic_block_sp msg << "external input port " << my_port << " not connected to " << endp; throw std::invalid_argument(msg.str()); } - + endps.erase(p); } @@ -296,7 +296,7 @@ gr_hier_block2_detail::disconnect_output(int my_port, int port, gr_basic_block_s } if (d_outputs[my_port].block() != block) { - msg << "block " << block << " not assigned to output " + msg << "block " << block << " not assigned to output " << my_port << ", can't disconnect"; throw std::invalid_argument(msg.str()); } @@ -390,7 +390,7 @@ gr_hier_block2_detail::resolve_endpoint(const gr_endpoint &endp, bool is_input) gr_hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(endp.block())); if (hier_block2) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) - std::cout << "Resolving endpoint " << endp << " as an " + std::cout << "Resolving endpoint " << endp << " as an " << (is_input ? "input" : "output") << ", recursing" << std::endl; return hier_block2->d_detail->resolve_port(endp.port(), is_input); @@ -428,7 +428,7 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const } } - // Construct unique list of blocks used either in edges, inputs, + // Construct unique list of blocks used either in edges, inputs, // outputs, or by themselves. I still hate STL. gr_basic_block_vector_t blocks; // unique list of used blocks gr_basic_block_vector_t tmp = d_fg->calc_used_blocks(); @@ -446,7 +446,7 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const << " is not connected internally"; throw std::runtime_error(msg.str()); } - + for (unsigned int j = 0; j < d_inputs[i].size(); j++) tmp.push_back(d_inputs[i][j].block()); } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index 5a77d6a03..f4f950e9d 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2007,2009 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -37,10 +37,10 @@ public: ~gr_hier_block2_detail(); void connect(gr_basic_block_sptr block); - void connect(gr_basic_block_sptr src, int src_port, + void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); void disconnect(gr_basic_block_sptr block); - void disconnect(gr_basic_block_sptr, int src_port, + void disconnect(gr_basic_block_sptr, int src_port, gr_basic_block_sptr, int dst_port); void disconnect_all(); void lock(); @@ -48,7 +48,7 @@ public: void flatten_aux(gr_flat_flowgraph_sptr sfg) const; private: - + // Private implementation data gr_hier_block2 *d_owner; gr_hier_block2_detail *d_parent_detail; @@ -56,7 +56,7 @@ private: std::vector d_inputs; // Multiple internal endpoints per external input gr_endpoint_vector_t d_outputs; // Single internal endpoint per external output gr_basic_block_vector_t d_blocks; - + void connect_input(int my_port, int port, gr_basic_block_sptr block); void connect_output(int my_port, int port, gr_basic_block_sptr block); void disconnect_input(int my_port, int port, gr_basic_block_sptr block); diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.cc b/gnuradio-core/src/lib/runtime/gr_io_signature.cc index 1c1b06f02..6ac9acd17 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -56,7 +56,7 @@ gr_make_io_signature2(int min_streams, int max_streams, } gr_io_signature_sptr -gr_make_io_signature3(int min_streams, int max_streams, +gr_make_io_signature3(int min_streams, int max_streams, int sizeof_stream_item1, int sizeof_stream_item2, int sizeof_stream_item3) @@ -85,7 +85,7 @@ gr_io_signature::gr_io_signature (int min_streams, int max_streams, if (max_streams != 0 && sizeof_stream_items[i] < 1) throw std::invalid_argument("gr_io_signature(3)"); } - + d_min_streams = min_streams; d_max_streams = max_streams; d_sizeof_stream_item = sizeof_stream_items; @@ -95,12 +95,12 @@ gr_io_signature::~gr_io_signature () { } -int +int gr_io_signature::sizeof_stream_item (int _index) const { if (_index < 0) throw std::invalid_argument ("gr_io_signature::sizeof_stream_item"); - + size_t index = _index; return d_sizeof_stream_item[std::min(index, d_sizeof_stream_item.size() - 1)]; } diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index 11c6b7f13..fd1825797 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -62,7 +62,7 @@ gr_make_io_signature2(int min_streams, int max_streams, * \param sizeof_stream_item3 specify the size of the items in the third and subsequent streams */ GR_CORE_API gr_io_signature_sptr -gr_make_io_signature3(int min_streams, int max_streams, +gr_make_io_signature3(int min_streams, int max_streams, int sizeof_stream_item1, int sizeof_stream_item2, int sizeof_stream_item3 @@ -96,7 +96,7 @@ class GR_CORE_API gr_io_signature { gr_io_signature(int min_streams, int max_streams, const std::vector &sizeof_stream_items); - friend GR_CORE_API gr_io_signature_sptr + friend GR_CORE_API gr_io_signature_sptr gr_make_io_signaturev(int min_streams, int max_streams, const std::vector &sizeof_stream_items); @@ -104,9 +104,9 @@ class GR_CORE_API gr_io_signature { public: static const int IO_INFINITE = -1; - + ~gr_io_signature (); - + int min_streams () const { return d_min_streams; } int max_streams () const { return d_max_streams; } int sizeof_stream_item (int index) const; diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.i b/gnuradio-core/src/lib/runtime/gr_io_signature.i index 78465b19e..fe1707e41 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.i +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2005,2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -40,7 +40,7 @@ gr_make_io_signature2(int min_streams, int max_streams, int sizeof_stream_item2 ); gr_io_signature_sptr -gr_make_io_signature3(int min_streams, int max_streams, +gr_make_io_signature3(int min_streams, int max_streams, int sizeof_stream_item1, int sizeof_stream_item2, int sizeof_stream_item3 @@ -53,7 +53,7 @@ gr_make_io_signaturev(int min_streams, int max_streams, class gr_io_signature { gr_io_signature (int min_streams, int max_streams, int sizeof_stream_item); - friend gr_io_signature_sptr + friend gr_io_signature_sptr gr_make_io_signaturev(int min_streams, int max_streams, const std::vector &sizeof_stream_item); @@ -62,9 +62,9 @@ class gr_io_signature { // disabled. Suspected bug in SWIG 1.3.24 // static const int IO_INFINITE = -1; - + ~gr_io_signature (); - + int min_streams () const { return d_min_streams; } int max_streams () const { return d_max_streams; } int sizeof_stream_item (int index) const; diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc index adad55791..fb31742e1 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -172,7 +172,7 @@ gr_signal::name () const #endif default: #if defined (HAVE_SNPRINTF) -#if defined (SIGRTMIN) && defined (SIGRTMAX) +#if defined (SIGRTMIN) && defined (SIGRTMAX) if (signal () >= SIGRTMIN && signal () <= SIGRTMAX){ snprintf (tmp, sizeof (tmp), "SIGRTMIN + %d", signal ()); return tmp; diff --git a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h index 9e4eacc47..a30e2c13a 100644 --- a/gnuradio-core/src/lib/runtime/gr_local_sighandler.h +++ b/gnuradio-core/src/lib/runtime/gr_local_sighandler.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_message.cc b/gnuradio-core/src/lib/runtime/gr_message.cc index 6bef71ed5..a99dcd765 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.cc +++ b/gnuradio-core/src/lib/runtime/gr_message.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -67,7 +67,7 @@ gr_message::~gr_message () std::string gr_message::to_string() const -{ +{ return std::string((char *)d_msg_start, length()); } diff --git a/gnuradio-core/src/lib/runtime/gr_message.h b/gnuradio-core/src/lib/runtime/gr_message.h index ead002616..d386ca009 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.h +++ b/gnuradio-core/src/lib/runtime/gr_message.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -32,7 +32,7 @@ typedef boost::shared_ptr gr_message_sptr; /*! * \brief public constructor for gr_message */ -GR_CORE_API gr_message_sptr +GR_CORE_API gr_message_sptr gr_make_message(long type = 0, double arg1 = 0, double arg2 = 0, size_t length = 0); GR_CORE_API gr_message_sptr @@ -55,7 +55,7 @@ class GR_CORE_API gr_message { unsigned char *d_msg_start; // where the msg starts unsigned char *d_msg_end; // one beyond end of msg unsigned char *d_buf_end; // one beyond end of allocated buffer - + gr_message (long type, double arg1, double arg2, size_t length); friend GR_CORE_API gr_message_sptr diff --git a/gnuradio-core/src/lib/runtime/gr_message.i b/gnuradio-core/src/lib/runtime/gr_message.i index 44636fde6..356bba5b5 100644 --- a/gnuradio-core/src/lib/runtime/gr_message.i +++ b/gnuradio-core/src/lib/runtime/gr_message.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc index 89876ae29..5018ee9e6 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2009 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. @@ -45,7 +45,7 @@ gr_msg_accepter::post(pmt_t msg) { // Notify derived class, handled case by case gr_block *p = dynamic_cast(this); - if (p) { + if (p) { p->detail()->_post(msg); return; } diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h index 4aec127a9..3e5c97638 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2009 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. diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.cc b/gnuradio-core/src/lib/runtime/gr_msg_handler.cc index a3a85a463..0f9349708 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.h b/gnuradio-core/src/lib/runtime/gr_msg_handler.h index ebe3ffe37..57e8a95d6 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -35,7 +35,7 @@ typedef boost::shared_ptr gr_msg_handler_sptr; class GR_CORE_API gr_msg_handler { public: virtual ~gr_msg_handler (); - + //! handle \p msg virtual void handle (gr_message_sptr msg) = 0; }; diff --git a/gnuradio-core/src/lib/runtime/gr_msg_handler.i b/gnuradio-core/src/lib/runtime/gr_msg_handler.i index 17ccd0ec5..f493dac1b 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_handler.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_handler.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -26,7 +26,7 @@ class gr_msg_handler { public: virtual ~gr_msg_handler () = 0; - + //! handle \p msg virtual void handle (gr_message_sptr msg) = 0; }; diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc index 3097acc9e..0cf046771 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005,2009 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.h b/gnuradio-core/src/lib/runtime/gr_msg_queue.h index bf7b89882..86440bbb0 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005,2009 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -71,16 +71,16 @@ public: * If no message is available, return 0. */ gr_message_sptr delete_head_nowait(); - + //! Delete all messages from the queue void flush(); //! is the queue empty? bool empty_p() const { return d_count == 0; } - + //! is the queue full? bool full_p() const { return d_limit != 0 && d_count >= d_limit; } - + //! return number of messages in queue unsigned int count() const { return d_count; } diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 2a78253b3..65cbe782b 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005,2009,2010,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -58,13 +58,13 @@ public: * If no message is available, return 0. */ gr_message_sptr delete_head_nowait(); - + //! is the queue empty? bool empty_p() const; - + //! is the queue full? bool full_p() const; - + //! return number of messages in queue unsigned int count() const; diff --git a/gnuradio-core/src/lib/runtime/gr_pagesize.cc b/gnuradio-core/src/lib/runtime/gr_pagesize.cc index 09fdf5578..e31e05ca7 100644 --- a/gnuradio-core/src/lib/runtime/gr_pagesize.cc +++ b/gnuradio-core/src/lib/runtime/gr_pagesize.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_pagesize.h b/gnuradio-core/src/lib/runtime/gr_pagesize.h index 60dad42c9..3e2daa925 100644 --- a/gnuradio-core/src/lib/runtime/gr_pagesize.h +++ b/gnuradio-core/src/lib/runtime/gr_pagesize.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index c2ca047a8..a0f561660 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,2010,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -85,7 +85,7 @@ gr_preferences::get (const char *key) return buf; } -void +void gr_preferences::set (const char *key, const char *value) { ensure_dir_path (); diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.h b/gnuradio-core/src/lib/runtime/gr_preferences.h index ab4dc0cb0..bfcc0424b 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.h +++ b/gnuradio-core/src/lib/runtime/gr_preferences.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.cc b/gnuradio-core/src/lib/runtime/gr_realtime.cc index b44c4d408..75b497999 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.cc +++ b/gnuradio-core/src/lib/runtime/gr_realtime.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2007,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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.h b/gnuradio-core/src/lib/runtime/gr_realtime.h index 58db83086..fe6549039 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.h +++ b/gnuradio-core/src/lib/runtime/gr_realtime.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_realtime.i b/gnuradio-core/src/lib/runtime/gr_realtime.i index be7f12bf0..1051d3e2b 100644 --- a/gnuradio-core/src/lib/runtime/gr_realtime.i +++ b/gnuradio-core/src/lib/runtime/gr_realtime.i @@ -1,19 +1,19 @@ /* -*- 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_runtime_types.h b/gnuradio-core/src/lib/runtime/gr_runtime_types.h index 98f08b417..0d6149288 100644 --- a/gnuradio-core/src/lib/runtime/gr_runtime_types.h +++ b/gnuradio-core/src/lib/runtime/gr_runtime_types.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_scheduler.cc index 3ae08a7a3..c691f5d99 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler.cc @@ -1,19 +1,19 @@ /* -*- 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. diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler.h b/gnuradio-core/src/lib/runtime/gr_scheduler.h index 92af8d1cb..6d130327f 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler.h @@ -1,19 +1,19 @@ /* -*- 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. diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc index 3cc1d4d45..2c96def6d 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.cc @@ -1,19 +1,19 @@ /* -*- 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. @@ -29,7 +29,7 @@ class sts_container { gr_block_vector_t d_blocks; - + public: sts_container(gr_block_vector_t blocks) diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h index 08c68d88a..011874ec0 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_sts.h @@ -1,19 +1,19 @@ /* -*- 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. diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc index 0a7ff4556..131ddd19c 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc @@ -1,19 +1,19 @@ /* -*- 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. @@ -34,7 +34,7 @@ class tpb_container { gr_block_sptr d_block; int d_max_noutput_items; - + public: tpb_container(gr_block_sptr block, int max_noutput_items) : d_block(block), d_max_noutput_items(max_noutput_items) {} diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h index ab74fa84d..a9b3abcfa 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.h @@ -1,19 +1,19 @@ /* -*- 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. diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.cc b/gnuradio-core/src/lib/runtime/gr_select_handler.cc index 869e46511..0fc86354a 100644 --- a/gnuradio-core/src/lib/runtime/gr_select_handler.cc +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_select_handler.h b/gnuradio-core/src/lib/runtime/gr_select_handler.h index 532707a02..c4c359213 100644 --- a/gnuradio-core/src/lib/runtime/gr_select_handler.h +++ b/gnuradio-core/src/lib/runtime/gr_select_handler.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -60,7 +60,7 @@ public: /*! * \brief Called when file_descriptor is writable. * - * Called when dispatcher detects that file descriptor can be + * Called when dispatcher detects that file descriptor can be * written without blocking. */ virtual void handle_write() = 0; diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc index ae04e4a65..1bb9e9b0a 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -81,7 +81,7 @@ gr_single_threaded_scheduler::run () void gr_single_threaded_scheduler::stop () -{ +{ if (0) std::cout << "gr_singled_threaded_scheduler::stop() " << this << std::endl; @@ -206,7 +206,7 @@ gr_single_threaded_scheduler::main_loop () //if (ninput_items[i] == 0 && d->input(i)->done()) if (ninput_items[i] < m->output_multiple() && d->input(i)->done()) goto were_done; - + max_items_avail = std::max (max_items_avail, ninput_items[i]); } @@ -345,7 +345,7 @@ gr_single_threaded_scheduler::main_loop () goto next_block; } assert (0); - + were_done: LOG(*d_log << " were_done\n"); d->set_done (true); diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h index 17f4a1c54..3a95c7194 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -51,7 +51,7 @@ class GR_CORE_API gr_single_threaded_scheduler { gr_single_threaded_scheduler (const std::vector &blocks); void main_loop (); - + friend GR_CORE_API gr_single_threaded_scheduler_sptr gr_make_single_threaded_scheduler (const std::vector &blocks); }; diff --git a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i index 2378a1880..7305cc9ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i +++ b/gnuradio-core/src/lib/runtime/gr_single_threaded_scheduler.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -28,7 +28,7 @@ typedef boost::shared_ptr gr_single_threaded_sched %rename(single_threaded_scheduler) gr_make_single_threaded_scheduler; %ignore gr_single_threaded_scheduler; -gr_single_threaded_scheduler_sptr +gr_single_threaded_scheduler_sptr gr_make_single_threaded_scheduler (const std::vector &modules); class gr_single_threaded_scheduler { diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc index b0351248c..7fdadf24a 100644 --- a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2008,2009 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. @@ -44,7 +44,7 @@ namespace gnuradio { } - gr_basic_block_sptr + gr_basic_block_sptr detail::sptr_magic::fetch_initial_sptr(gr_basic_block *p) { /* diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.h b/gnuradio-core/src/lib/runtime/gr_sptr_magic.h index 4b7f9899d..3d997539c 100644 --- a/gnuradio-core/src/lib/runtime/gr_sptr_magic.h +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.h @@ -1,19 +1,19 @@ /* -*- 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. @@ -30,7 +30,7 @@ class gr_hier_block2; namespace gnuradio { namespace detail { - + class GR_CORE_API sptr_magic { public: static boost::shared_ptr fetch_initial_sptr(gr_basic_block *p); @@ -38,7 +38,7 @@ namespace gnuradio { }; }; - /* + /* * \brief New! Improved! Standard method to get/create the boost::shared_ptr for a block. */ template diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.cc b/gnuradio-core/src/lib/runtime/gr_sync_block.cc index 1427570ae..94efcdc8e 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index 808c1c18a..1e4109b03 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -50,7 +50,7 @@ class GR_CORE_API gr_sync_block : public gr_block virtual int work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) = 0; - + // gr_sync_block overrides these to assist work void forecast (int noutput_items, gr_vector_int &ninput_items_required); @@ -62,5 +62,5 @@ class GR_CORE_API gr_sync_block : public gr_block int fixed_rate_ninput_to_noutput(int ninput); int fixed_rate_noutput_to_ninput(int noutput); }; - + #endif /* INCLUDED_GR_SYNC_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.i b/gnuradio-core/src/lib/runtime/gr_sync_block.i index 8e140bb88..d3e1bb957 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.i +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc index 1add2fadd..a0f907db5 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h index 7228d3655..657aba985 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.i b/gnuradio-core/src/lib/runtime/gr_sync_decimator.i index 821b2648e..af4574b19 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.i +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc index d130a5be1..ece873c14 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index c332a5272..86d2fde43 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i index 4443ed0aa..6f8b08252 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_sys_paths.cc b/gnuradio-core/src/lib/runtime/gr_sys_paths.cc index 9d10a3ccd..b4918af33 100644 --- a/gnuradio-core/src/lib/runtime/gr_sys_paths.cc +++ b/gnuradio-core/src/lib/runtime/gr_sys_paths.cc @@ -1,18 +1,18 @@ /* * Copyright 2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_sys_paths.h b/gnuradio-core/src/lib/runtime/gr_sys_paths.h index 1f1759c36..bd51ebdf9 100644 --- a/gnuradio-core/src/lib/runtime/gr_sys_paths.h +++ b/gnuradio-core/src/lib/runtime/gr_sys_paths.h @@ -1,18 +1,18 @@ /* * Copyright 2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_tags.h b/gnuradio-core/src/lib/runtime/gr_tags.h index 5fff6f15b..8bffcd0fe 100644 --- a/gnuradio-core/src/lib/runtime/gr_tags.h +++ b/gnuradio-core/src/lib/runtime/gr_tags.h @@ -1,18 +1,18 @@ /* * Copyright 2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_timer.h b/gnuradio-core/src/lib/runtime/gr_timer.h index fa3c06ece..e0b4cc437 100644 --- a/gnuradio-core/src/lib/runtime/gr_timer.h +++ b/gnuradio-core/src/lib/runtime/gr_timer.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -57,7 +57,7 @@ public: //! return absolute current time (seconds since the epoc). static double now (); - + /*! * \brief schedule timer to fire at abs_when * \param abs_when absolute time in seconds since the epoc. diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 56d1352cd..e47473edd 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -30,48 +30,48 @@ #include #include -gr_top_block_sptr +gr_top_block_sptr gr_make_top_block(const std::string &name) { return gnuradio::get_initial_sptr(new gr_top_block(name)); } gr_top_block::gr_top_block(const std::string &name) - : gr_hier_block2(name, - gr_make_io_signature(0,0,0), + : gr_hier_block2(name, + gr_make_io_signature(0,0,0), gr_make_io_signature(0,0,0)) - + { d_impl = new gr_top_block_impl(this); } - + gr_top_block::~gr_top_block() { stop(); wait(); - + delete d_impl; } -void +void gr_top_block::start(int max_noutput_items) { d_impl->start(max_noutput_items); } -void +void gr_top_block::stop() { d_impl->stop(); } -void +void gr_top_block::wait() { d_impl->wait(); } -void +void gr_top_block::run(int max_noutput_items) { start(max_noutput_items); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index e837700c3..04d1e95e5 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,2008,2009 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -44,7 +44,7 @@ private: protected: gr_top_block(const std::string &name); - + public: ~gr_top_block(); @@ -72,7 +72,7 @@ public: * this to adjust the maximum latency a flowgraph can exhibit. */ void start(int max_noutput_items=100000); - + /*! * Stop the running flowgraph. Notifies each thread created by the * scheduler to shutdown, then returns to caller. Calling stop() on @@ -118,7 +118,7 @@ public: //! Get the number of max noutput_items in the flowgraph int max_noutput_items(); - + //! Set the maximum number of noutput_items in the flowgraph void set_max_noutput_items(int nmax); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index ea5534c17..80a1b82ae 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,2008,2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -29,14 +29,14 @@ typedef boost::shared_ptr gr_top_block_sptr; // Hack to have a Python shim implementation of gr.top_block // that instantiates one of these and passes through calls %rename(top_block_swig) gr_make_top_block; -gr_top_block_sptr gr_make_top_block(const std::string name) +gr_top_block_sptr gr_make_top_block(const std::string name) throw (std::logic_error); class gr_top_block : public gr_hier_block2 { private: gr_top_block(const std::string &name); - + public: ~gr_top_block(); @@ -57,14 +57,14 @@ public: #ifdef SWIGPYTHON %inline %{ -void top_block_run_unlocked(gr_top_block_sptr r) throw (std::runtime_error) +void top_block_run_unlocked(gr_top_block_sptr r) throw (std::runtime_error) { Py_BEGIN_ALLOW_THREADS; // release global interpreter lock r->run(); Py_END_ALLOW_THREADS; // acquire global interpreter lock } -void top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error) +void top_block_wait_unlocked(gr_top_block_sptr r) throw (std::runtime_error) { Py_BEGIN_ALLOW_THREADS; // release global interpreter lock r->wait(); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc index 0227d789c..4a3694163 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc @@ -77,7 +77,7 @@ make_scheduler(gr_flat_flowgraph_sptr ffg, int max_noutput_items) } -gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) +gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) : d_owner(owner), d_ffg(), d_state(IDLE), d_lock_count(0) { @@ -112,7 +112,7 @@ gr_top_block_impl::start(int max_noutput_items) d_state = RUNNING; } -void +void gr_top_block_impl::stop() { if (d_scheduler) @@ -165,7 +165,7 @@ gr_top_block_impl::restart() wait(); // Create new simple flow graph - gr_flat_flowgraph_sptr new_ffg = d_owner->flatten(); + gr_flat_flowgraph_sptr new_ffg = d_owner->flatten(); new_ffg->validate(); // check consistency, sanity, etc new_ffg->merge_connections(d_ffg); // reuse buffers, etc d_ffg = new_ffg; @@ -187,7 +187,7 @@ gr_top_block_impl::max_noutput_items() { return d_max_noutput_items; } - + void gr_top_block_impl::set_max_noutput_items(int nmax) { diff --git a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h index d804e3f30..f55c3f021 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block_impl.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block_impl.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -61,12 +61,12 @@ public: // Get the number of max noutput_items in the flowgraph int max_noutput_items(); - + // Set the maximum number of noutput_items in the flowgraph void set_max_noutput_items(int nmax); - + protected: - + enum tb_state { IDLE, RUNNING }; gr_top_block *d_owner; @@ -77,7 +77,7 @@ protected: tb_state d_state; int d_lock_count; int d_max_noutput_items; - + private: void restart(); }; diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc b/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc index c6311ccaa..46b33d91f 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2008,2009 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. @@ -80,7 +80,7 @@ gr_tpb_detail::insert_tail(pmt::pmt_t msg) output_cond.notify_one(); } -pmt_t +pmt_t gr_tpb_detail::delete_head_nowait() { gruel::scoped_lock guard(mutex); @@ -97,7 +97,7 @@ gr_tpb_detail::delete_head_nowait() /* * Caller must already be holding the mutex */ -pmt_t +pmt_t gr_tpb_detail::delete_head_nowait_already_holding_mutex() { if (empty_p()) diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h index 90908c2f5..b6e342dee 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2008,2009 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. @@ -62,11 +62,11 @@ public: input_changed = false; output_changed = false; } - + //! is the queue empty? bool empty_p() const { return msg_queue.empty(); } - //| Acquires and release the mutex + //| Acquires and release the mutex void insert_tail(pmt::pmt_t msg); /*! diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index d44c09aa6..a5aabb379 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2008,2009,2011 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. @@ -40,7 +40,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item while (1){ boost::this_thread::interruption_point(); - + // handle any queued up messages while ((msg = d->d_tpb.delete_head_nowait())) block->dispatch_msg(msg); @@ -65,7 +65,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item { gruel::scoped_lock guard(d->d_tpb.mutex); while (!d->d_tpb.input_changed){ - + // wait for input or message while(!d->d_tpb.input_changed && d->d_tpb.empty_p()) d->d_tpb.input_cond.wait(guard); @@ -80,12 +80,12 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item } break; - + case gr_block_executor::BLKD_OUT: // Wait for output buffer space. { gruel::scoped_lock guard(d->d_tpb.mutex); while (!d->d_tpb.output_changed){ - + // wait for output room or message while(!d->d_tpb.output_changed && d->d_tpb.empty_p()) d->d_tpb.output_cond.wait(guard); diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h index 3170b402e..f920663a2 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.h @@ -1,19 +1,19 @@ /* -*- 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. diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h index fd5ca7758..ad6cee768 100644 --- a/gnuradio-core/src/lib/runtime/gr_types.h +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -37,7 +37,7 @@ typedef std::vector gr_vector_void_star; typedef std::vector gr_vector_const_void_star; /* - * #include must be placed beforehand + * #include must be placed beforehand * in the source file including gr_types.h for * the following to work correctly */ diff --git a/gnuradio-core/src/lib/runtime/gr_unittests.h b/gnuradio-core/src/lib/runtime/gr_unittests.h index 7161b31e7..9fbf228cd 100644 --- a/gnuradio-core/src/lib/runtime/gr_unittests.h +++ b/gnuradio-core/src/lib/runtime/gr_unittests.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2010,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc index 7138605c9..522d9515d 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -135,7 +135,7 @@ static bool check_mapping (gr_vmcircbuf *c, int counter, int size, const char *msg, bool verbose) { bool ok = true; - + if (verbose) fprintf (stderr, "... %s", msg); @@ -246,7 +246,7 @@ gr_vmcircbuf_sysconfig::test_factory (gr_vmcircbuf_factory *f, int verbose) { // Install local signal handlers for SIGSEGV and SIGBUS. // If something goes wrong, these signals may be invoked. - + #ifdef SIGSEGV gr_local_sighandler sigsegv (SIGSEGV, gr_local_sighandler::throw_signal); #endif @@ -285,7 +285,7 @@ bool gr_vmcircbuf_sysconfig::test_all_factories (int verbose) { bool ok = false; - + std::vector all = all_factories (); for (unsigned int i = 0; i < all.size (); i++) diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h index 0e67d405b..45c6f969c 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -88,10 +88,10 @@ class GR_CORE_API gr_vmcircbuf_sysconfig { */ static gr_vmcircbuf_factory *get_default_factory (); - + static int granularity () { return get_default_factory()->granularity(); } static gr_vmcircbuf *make (int size) { return get_default_factory()->make(size); } - + // N.B. not all factories are guaranteed to work. // It's too hard to check everything at config time, so we check at runtime diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc index 4f7ae39cd..3d170081d 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -57,7 +57,7 @@ gr_vmcircbuf_mmap_shm_open::gr_vmcircbuf_mmap_shm_open (int size) int shm_fd = -1; char seg_name[1024]; static bool portable_format = true; - + // open a new named shared memory segment while (1){ @@ -65,7 +65,7 @@ gr_vmcircbuf_mmap_shm_open::gr_vmcircbuf_mmap_shm_open (int size) // This is the POSIX recommended "portable format". // Of course the "portable format" doesn't work on some systems... - + snprintf (seg_name, sizeof (seg_name), "/gnuradio-%d-%d", getpid (), s_seg_counter); } @@ -73,7 +73,7 @@ gr_vmcircbuf_mmap_shm_open::gr_vmcircbuf_mmap_shm_open (int size) // Where the "portable format" doesn't work, we try building // a full filesystem pathname pointing into a suitable temporary directory. - + snprintf (seg_name, sizeof (seg_name), "%s/gnuradio-%d-%d", gr_tmp_path (), getpid (), s_seg_counter); } @@ -149,7 +149,7 @@ gr_vmcircbuf_mmap_shm_open::gr_vmcircbuf_mmap_shm_open (int size) close (shm_fd); // fd no longer needed. The mapping is retained. - if (shm_unlink (seg_name) == -1){ // unlink the seg_name. + if (shm_unlink (seg_name) == -1){ // unlink the seg_name. perror ("gr_vmcircbuf_mmap_shm_open: shm_unlink"); throw std::runtime_error ("gr_vmcircbuf_mmap_shm_open"); } @@ -163,7 +163,7 @@ gr_vmcircbuf_mmap_shm_open::gr_vmcircbuf_mmap_shm_open (int size) gr_vmcircbuf_mmap_shm_open::~gr_vmcircbuf_mmap_shm_open () { -#if defined(HAVE_MMAP) +#if defined(HAVE_MMAP) if (munmap (d_base, 2 * d_size) == -1){ perror ("gr_vmcircbuf_mmap_shm_open: munmap (2)"); } diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h index 002f5b434..bcbbbac42 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_shm_open.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc index ee8b0c485..35de64699 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -56,7 +56,7 @@ gr_vmcircbuf_mmap_tmpfile::gr_vmcircbuf_mmap_tmpfile (int size) int seg_fd = -1; char seg_name[1024]; - + static int s_seg_counter = 0; @@ -121,7 +121,7 @@ gr_vmcircbuf_mmap_tmpfile::gr_vmcircbuf_mmap_tmpfile (int size) if (second_copy == MAP_FAILED){ munmap(first_copy, size); // cleanup - close (seg_fd); + close (seg_fd); perror ("gr_vmcircbuf_mmap_tmpfile: mmap (2)"); throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); } @@ -130,7 +130,7 @@ gr_vmcircbuf_mmap_tmpfile::gr_vmcircbuf_mmap_tmpfile (int size) if ((char *) second_copy != (char *) first_copy + size){ munmap(first_copy, size); // cleanup munmap(second_copy, size); - close (seg_fd); + close (seg_fd); perror ("gr_vmcircbuf_mmap_tmpfile: non-contiguous second copy"); throw std::runtime_error ("gr_vmcircbuf_mmap_tmpfile"); } diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h index a2ed6b87b..28ff31490 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_mmap_tmpfile.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc index 88869dc75..d9cf75e70 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -97,7 +97,7 @@ gr_vmcircbuf_sysv_shm::gr_vmcircbuf_sysv_shm (int size) // some other segment to first_copy or first_copoy + size between // our detach and attach, the attaches below could fail [I've never // seen it fail for this reason]. - + shmdt (first_copy); // first read-only guard page diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h index c7a008581..9f5c04f0d 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index ab5840c6d..4fa0a0323 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -57,7 +57,7 @@ qa_block_tags::t0 () gr_block_sptr src (gr_make_null_source(sizeof(int))); gr_block_sptr head (gr_make_head(sizeof(int), N)); gr_block_sptr snk (gr_make_null_sink(sizeof(int))); - + tb->connect(src, 0, head, 0); tb->connect(head, 0, snk, 0); @@ -89,7 +89,7 @@ qa_block_tags::t1 () gr_annotator_alltoall_sptr ann4 (gr_make_annotator_alltoall(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); - + tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); @@ -140,7 +140,7 @@ qa_block_tags::t1 () expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); std::cout << std::endl << "qa_block_tags::t1" << std::endl; - + // For annotator 3, we know it gets tags from ann0 and ann1, test this for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; @@ -171,7 +171,7 @@ qa_block_tags::t2 () gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk2 (gr_make_null_sink(sizeof(int))); - + tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); @@ -271,7 +271,7 @@ qa_block_tags::t3 () gr_annotator_1to1_sptr ann4 (gr_make_annotator_1to1(10000, sizeof(int))); gr_block_sptr snk0 (gr_make_null_sink(sizeof(int))); gr_block_sptr snk1 (gr_make_null_sink(sizeof(int))); - + tb->connect(src, 0, head, 0); tb->connect(head, 0, ann0, 0); tb->connect(head, 0, ann0, 1); @@ -286,7 +286,7 @@ qa_block_tags::t3 () tb->run(); - + std::vector tags0 = ann0->data(); std::vector tags3 = ann3->data(); std::vector tags4 = ann4->data(); @@ -324,7 +324,7 @@ qa_block_tags::t3 () expected_tags4[7] = mp(pmt_from_uint64(30000), mp(str0.str()), mp("seq"), mp(7)); std::cout << std::endl << "qa_block_tags::t3" << std::endl; - + // For annotator 3, we know it gets tags from ann0 and ann1, test this for(size_t i = 0; i < tags3.size(); i++) { std::cout << "tags3[" << i << "] = " << tags3[i] << "\t\t" << expected_tags3[i] << std::endl; diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.h b/gnuradio-core/src/lib/runtime/qa_block_tags.h index b0d211390..6b7e5975d 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.h +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2010 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_block.cc index ea3f3e14c..aeab5b74a 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_block.h b/gnuradio-core/src/lib/runtime/qa_gr_block.h index 24634998e..14c7c40d1 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_block.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_block.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc index 7434cf657..c74baf398 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -65,7 +65,7 @@ t0_body () sa = buf->space_available (); CPPUNIT_ASSERT_EQUAL (last_sa, sa); last_sa = sa; - + int *p = (int *) buf->write_pointer (); CPPUNIT_ASSERT (p != 0); @@ -80,7 +80,7 @@ t0_body () // test single writer, single reader // -static void +static void t1_body () { int nitems = 4000 / sizeof (int); @@ -89,7 +89,7 @@ t1_body () gr_buffer_sptr buf(gr_make_buffer(nitems, sizeof (int), gr_block_sptr())); gr_buffer_reader_sptr r1 (gr_buffer_add_reader (buf, 0, gr_block_sptr())); - + int sa; @@ -106,7 +106,7 @@ t1_body () } buf->update_write_pointer (sa/3); - + // write the next 1/3 (1/2 of what's left) sa = buf->space_available (); @@ -125,7 +125,7 @@ t1_body () int ia = r1->items_available (); CPPUNIT_ASSERT_EQUAL (write_counter, ia); - + int *rp = (int *) r1->read_pointer (); CPPUNIT_ASSERT (rp != 0); @@ -159,7 +159,7 @@ t2_body () { // 64K is the largest granularity we've seen so far (MS windows file mapping). // This allows a bit of "white box testing" - + int nitems = (64 * (1L << 10)) / sizeof (int); // 64K worth of ints gr_buffer_sptr buf(gr_make_buffer (nitems, sizeof (int), gr_block_sptr())); @@ -170,7 +170,7 @@ t2_body () int n; int *wp = 0; int *rp = 0; - + // Write 3/4 of buffer n = (int) (buf->space_available () * 0.75); @@ -203,7 +203,7 @@ t2_body () for (int i = 0; i < n; i++) *wp++ = write_counter++; buf->update_write_pointer (n); - + // now read it all m = r1->items_available (); diff --git a/gnuradio-core/src/lib/runtime/qa_gr_buffer.h b/gnuradio-core/src/lib/runtime/qa_gr_buffer.h index 7e812e721..2937c24b6 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_buffer.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc index c883c1678..cce83cb0a 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -223,7 +223,7 @@ void qa_gr_flowgraph::t16_partition() gr_block_sptr nop31 = gr_make_nop(sizeof(int)); gr_block_sptr nop32 = gr_make_nop(sizeof(int)); - + // Build disjoint graph #1 fg->connect(nop11, 0, nop12, 0); fg->connect(nop12, 0, nop13, 0); diff --git a/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h b/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h index 2253afccd..2c2686f71 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_flowgraph.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -27,10 +27,10 @@ #include #include -class qa_gr_flowgraph : public CppUnit::TestCase +class qa_gr_flowgraph : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(qa_gr_flowgraph); - + CPPUNIT_TEST(t0); CPPUNIT_TEST(t1_connect); CPPUNIT_TEST(t2_connect_invalid_src_port_neg); diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc index d9d89ce2c..9844d3381 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,2008,2009 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -39,14 +39,14 @@ void qa_gr_hier_block2::test_make() CPPUNIT_ASSERT(src1); CPPUNIT_ASSERT_EQUAL(std::string("test"), src1->name()); - CPPUNIT_ASSERT_EQUAL(1 * (int) sizeof(int), + CPPUNIT_ASSERT_EQUAL(1 * (int) sizeof(int), src1->input_signature()->sizeof_stream_item(0)); CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->min_streams()); CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->max_streams()); - CPPUNIT_ASSERT_EQUAL(1 * (int) sizeof(int), + CPPUNIT_ASSERT_EQUAL(1 * (int) sizeof(int), src1->output_signature()->sizeof_stream_item(0)); CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->min_streams()); diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h index 3870b9f0f..653cd2725 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -27,12 +27,12 @@ #include #include -class qa_gr_hier_block2 : public CppUnit::TestCase +class qa_gr_hier_block2 : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(qa_gr_hier_block2); CPPUNIT_TEST(test_make); - + CPPUNIT_TEST_SUITE_END(); private: diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc index fe5f3a751..060c4e244 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -78,7 +78,7 @@ void qa_gr_hier_block2_derived::test_1() gr_block_sptr head(gr_make_head(sizeof(int), 1000)); gr_derived_block_sptr blk(gr_make_derived_block()); gr_block_sptr dst(gr_make_null_sink(sizeof(int))); - + tb->connect(src, 0, head, 0); tb->connect(head, 0, blk, 0); tb->connect(blk, 0, dst, 0); diff --git a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h index 5a27b1b2d..8e0a1880c 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2006,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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -28,7 +28,7 @@ #include // Declare a QA test case -class qa_gr_hier_block2_derived : public CppUnit::TestCase +class qa_gr_hier_block2_derived : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(qa_gr_hier_block2_derived); CPPUNIT_TEST(test_1); diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc index 07abe10b3..c1737ffb8 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h index 02fc9ddc4..9cd6bb524 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_io_signature.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc index 52677f0de..cc7b7c720 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h index 278b5ffb4..b223633e5 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -27,10 +27,10 @@ #include #include -class qa_gr_top_block : public CppUnit::TestCase +class qa_gr_top_block : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(qa_gr_top_block); - + CPPUNIT_TEST(t0); CPPUNIT_TEST(t1_run); CPPUNIT_TEST(t2_start_stop_wait); diff --git a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc index 2e787ac28..e3b36d882 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2002 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -35,6 +35,6 @@ qa_gr_vmcircbuf::test_all () int verbose = 1; // summary bool ok = gr_vmcircbuf_sysconfig::test_all_factories (verbose); - + CPPUNIT_ASSERT_EQUAL (true, ok); } diff --git a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h index 42f6a1917..3576660d5 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_vmcircbuf.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index c0bee8ea0..5e62c7991 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -1,18 +1,18 @@ /* * Copyright 2002,2007,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -56,6 +56,6 @@ qa_runtime::suite () s->addTest (qa_gr_buffer::suite ()); s->addTest (qa_block_tags::suite ()); s->addTest (qa_set_msg_handler::suite ()); - + return s; } diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.h b/gnuradio-core/src/lib/runtime/qa_runtime.h index e1038aaf6..da71cbd0f 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.h +++ b/gnuradio-core/src/lib/runtime/qa_runtime.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2002 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc index 35ef5527e..25ae0b1e1 100644 --- a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc +++ b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.h b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.h index e73fffbcd..60277a12c 100644 --- a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.h +++ b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,2011 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -27,10 +27,10 @@ #include #include -class qa_set_msg_handler : public CppUnit::TestCase +class qa_set_msg_handler : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(qa_set_msg_handler); - + CPPUNIT_TEST(t0); CPPUNIT_TEST_SUITE_END(); diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 9bf2df31e..8e35df834 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, diff --git a/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc b/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc index e541c5402..bb4e86322 100644 --- a/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc +++ b/gnuradio-core/src/lib/runtime/test_shared_block_ptr.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -23,7 +23,7 @@ #include #include -gr_block_sptr +gr_block_sptr foo (gr_vector_source_i_sptr s) { return gr_block_sptr (s); @@ -38,14 +38,14 @@ bar (gr_vector_source_i *s) return gr_vector_source_i_ptrX (s); } -gr_block_sptr +gr_block_sptr baz_1 (gr_vector_source_i_ptrX s) { return gr_block_sptr (s); } #if 0 -gr_block_sptr +gr_block_sptr baz_2 (gr_vector_source_i_ptrX s) { return s.block_sptr (); -- cgit From ea4ea222dd41f45b370b0bb322b1f63f76a77a34 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 4 Jun 2012 18:22:48 -0400 Subject: runtime: added ability for blocks to have their own max_noutput_items. Setting a max_noutput_items for an individual block will override the global max that can be passed to the start/run method of the top_block. Also adds QA code for testing that these features run and complete a flowgraph. --- gnuradio-core/src/lib/runtime/gr_block.cc | 31 +++++++++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 39 +++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block_executor.cc | 4 +- gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc | 5 +++ gnuradio-core/src/lib/runtime/qa_gr_top_block.cc | 45 ++++++++++++++++++++++ gnuradio-core/src/lib/runtime/qa_gr_top_block.h | 4 ++ 6 files changed, 126 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 9a5255a93..7e01c0ba8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -40,6 +40,8 @@ gr_block::gr_block (const std::string &name, d_relative_rate (1.0), d_history(1), d_fixed_rate(false), + d_max_noutput_items_set(false), + d_max_noutput_items(0), d_tag_propagation_policy(TPP_ALL_TO_ALL) { } @@ -208,6 +210,35 @@ gr_block::set_tag_propagation_policy(tag_propagation_policy_t p) d_tag_propagation_policy = p; } + +int +gr_block::max_noutput_items() +{ + return d_max_noutput_items; +} + +void +gr_block::set_max_noutput_items(int m) +{ + if(m <= 0) + throw std::runtime_error("gr_block::set_max_noutput_items: value for max_noutput_items must be greater than 0.\n"); + + d_max_noutput_items = m; + d_max_noutput_items_set = true; +} + +void +gr_block::unset_max_noutput_items() +{ + d_max_noutput_items_set = false; +} + +bool +gr_block::is_set_max_noutput_items() +{ + return d_max_noutput_items_set; +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 71ac8eee6..c89138bb3 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -251,6 +251,43 @@ class GR_CORE_API gr_block : public gr_basic_block { */ void set_tag_propagation_policy(tag_propagation_policy_t p); + /*! + * \brief Return the maximum number of output items this block will + * handle during a call to work. + */ + int max_noutput_items(); + + /*! + * \brief Set the maximum number of ouput items htis block will + * handle during a call to work. + * + * \param m the maximum noutput_items this block will handle. + */ + void set_max_noutput_items(int m); + + /*! + * \brief Clear the switch for using the max_noutput_items value of this block. + * + * When is_set_max_noutput_items() returns 'true', the scheduler + * will use the value returned by max_noutput_items() to limit the + * size of the number of items possible for this block's work + * function. If is_set_max_notput_items() returns 'false', then the + * scheduler ignores the internal value and uses the value set + * globally in the top_block. + * + * Use this value to clear the 'is_set' flag so the scheduler will + * ignore this. Use the set_max_noutput_items(m) call to both set a + * new value for max_noutput_items and to reenable its use in the + * scheduler. + */ + void unset_max_noutput_items(); + + /*! + * \brief Ask the block if the flag is or is not set to use the + * internal value of max_noutput_items during a call to work. + */ + bool is_set_max_noutput_items(); + // ---------------------------------------------------------------------------- private: @@ -263,6 +300,8 @@ class GR_CORE_API gr_block : public gr_basic_block { gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; + bool d_max_noutput_items_set; // if d_max_noutput_items is valid + int d_max_noutput_items; // value of max_noutput_items for this block tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream protected: diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 6fea14613..5b24e9f6e 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -206,7 +206,7 @@ gr_block_executor::run_one_iteration() // determine the minimum available output space noutput_items = min_available_space (d, m->output_multiple ()); - noutput_items = std::min(noutput_items, d_max_noutput_items); + noutput_items = std::min(noutput_items, max_noutput_items); LOG(*d_log << " source\n noutput_items = " << noutput_items << std::endl); if (noutput_items == -1) // we're done goto were_done; @@ -251,7 +251,7 @@ gr_block_executor::run_one_iteration() // take a swag at how much output we can sink noutput_items = (int) (max_items_avail * m->relative_rate ()); noutput_items = round_down (noutput_items, m->output_multiple ()); - noutput_items = std::min(noutput_items, d_max_noutput_items); + noutput_items = std::min(noutput_items, max_noutput_items); LOG(*d_log << " max_items_avail = " << max_items_avail << std::endl); LOG(*d_log << " noutput_items = " << noutput_items << std::endl); diff --git a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc index 131ddd19c..2824eb1b3 100644 --- a/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc +++ b/gnuradio-core/src/lib/runtime/gr_scheduler_tpb.cc @@ -74,6 +74,11 @@ gr_scheduler_tpb::gr_scheduler_tpb(gr_flat_flowgraph_sptr ffg, int max_noutput_i for (size_t i = 0; i < blocks.size(); i++){ std::stringstream name; name << "thread-per-block[" << i << "]: " << blocks[i]; + + // If set, use internal value instead of global value + if(blocks[i]->is_set_max_noutput_items()) + max_noutput_items = blocks[i]->max_noutput_items(); + d_threads.create_thread( gruel::thread_body_wrapper(tpb_container(blocks[i], max_noutput_items), name.str())); diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc index cc7b7c720..fe0883eba 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc @@ -119,3 +119,48 @@ void qa_gr_top_block::t4_reconfigure() // Wait for flowgraph to end on its own tb->wait(); } + + +void qa_gr_top_block::t5_max_noutputs() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t5()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + // Start infinite flowgraph + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->start(100); + tb->wait(); +} + +void qa_gr_top_block::t6_reconfig_max_noutputs() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t5()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + // Start infinite flowgraph + tb->connect(src, 0, dst, 0); + tb->start(100); + + // Reconfigure with gr_head in the middle + tb->lock(); + tb->disconnect(src, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->set_max_noutput_items(1000); + head->set_max_noutput_items(500); + tb->unlock(); + + // Wait for flowgraph to end on its own + tb->wait(); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h index b223633e5..7299ca330 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h @@ -36,6 +36,8 @@ class qa_gr_top_block : public CppUnit::TestCase CPPUNIT_TEST(t2_start_stop_wait); CPPUNIT_TEST(t3_lock_unlock); CPPUNIT_TEST(t4_reconfigure); // triggers 'join never returns' bug + CPPUNIT_TEST(t5_max_noutputs); + CPPUNIT_TEST(t6_reconfig_max_noutputs); CPPUNIT_TEST_SUITE_END(); @@ -46,6 +48,8 @@ private: void t2_start_stop_wait(); void t3_lock_unlock(); void t4_reconfigure(); + void t5_max_noutputs(); + void t6_reconfig_max_noutputs(); }; #endif /* INCLUDED_QA_GR_TOP_BLOCK_H */ -- cgit From 5dafe3c0ea2f66e078781f35e8fd30c90abb673b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 4 Jun 2012 19:56:36 -0400 Subject: core: exported max_noutput_item methods from gr_block to Python. --- gnuradio-core/src/lib/runtime/gr_block.i | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index 4cc260bfe..e9341e8cb 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -52,6 +52,12 @@ class gr_block : public gr_basic_block { uint64_t nitems_read(unsigned int which_input); uint64_t nitems_written(unsigned int which_output); + // Methods to manage the block's max_noutput_items size. + int max_noutput_items(); + void set_max_noutput_items(int m); + void unset_max_noutput_items(); + bool is_set_max_noutput_items(); + // internal use gr_block_detail_sptr detail () const { return d_detail; } void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } -- cgit From 04e28f4ed161810f0af1caa7bd31a4aaa2f5f8c3 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 14 Jun 2012 08:27:38 -0700 Subject: core: remove extraneous include statement --- gnuradio-core/src/lib/runtime/gr_top_block.i | 2 -- 1 file changed, 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 80a1b82ae..6ae4c65a9 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -20,8 +20,6 @@ * Boston, MA 02110-1301, USA. */ -%include - class gr_top_block; typedef boost::shared_ptr gr_top_block_sptr; %template(gr_top_block_sptr) boost::shared_ptr; -- cgit From a5cbf3b508bcdbfdc955a92dc752218359c5c88a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 3 Jul 2012 12:04:00 -0700 Subject: core: moved VMCIRCBUF related code to runtime This build stuff should not be at the top level. --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 1415ff4c6..5f3672dde 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -21,6 +21,29 @@ # This file included, use CMake directory variables ######################################################################## +######################################################################## +# Control availability of vmcircbuf methods. +# For now, only allows disabling of shm methods, which cause uncatchable +# segmentation faults on Cygwin with gcc 4.x (x <= 5) +# Usage: +# GR_VMCIRCBUF() +# +# Will set TRY_SHM_VMCIRCBUF to 1 by default except on Windows machines. +# Can manually set with -DTRY_SHM_VMCIRCBUF=0|1 +######################################################################## + + if(WIN32) + OPTION(TRY_SHM_VMCIRCBUF "Try SHM VMCIRCBUF" OFF) + else(WIN32) + OPTION(TRY_SHM_VMCIRCBUF "Try SHM VMCIRCBUF" ON) + endif(WIN32) + + message(STATUS "TRY_SHM_VMCIRCBUF set to ${TRY_SHM_VMCIRCBUF}.") + + if(TRY_SHM_VMCIRCBUF) + add_definitions( -DTRY_SHM_VMCIRCBUF ) + endif(TRY_SHM_VMCIRCBUF) + ######################################################################## # Append gnuradio-core library sources ######################################################################## -- cgit From a7e260a09bdb923b77174cedd31c2d7d70f32765 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 29 Sep 2012 20:13:38 -0700 Subject: core: source block can yield thread context/produce none --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 6fea14613..c08534475 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -449,6 +449,7 @@ gr_block_executor::run_one_iteration() // We didn't produce any output even though we called general_work. // We have (most likely) consumed some input. + /* // If this is a source, it's broken. if (d->source_p()){ std::cerr << "gr_block_executor: source " << m @@ -456,6 +457,7 @@ gr_block_executor::run_one_iteration() // FIXME maybe we ought to raise an exception... goto were_done; } + */ // Have the caller try again... return READY_NO_OUTPUT; -- cgit From 765d0686e6e0b46a7067cdf55ff195c425c709ed Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Thu, 27 Sep 2012 14:41:55 -0400 Subject: providing additional control over GNU Radio buffer allocation size for latency effects etc unlimited io_signatures of -1 should work correctly with this patch now --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 4 +++- gnuradio-core/src/lib/runtime/gr_basic_block.h | 20 +++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_basic_block.i | 6 ++++++ gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 16 ++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index d7263b92d..3d809aa8b 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -45,7 +45,9 @@ gr_basic_block::gr_basic_block(const std::string &name, d_input_signature(input_signature), d_output_signature(output_signature), d_unique_id(s_next_id++), - d_color(WHITE) + d_color(WHITE), + d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), + d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) { s_ncurrently_allocated++; } diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 4d03b878e..4d16014dd 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -29,7 +29,9 @@ #include #include #include +#include #include +#include /*! * \brief The abstract base class for all signal processing blocks. @@ -73,6 +75,8 @@ protected: gr_io_signature_sptr d_output_signature; long d_unique_id; vcolor d_color; + std::vector d_max_output_buffer; + std::vector d_min_output_buffer; gr_basic_block(void){} //allows pure virtual interface sub-classes @@ -104,7 +108,21 @@ public: gr_io_signature_sptr input_signature() const { return d_input_signature; } gr_io_signature_sptr output_signature() const { return d_output_signature; } gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion - + long max_output_buffer(size_t i){ return d_max_output_buffer.size()>i?d_max_output_buffer[i]:d_max_output_buffer[0]; } + void set_max_output_buffer(long max_output_buffer){ + for(int i=0; imax_streams(); i++){ + set_max_output_buffer(max_output_buffer, i); + } + } + void set_max_output_buffer(long max_output_buffer, int port){ d_max_output_buffer[port] = max_output_buffer; } + long min_output_buffer(size_t i){ return d_min_output_buffer.size()>i?d_min_output_buffer[i]:d_min_output_buffer[0]; } + void set_min_output_buffer(long min_output_buffer){ + for(int i=0; imax_streams(); i++){ + set_min_output_buffer(min_output_buffer, i); + } + } + void set_min_output_buffer(long min_output_buffer, int port){ d_min_output_buffer[port] = min_output_buffer; } + /*! * \brief Confirm that ninputs and noutputs is an acceptable combination. * diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index e43cc114c..848017dd8 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -42,6 +42,12 @@ public: long unique_id() const; gr_basic_block_sptr to_basic_block(); bool check_topology (int ninputs, int noutputs); + long max_output_buffer(int i); + void set_max_output_buffer(long max_output_buffer); + void set_max_output_buffer(long max_output_buffer, int port); + long min_output_buffer(int i); + void set_min_output_buffer(long min_output_buffer); + void set_min_output_buffer(long min_output_buffer, int port); }; %rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 030e2d97d..fb375b0f3 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -114,6 +114,21 @@ gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) // ensure we have a buffer at least twice their decimation factor*output_multiple gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); + + // limit buffer size if indicated + if(block->max_output_buffer(port) > 0){ +// std::cout << "constraining output items to " << block->max_output_buffer(port) << "\n"; + nitems = std::min((long)nitems, (long)block->max_output_buffer(port)); + nitems -= nitems%grblock->output_multiple(); + if( nitems < 1 ) + throw std::runtime_error("problems allocating a buffer with the given max output buffer constraint!"); + } else if(block->min_output_buffer(port) > 0){ + nitems = std::max((long)nitems, (long)block->min_output_buffer(port)); + nitems -= nitems%grblock->output_multiple(); + if( nitems < 1 ) + throw std::runtime_error("problems allocating a buffer with the given min output buffer constraint!"); + } + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { gr_block_sptr dgrblock = cast_to_block_sptr(*p); if (!dgrblock) @@ -125,6 +140,7 @@ gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) nitems = std::max(nitems, static_cast(2*(decimation*multiple+history))); } +// std::cout << "gr_make_buffer(" << nitems << ", " << item_size << ", " << grblock << "\n"; return gr_make_buffer(nitems, item_size, grblock); } -- cgit From 0ecb4d407b888b8631afa5a7c0b8c4f45e6c16c2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Oct 2012 13:01:54 -0400 Subject: core: bit of rework on setting/getting max_output_buffer. When setting, specify port first, than buffer size. This is consistent with other calls (like consume and produce). When getting, throw an error if port is out of range. --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 4d16014dd..37a09cd41 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -108,20 +108,28 @@ public: gr_io_signature_sptr input_signature() const { return d_input_signature; } gr_io_signature_sptr output_signature() const { return d_output_signature; } gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion - long max_output_buffer(size_t i){ return d_max_output_buffer.size()>i?d_max_output_buffer[i]:d_max_output_buffer[0]; } + long max_output_buffer(size_t i) { + if(d_max_output_buffer.size() <= i) + throw std::invalid_argument("gr_basic_block::max_output_buffer: port out of range."); + return d_max_output_buffer[i]; + } void set_max_output_buffer(long max_output_buffer){ for(int i=0; imax_streams(); i++){ set_max_output_buffer(max_output_buffer, i); } } - void set_max_output_buffer(long max_output_buffer, int port){ d_max_output_buffer[port] = max_output_buffer; } - long min_output_buffer(size_t i){ return d_min_output_buffer.size()>i?d_min_output_buffer[i]:d_min_output_buffer[0]; } + void set_max_output_buffer(int port, long max_output_buffer){ d_max_output_buffer[port] = max_output_buffer; } + long min_output_buffer(size_t i) { + if(d_min_output_buffer.size() <= i) + throw std::invalid_argument("gr_basic_block::min_output_buffer: port out of range."); + return d_min_output_buffer[i]; + } void set_min_output_buffer(long min_output_buffer){ for(int i=0; imax_streams(); i++){ set_min_output_buffer(min_output_buffer, i); } } - void set_min_output_buffer(long min_output_buffer, int port){ d_min_output_buffer[port] = min_output_buffer; } + void set_min_output_buffer(int port, long min_output_buffer){ d_min_output_buffer[port] = min_output_buffer; } /*! * \brief Confirm that ninputs and noutputs is an acceptable combination. -- cgit From ba7a5f0721b0c0ce4e907c1137de1e82746e0223 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Oct 2012 13:03:40 -0400 Subject: core: update max_buffer_size after buffer is actually allocated. --- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index fb375b0f3..15f07e26b 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -88,6 +88,9 @@ gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block) if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Allocated buffer for output " << block << ":" << i << std::endl; detail->set_output(i, buffer); + + // Update the block's max_output_buffer based on what was actually allocated. + block->set_max_output_buffer(i, buffer->bufsize()); } return detail; -- cgit From 48dd3fed73409a22b1bfd612cb74352cc555d0d0 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Oct 2012 19:26:32 -0400 Subject: core: fix for restarting the flowgraph with VOLK blocks. --- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 030e2d97d..9005cd339 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -267,10 +267,10 @@ gr_flat_flowgraph::setup_buffer_alignment(gr_block_sptr block) for(int i = 0; i < block->detail()->ninputs(); i++) { void *r = (void*)block->detail()->input(i)->read_pointer(); unsigned long int ri = (unsigned long int)r % alignment; - //std::cout << "reader: " << r << " alignment: " << ri << std::endl; + //std::cerr << "reader: " << r << " alignment: " << ri << std::endl; if(ri != 0) { size_t itemsize = block->detail()->input(i)->get_sizeof_item(); - block->detail()->input(i)->update_read_pointer(ri/itemsize); + block->detail()->input(i)->update_read_pointer(alignment-ri/itemsize); } block->set_unaligned(0); block->set_is_unaligned(false); @@ -279,10 +279,10 @@ gr_flat_flowgraph::setup_buffer_alignment(gr_block_sptr block) for(int i = 0; i < block->detail()->noutputs(); i++) { void *w = (void*)block->detail()->output(i)->write_pointer(); unsigned long int wi = (unsigned long int)w % alignment; - size_t itemsize = block->detail()->output(i)->get_sizeof_item(); - //std::cout << "writer: " << w << " alignment: " << wi << std::endl; + //std::cerr << "writer: " << w << " alignment: " << wi << std::endl; if(wi != 0) { - block->detail()->output(i)->update_write_pointer(wi/itemsize); + size_t itemsize = block->detail()->output(i)->get_sizeof_item(); + block->detail()->output(i)->update_write_pointer(alignment-wi/itemsize); } block->set_unaligned(0); block->set_is_unaligned(false); -- cgit From 1e528816fd70f3a61d7f00a370cb056f03ceb6a7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Oct 2012 14:52:07 -0400 Subject: core: fixed swig file for exporting max/min buffer sizes with port first. --- gnuradio-core/src/lib/runtime/gr_basic_block.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 848017dd8..7713f2fe1 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -44,10 +44,10 @@ public: bool check_topology (int ninputs, int noutputs); long max_output_buffer(int i); void set_max_output_buffer(long max_output_buffer); - void set_max_output_buffer(long max_output_buffer, int port); + void set_max_output_buffer(int port, long max_output_buffer); long min_output_buffer(int i); void set_min_output_buffer(long min_output_buffer); - void set_min_output_buffer(long min_output_buffer, int port); + void set_min_output_buffer(int port, long min_output_buffer); }; %rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; -- cgit From 2fdfad0411da70118269a3fb85d5c2c6ad80ead3 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Oct 2012 14:56:10 -0400 Subject: core: fixed set min/max buffer sizes to better handle blocks with infinite streams. --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 74 ++++++++++++++++++---- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 7 +- 2 files changed, 65 insertions(+), 16 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 37a09cd41..b8e8148b2 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -63,6 +63,20 @@ private: msg_handler_t d_msg_handler; + /* + * Used to expand the vectors that hold the min/max buffer sizes. + * + * Specifically, when -1 is used, the vectors are just initialized + * with 1 value; this is used by the flat_flowgraph to expand when + * required to add a new value for new ports on these blocks. + */ + void expand_minmax_buffer(int port) { + if((size_t)port >= d_max_output_buffer.size()) + set_max_output_buffer(port, -1); + if((size_t)port >= d_min_output_buffer.size()) + set_min_output_buffer(port, -1); + } + protected: friend class gr_flowgraph; friend class gr_flat_flowgraph; // TODO: will be redundant @@ -108,29 +122,63 @@ public: gr_io_signature_sptr input_signature() const { return d_input_signature; } gr_io_signature_sptr output_signature() const { return d_output_signature; } gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion + + /*! + * \brief Returns max buffer size on output port \p i. + */ long max_output_buffer(size_t i) { - if(d_max_output_buffer.size() <= i) + if(i >= d_max_output_buffer.size()) throw std::invalid_argument("gr_basic_block::max_output_buffer: port out of range."); return d_max_output_buffer[i]; } - void set_max_output_buffer(long max_output_buffer){ - for(int i=0; imax_streams(); i++){ - set_max_output_buffer(max_output_buffer, i); - } + + /*! + * \brief Sets max buffer size on all output ports. + */ + void set_max_output_buffer(long max_output_buffer) { + for(int i=0; imax_streams(); i++) { + set_max_output_buffer(i, max_output_buffer); + } } - void set_max_output_buffer(int port, long max_output_buffer){ d_max_output_buffer[port] = max_output_buffer; } + + /*! + * \brief Sets max buffer size on output port \p port. + */ + void set_max_output_buffer(int port, long max_output_buffer) { + if((size_t)port >= d_max_output_buffer.size()) + d_max_output_buffer.push_back(max_output_buffer); + else + d_max_output_buffer[port] = max_output_buffer; + } + + /*! + * \brief Returns min buffer size on output port \p i. + */ long min_output_buffer(size_t i) { - if(d_min_output_buffer.size() <= i) + if(i >= d_min_output_buffer.size()) throw std::invalid_argument("gr_basic_block::min_output_buffer: port out of range."); return d_min_output_buffer[i]; } - void set_min_output_buffer(long min_output_buffer){ - for(int i=0; imax_streams(); i++){ - set_min_output_buffer(min_output_buffer, i); - } + + /*! + * \brief Sets min buffer size on all output ports. + */ + void set_min_output_buffer(long min_output_buffer) { + for(int i=0; imax_streams(); i++) { + set_min_output_buffer(i, min_output_buffer); + } } - void set_min_output_buffer(int port, long min_output_buffer){ d_min_output_buffer[port] = min_output_buffer; } - + + /*! + * \brief Sets min buffer size on output port \p port. + */ + void set_min_output_buffer(int port, long min_output_buffer) { + if((size_t)port >= d_min_output_buffer.size()) + d_min_output_buffer.push_back(min_output_buffer); + else + d_min_output_buffer[port] = min_output_buffer; + } + /*! * \brief Confirm that ninputs and noutputs is an acceptable combination. * diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 15f07e26b..f51e52ce3 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -84,6 +84,7 @@ gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block) std::cout << "Creating block detail for " << block << std::endl; for (int i = 0; i < noutputs; i++) { + block->expand_minmax_buffer(i); gr_buffer_sptr buffer = allocate_buffer(block, i); if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Allocated buffer for output " << block << ":" << i << std::endl; @@ -117,15 +118,15 @@ gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) // ensure we have a buffer at least twice their decimation factor*output_multiple gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); - // limit buffer size if indicated - if(block->max_output_buffer(port) > 0){ + if(block->max_output_buffer(port) > 0) { // std::cout << "constraining output items to " << block->max_output_buffer(port) << "\n"; nitems = std::min((long)nitems, (long)block->max_output_buffer(port)); nitems -= nitems%grblock->output_multiple(); if( nitems < 1 ) throw std::runtime_error("problems allocating a buffer with the given max output buffer constraint!"); - } else if(block->min_output_buffer(port) > 0){ + } + else if(block->min_output_buffer(port) > 0) { nitems = std::max((long)nitems, (long)block->min_output_buffer(port)); nitems -= nitems%grblock->output_multiple(); if( nitems < 1 ) -- cgit From 46f18cd4b0fcc39f1aa2eb12bd0ccc6b90860550 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Oct 2012 16:00:28 -0400 Subject: core: Added QA for max_noutput_items per block and max_output_buffer. --- gnuradio-core/src/lib/runtime/qa_gr_top_block.cc | 100 ++++++++++++++++++++++- gnuradio-core/src/lib/runtime/qa_gr_top_block.h | 4 + 2 files changed, 103 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc index fe0883eba..a0b4755a8 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -140,7 +141,7 @@ void qa_gr_top_block::t5_max_noutputs() void qa_gr_top_block::t6_reconfig_max_noutputs() { - if (VERBOSE) std::cout << "qa_gr_top_block::t5()\n"; + if (VERBOSE) std::cout << "qa_gr_top_block::t6()\n"; gr_top_block_sptr tb = gr_make_top_block("top"); @@ -164,3 +165,100 @@ void qa_gr_top_block::t6_reconfig_max_noutputs() // Wait for flowgraph to end on its own tb->wait(); } + +void qa_gr_top_block::t7_max_noutputs_per_block() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t7()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + head->set_max_noutput_items(100); + + // Start infinite flowgraph + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->start(); + tb->wait(); +} + +void qa_gr_top_block::t8_reconfig_max_noutputs_per_block() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t8()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + head->set_max_noutput_items(99); + + // Start infinite flowgraph + tb->connect(src, 0, dst, 0); + tb->start(201); + + // Reconfigure with gr_head in the middle + tb->lock(); + tb->disconnect(src, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->set_max_noutput_items(1023); + head->set_max_noutput_items(513); + tb->unlock(); + + // Wait for flowgraph to end on its own + tb->wait(); +} + +void qa_gr_top_block::t9_max_output_buffer() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t9()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + head->set_max_output_buffer(1024); + + // Start infinite flowgraph + tb->connect(src, 0, head, 0); + tb->connect(head, 0, dst, 0); + tb->start(); + tb->wait(); +} + +void qa_gr_top_block::t10_reconfig_max_output_buffer() +{ + if (VERBOSE) std::cout << "qa_gr_top_block::t10()\n"; + + gr_top_block_sptr tb = gr_make_top_block("top"); + + gr_block_sptr src = gr_make_null_source(sizeof(int)); + gr_block_sptr head = gr_make_head(sizeof(int), 100000); + gr_block_sptr dst = gr_make_null_sink(sizeof(int)); + + head->set_max_output_buffer(1000); + + // Start infinite flowgraph + tb->connect(src, 0, dst, 0); + tb->start(201); + + // Reconfigure with gr_head in the middle + tb->lock(); + gr_block_sptr nop = gr_make_nop(sizeof(int)); + nop->set_max_output_buffer(4000); + tb->disconnect(src, 0, dst, 0); + tb->connect(src, 0, head, 0); + tb->connect(head, 0, nop, 0); + tb->connect(nop, 0, dst, 0); + tb->unlock(); + + // Wait for flowgraph to end on its own + tb->wait(); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h index 7299ca330..bb891abca 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h @@ -50,6 +50,10 @@ private: void t4_reconfigure(); void t5_max_noutputs(); void t6_reconfig_max_noutputs(); + void t7_max_noutputs_per_block(); + void t8_reconfig_max_noutputs_per_block(); + void t9_max_output_buffer(); + void t10_reconfig_max_output_buffer(); }; #endif /* INCLUDED_QA_GR_TOP_BLOCK_H */ -- cgit From 77035b5d188be9e5dcd6731b1a58a4ce47451bde Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 2 Oct 2012 19:26:32 -0400 Subject: core: fix for restarting the flowgraph with VOLK blocks. --- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index f51e52ce3..b70135b85 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -287,10 +287,10 @@ gr_flat_flowgraph::setup_buffer_alignment(gr_block_sptr block) for(int i = 0; i < block->detail()->ninputs(); i++) { void *r = (void*)block->detail()->input(i)->read_pointer(); unsigned long int ri = (unsigned long int)r % alignment; - //std::cout << "reader: " << r << " alignment: " << ri << std::endl; + //std::cerr << "reader: " << r << " alignment: " << ri << std::endl; if(ri != 0) { size_t itemsize = block->detail()->input(i)->get_sizeof_item(); - block->detail()->input(i)->update_read_pointer(ri/itemsize); + block->detail()->input(i)->update_read_pointer(alignment-ri/itemsize); } block->set_unaligned(0); block->set_is_unaligned(false); @@ -299,10 +299,10 @@ gr_flat_flowgraph::setup_buffer_alignment(gr_block_sptr block) for(int i = 0; i < block->detail()->noutputs(); i++) { void *w = (void*)block->detail()->output(i)->write_pointer(); unsigned long int wi = (unsigned long int)w % alignment; - size_t itemsize = block->detail()->output(i)->get_sizeof_item(); - //std::cout << "writer: " << w << " alignment: " << wi << std::endl; + //std::cerr << "writer: " << w << " alignment: " << wi << std::endl; if(wi != 0) { - block->detail()->output(i)->update_write_pointer(wi/itemsize); + size_t itemsize = block->detail()->output(i)->get_sizeof_item(); + block->detail()->output(i)->update_write_pointer(alignment-wi/itemsize); } block->set_unaligned(0); block->set_is_unaligned(false); -- cgit From a3dfc8b6193b316c95125aafa5c9de1fcf1b6fe3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 8 Oct 2012 00:32:21 -0700 Subject: core: fix several tag includes throughout core Techinically this include should be the tags header which brings in the pmt *and* the tags struct definition. This happens to be working because the struct definition is implicitly included by the gr_block* and subclass headers. --- gnuradio-core/src/lib/runtime/qa_block_tags.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_block_tags.cc b/gnuradio-core/src/lib/runtime/qa_block_tags.cc index 4fa0a0323..d6b1065e3 100644 --- a/gnuradio-core/src/lib/runtime/qa_block_tags.cc +++ b/gnuradio-core/src/lib/runtime/qa_block_tags.cc @@ -33,7 +33,7 @@ #include #include #include -#include +#include // ---------------------------------------------------------------- -- cgit From 83e1adf6f3efee641a994a9f4bb8dc2f827c873b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 22 Nov 2012 10:42:03 -0500 Subject: runtime: moved setting of min/max buffer sizes from gr_basic_block to gr_block. --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 4 +- gnuradio-core/src/lib/runtime/gr_basic_block.h | 77 +--------------------- gnuradio-core/src/lib/runtime/gr_basic_block.i | 6 -- gnuradio-core/src/lib/runtime/gr_block.cc | 4 +- gnuradio-core/src/lib/runtime/gr_block.h | 74 +++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block.i | 8 +++ gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 20 ++++-- 7 files changed, 101 insertions(+), 92 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 3d809aa8b..d7263b92d 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -45,9 +45,7 @@ gr_basic_block::gr_basic_block(const std::string &name, d_input_signature(input_signature), d_output_signature(output_signature), d_unique_id(s_next_id++), - d_color(WHITE), - d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), - d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) + d_color(WHITE) { s_ncurrently_allocated++; } diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index b8e8148b2..cb6a983c4 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -29,9 +29,8 @@ #include #include #include -#include #include -#include +#include /*! * \brief The abstract base class for all signal processing blocks. @@ -62,21 +61,7 @@ private: }; msg_handler_t d_msg_handler; - - /* - * Used to expand the vectors that hold the min/max buffer sizes. - * - * Specifically, when -1 is used, the vectors are just initialized - * with 1 value; this is used by the flat_flowgraph to expand when - * required to add a new value for new ports on these blocks. - */ - void expand_minmax_buffer(int port) { - if((size_t)port >= d_max_output_buffer.size()) - set_max_output_buffer(port, -1); - if((size_t)port >= d_min_output_buffer.size()) - set_min_output_buffer(port, -1); - } - + protected: friend class gr_flowgraph; friend class gr_flat_flowgraph; // TODO: will be redundant @@ -89,8 +74,6 @@ protected: gr_io_signature_sptr d_output_signature; long d_unique_id; vcolor d_color; - std::vector d_max_output_buffer; - std::vector d_min_output_buffer; gr_basic_block(void){} //allows pure virtual interface sub-classes @@ -123,62 +106,6 @@ public: gr_io_signature_sptr output_signature() const { return d_output_signature; } gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion - /*! - * \brief Returns max buffer size on output port \p i. - */ - long max_output_buffer(size_t i) { - if(i >= d_max_output_buffer.size()) - throw std::invalid_argument("gr_basic_block::max_output_buffer: port out of range."); - return d_max_output_buffer[i]; - } - - /*! - * \brief Sets max buffer size on all output ports. - */ - void set_max_output_buffer(long max_output_buffer) { - for(int i=0; imax_streams(); i++) { - set_max_output_buffer(i, max_output_buffer); - } - } - - /*! - * \brief Sets max buffer size on output port \p port. - */ - void set_max_output_buffer(int port, long max_output_buffer) { - if((size_t)port >= d_max_output_buffer.size()) - d_max_output_buffer.push_back(max_output_buffer); - else - d_max_output_buffer[port] = max_output_buffer; - } - - /*! - * \brief Returns min buffer size on output port \p i. - */ - long min_output_buffer(size_t i) { - if(i >= d_min_output_buffer.size()) - throw std::invalid_argument("gr_basic_block::min_output_buffer: port out of range."); - return d_min_output_buffer[i]; - } - - /*! - * \brief Sets min buffer size on all output ports. - */ - void set_min_output_buffer(long min_output_buffer) { - for(int i=0; imax_streams(); i++) { - set_min_output_buffer(i, min_output_buffer); - } - } - - /*! - * \brief Sets min buffer size on output port \p port. - */ - void set_min_output_buffer(int port, long min_output_buffer) { - if((size_t)port >= d_min_output_buffer.size()) - d_min_output_buffer.push_back(min_output_buffer); - else - d_min_output_buffer[port] = min_output_buffer; - } - /*! * \brief Confirm that ninputs and noutputs is an acceptable combination. * diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 7713f2fe1..e43cc114c 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -42,12 +42,6 @@ public: long unique_id() const; gr_basic_block_sptr to_basic_block(); bool check_topology (int ninputs, int noutputs); - long max_output_buffer(int i); - void set_max_output_buffer(long max_output_buffer); - void set_max_output_buffer(int port, long max_output_buffer); - long min_output_buffer(int i); - void set_min_output_buffer(long min_output_buffer); - void set_min_output_buffer(int port, long min_output_buffer); }; %rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 7e01c0ba8..a88052ee0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -42,7 +42,9 @@ gr_block::gr_block (const std::string &name, d_fixed_rate(false), d_max_noutput_items_set(false), d_max_noutput_items(0), - d_tag_propagation_policy(TPP_ALL_TO_ALL) + d_tag_propagation_policy(TPP_ALL_TO_ALL), + d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), + d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) { } diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index c89138bb3..98339080d 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -288,6 +288,76 @@ class GR_CORE_API gr_block : public gr_basic_block { */ bool is_set_max_noutput_items(); + /* + * Used to expand the vectors that hold the min/max buffer sizes. + * + * Specifically, when -1 is used, the vectors are just initialized + * with 1 value; this is used by the flat_flowgraph to expand when + * required to add a new value for new ports on these blocks. + */ + void expand_minmax_buffer(int port) { + if((size_t)port >= d_max_output_buffer.size()) + set_max_output_buffer(port, -1); + if((size_t)port >= d_min_output_buffer.size()) + set_min_output_buffer(port, -1); + } + + /*! + * \brief Returns max buffer size on output port \p i. + */ + long max_output_buffer(size_t i) { + if(i >= d_max_output_buffer.size()) + throw std::invalid_argument("gr_basic_block::max_output_buffer: port out of range."); + return d_max_output_buffer[i]; + } + + /*! + * \brief Sets max buffer size on all output ports. + */ + void set_max_output_buffer(long max_output_buffer) { + for(int i = 0; i < output_signature()->max_streams(); i++) { + set_max_output_buffer(i, max_output_buffer); + } + } + + /*! + * \brief Sets max buffer size on output port \p port. + */ + void set_max_output_buffer(int port, long max_output_buffer) { + if((size_t)port >= d_max_output_buffer.size()) + d_max_output_buffer.push_back(max_output_buffer); + else + d_max_output_buffer[port] = max_output_buffer; + } + + /*! + * \brief Returns min buffer size on output port \p i. + */ + long min_output_buffer(size_t i) { + if(i >= d_min_output_buffer.size()) + throw std::invalid_argument("gr_basic_block::min_output_buffer: port out of range."); + return d_min_output_buffer[i]; + } + + /*! + * \brief Sets min buffer size on all output ports. + */ + void set_min_output_buffer(long min_output_buffer) { + for(int i=0; imax_streams(); i++) { + set_min_output_buffer(i, min_output_buffer); + } + } + + /*! + * \brief Sets min buffer size on output port \p port. + */ + void set_min_output_buffer(int port, long min_output_buffer) { + if((size_t)port >= d_min_output_buffer.size()) + d_min_output_buffer.push_back(min_output_buffer); + else + d_min_output_buffer[port] = min_output_buffer; + } + // ---------------------------------------------------------------------------- private: @@ -384,6 +454,10 @@ class GR_CORE_API gr_block : public gr_basic_block { uint64_t abs_end, const pmt::pmt_t &key); + std::vector d_max_output_buffer; + std::vector d_min_output_buffer; + + // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friend GR_CORE_APIs diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index e9341e8cb..db6c1d04a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -58,6 +58,14 @@ class gr_block : public gr_basic_block { void unset_max_noutput_items(); bool is_set_max_noutput_items(); + // Methods to manage block's min/max buffer sizes. + long max_output_buffer(int i); + void set_max_output_buffer(long max_output_buffer); + void set_max_output_buffer(int port, long max_output_buffer); + long min_output_buffer(int i); + void set_min_output_buffer(long min_output_buffer); + void set_min_output_buffer(int port, long min_output_buffer); + // internal use gr_block_detail_sptr detail () const { return d_detail; } void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index b70135b85..b82ef46af 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -79,19 +79,25 @@ gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block) int ninputs = calc_used_ports(block, true).size(); int noutputs = calc_used_ports(block, false).size(); gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); + gr_block_sptr grblock = cast_to_block_sptr(block); if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Creating block detail for " << block << std::endl; for (int i = 0; i < noutputs; i++) { - block->expand_minmax_buffer(i); + if(grblock) { + grblock->expand_minmax_buffer(i); + } + gr_buffer_sptr buffer = allocate_buffer(block, i); if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Allocated buffer for output " << block << ":" << i << std::endl; detail->set_output(i, buffer); - // Update the block's max_output_buffer based on what was actually allocated. - block->set_max_output_buffer(i, buffer->bufsize()); + if(grblock) { + // Update the block's max_output_buffer based on what was actually allocated. + grblock->set_max_output_buffer(i, buffer->bufsize()); + } } return detail; @@ -119,15 +125,15 @@ gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); // limit buffer size if indicated - if(block->max_output_buffer(port) > 0) { + if(grblock->max_output_buffer(port) > 0) { // std::cout << "constraining output items to " << block->max_output_buffer(port) << "\n"; - nitems = std::min((long)nitems, (long)block->max_output_buffer(port)); + nitems = std::min((long)nitems, (long)grblock->max_output_buffer(port)); nitems -= nitems%grblock->output_multiple(); if( nitems < 1 ) throw std::runtime_error("problems allocating a buffer with the given max output buffer constraint!"); } - else if(block->min_output_buffer(port) > 0) { - nitems = std::max((long)nitems, (long)block->min_output_buffer(port)); + else if(grblock->min_output_buffer(port) > 0) { + nitems = std::max((long)nitems, (long)grblock->min_output_buffer(port)); nitems -= nitems%grblock->output_multiple(); if( nitems < 1 ) throw std::runtime_error("problems allocating a buffer with the given min output buffer constraint!"); -- cgit From 5a6f3e4bc8fc6af84bb09294b77bb4456c4c77f0 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 22 Nov 2012 14:10:31 -0500 Subject: runtime: changed check after cast to gr_block. --- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index b82ef46af..e04deb948 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -79,25 +79,24 @@ gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block) int ninputs = calc_used_ports(block, true).size(); int noutputs = calc_used_ports(block, false).size(); gr_block_detail_sptr detail = gr_make_block_detail(ninputs, noutputs); + gr_block_sptr grblock = cast_to_block_sptr(block); + if(!grblock) + throw std::runtime_error("allocate_block_detail found non-gr_block"); if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Creating block detail for " << block << std::endl; for (int i = 0; i < noutputs; i++) { - if(grblock) { - grblock->expand_minmax_buffer(i); - } + grblock->expand_minmax_buffer(i); gr_buffer_sptr buffer = allocate_buffer(block, i); if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Allocated buffer for output " << block << ":" << i << std::endl; detail->set_output(i, buffer); - if(grblock) { - // Update the block's max_output_buffer based on what was actually allocated. - grblock->set_max_output_buffer(i, buffer->bufsize()); - } + // Update the block's max_output_buffer based on what was actually allocated. + grblock->set_max_output_buffer(i, buffer->bufsize()); } return detail; -- cgit From 92cfb0240005675f4e7a55a81552f4c7a5128cd8 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Wed, 28 Nov 2012 15:15:58 -0800 Subject: core: adding msg_connect, updating msg interface, adding symbolic block names --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 2 + gnuradio-core/src/lib/runtime/gr_basic_block.cc | 117 ++++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_basic_block.h | 85 +++++++++++++-- gnuradio-core/src/lib/runtime/gr_basic_block.i | 3 + gnuradio-core/src/lib/runtime/gr_block_detail.cc | 6 -- gnuradio-core/src/lib/runtime/gr_block_detail.h | 5 - gnuradio-core/src/lib/runtime/gr_block_registry.cc | 58 ++++++++++ gnuradio-core/src/lib/runtime/gr_block_registry.h | 36 +++++++ gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 30 ++++++ gnuradio-core/src/lib/runtime/gr_hier_block2.h | 15 +++ gnuradio-core/src/lib/runtime/gr_hier_block2.i | 15 +++ .../src/lib/runtime/gr_hier_block2_detail.cc | 22 ++++ .../src/lib/runtime/gr_hier_block2_detail.h | 4 + gnuradio-core/src/lib/runtime/gr_msg_accepter.cc | 4 +- gnuradio-core/src/lib/runtime/gr_msg_accepter.h | 2 +- gnuradio-core/src/lib/runtime/gr_tpb_detail.cc | 40 ------- gnuradio-core/src/lib/runtime/gr_tpb_detail.h | 26 ++--- .../src/lib/runtime/gr_tpb_thread_body.cc | 41 +++++--- .../src/lib/runtime/qa_set_msg_handler.cc | 5 +- 19 files changed, 419 insertions(+), 97 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/gr_block_registry.cc create mode 100644 gnuradio-core/src/lib/runtime/gr_block_registry.h (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 5f3672dde..70938a0f1 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -54,6 +54,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_detail.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_executor.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_registry.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2_detail.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_buffer.cc @@ -116,6 +117,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_detail.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_executor.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_registry.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2_detail.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_buffer.h diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index d7263b92d..3d08b63d1 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -25,7 +25,9 @@ #endif #include +#include #include +#include using namespace pmt; @@ -45,7 +47,10 @@ gr_basic_block::gr_basic_block(const std::string &name, d_input_signature(input_signature), d_output_signature(output_signature), d_unique_id(s_next_id++), - d_color(WHITE) + d_symbolic_id(global_block_registry.block_register(this)), + d_symbol_name(global_block_registry.register_symbolic_name(this)), + d_color(WHITE), + message_subscribers(pmt::pmt_make_dict()) { s_ncurrently_allocated++; } @@ -53,6 +58,7 @@ gr_basic_block::gr_basic_block(const std::string &name, gr_basic_block::~gr_basic_block() { s_ncurrently_allocated--; + global_block_registry.block_unregister(this); } gr_basic_block_sptr @@ -60,3 +66,112 @@ gr_basic_block::to_basic_block() { return shared_from_this(); } + +void +gr_basic_block::set_block_alias(std::string name) +{ + global_block_registry.register_symbolic_name(this, name); +} + +// ** Message passing interface ** + +// - register a new input message port +void gr_basic_block::message_port_register_in(pmt::pmt_t port_id){ + msg_queue[port_id] = msg_queue_t(); + } + +// - register a new output message port +void gr_basic_block::message_port_register_out(pmt::pmt_t port_id){ + if(!pmt::pmt_is_symbol(port_id)){ throw std::runtime_error("bad port id"); } + if(pmt::pmt_dict_has_key(message_subscribers, port_id)){ throw std::runtime_error("port already in use"); } + message_subscribers = pmt::pmt_dict_add(message_subscribers, port_id, pmt::PMT_NIL); + } + +// - publish a message on a message port +void gr_basic_block::message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg){ + if(!pmt::pmt_dict_has_key(message_subscribers, port_id)){ throw std::runtime_error("port does not exist"); } + pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); + // iterate through subscribers on port + while( pmt::pmt_is_pair(currlist) ){ + pmt::pmt_t target = pmt::pmt_car(currlist); + + pmt::pmt_t block = pmt::pmt_car(target); + pmt::pmt_t port = pmt::pmt_cdr(target); + + currlist = pmt::pmt_cdr(currlist); + gr_basic_block_sptr blk = global_block_registry.block_lookup(block); + //blk->post(msg); + blk->post(port, msg); + } + } + +// - subscribe to a message port +void gr_basic_block::message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target){ + if(!pmt::pmt_dict_has_key(message_subscribers, port_id)){ + std::stringstream ss; + ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) << "\" on block: " << pmt::pmt_write_string(target) << std::endl; + throw std::runtime_error(ss.str()); + } + pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); + message_subscribers = pmt::pmt_dict_add(message_subscribers,port_id,pmt::pmt_list_add(currlist,target)); + } + +void gr_basic_block::message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target){ + if(!pmt::pmt_dict_has_key(message_subscribers, port_id)){ + std::stringstream ss; + ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) << "\" on block: " << pmt::pmt_write_string(target) << std::endl; + throw std::runtime_error(ss.str()); + } + pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); + message_subscribers = pmt::pmt_dict_add(message_subscribers,port_id,pmt::pmt_list_rm(currlist,target)); + } + +void +gr_basic_block::_post(pmt_t which_port, pmt_t msg) +{ + insert_tail(which_port, msg); + //notify_msg(); +} + +void +gr_basic_block::insert_tail(pmt::pmt_t which_port, pmt::pmt_t msg) +{ + gruel::scoped_lock guard(mutex); + + msg_queue[which_port].push_back(msg); + + // wake up thread if BLKD_IN or BLKD_OUT + //input_cond.notify_one(); + //output_cond.notify_one(); + // TODO: reconsider the need for notification of input and output conditions! +} + +pmt_t +gr_basic_block::delete_head_nowait(pmt::pmt_t which_port) +{ + gruel::scoped_lock guard(mutex); + + if (empty_p(which_port)) + return pmt_t(); + + pmt_t m(msg_queue[which_port].front()); + msg_queue[which_port].pop_front(); + + return m; +} + +/* + * Caller must already be holding the mutex + */ +pmt_t +gr_basic_block::delete_head_nowait_already_holding_mutex(pmt::pmt_t which_port) +{ + if (empty_p(which_port)) + return pmt_t(); + + pmt_t m(msg_queue[which_port].front()); + msg_queue[which_port].pop_front(); + + return m; +} + diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index cb6a983c4..31026a2e4 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -30,7 +30,11 @@ #include #include #include +#include +#include #include +#include +#include /*! * \brief The abstract base class for all signal processing blocks. @@ -54,14 +58,23 @@ private: * The thread-safety guarantees mentioned in set_msg_handler are implemented * by the callers of this method. */ - void dispatch_msg(pmt::pmt_t msg) + void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) { - if (d_msg_handler) // Is there a handler? - d_msg_handler(msg); // Yes, invoke it. + // AA Update this + if (d_msg_handlers.find(which_port) != d_msg_handlers.end()) // Is there a handler? + d_msg_handlers[which_port](msg); // Yes, invoke it. }; - msg_handler_t d_msg_handler; + //msg_handler_t d_msg_handler; + typedef std::map d_msg_handlers_t; + d_msg_handlers_t d_msg_handlers; + typedef std::deque msg_queue_t; + typedef std::map msg_queue_map_t; + msg_queue_map_t msg_queue; + gruel::mutex mutex; //< protects all vars + + protected: friend class gr_flowgraph; friend class gr_flat_flowgraph; // TODO: will be redundant @@ -73,6 +86,9 @@ protected: gr_io_signature_sptr d_input_signature; gr_io_signature_sptr d_output_signature; long d_unique_id; + long d_symbolic_id; + std::string d_symbol_name; + std::string d_symbol_alias; vcolor d_color; gr_basic_block(void){} //allows pure virtual interface sub-classes @@ -98,13 +114,65 @@ protected: void set_color(vcolor color) { d_color = color; } vcolor color() const { return d_color; } + // Message passing interface + std::vector message_inputs; + pmt::pmt_t message_subscribers; + public: virtual ~gr_basic_block(); long unique_id() const { return d_unique_id; } + long symbolic_id() const { return d_symbolic_id; } std::string name() const { return d_name; } + std::string symbol_name() const { return d_symbol_name; } gr_io_signature_sptr input_signature() const { return d_input_signature; } gr_io_signature_sptr output_signature() const { return d_output_signature; } gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion + bool alias_set() { return !d_symbol_alias.empty(); } + std::string alias(){ return alias_set()?d_symbol_alias:symbol_name(); } + pmt::pmt_t alias_pmt(){ return pmt::pmt_intern(alias()); } + void set_block_alias(std::string name); + + // ** Message passing interface ** + void message_port_register_in(pmt::pmt_t port_id); + void message_port_register_out(pmt::pmt_t port_id); + void message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg); + void message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target); + void message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target); + + /*! + * Accept msg, place in queue, arrange for thread to be awakened if it's not already. + */ + void _post(pmt::pmt_t which_port, pmt::pmt_t msg); + + + //! is the queue empty? + //bool empty_p(const pmt::pmt_t &which_port) const { return msg_queue[which_port].empty(); } + bool empty_p(pmt::pmt_t which_port) { return msg_queue[which_port].empty(); } + bool empty_p() { + bool rv = true; + BOOST_FOREACH(msg_queue_map_t::value_type &i, msg_queue){ rv &= msg_queue[i.first].empty(); } + return rv; + } + + //| Acquires and release the mutex + void insert_tail( pmt::pmt_t which_port, pmt::pmt_t msg); + /*! + * \returns returns pmt at head of queue or pmt_t() if empty. + */ + pmt::pmt_t delete_head_nowait( pmt::pmt_t which_port); + /*! + * \returns returns pmt at head of queue or pmt_t() if empty. + * Caller must already be holding the mutex + */ + pmt::pmt_t delete_head_nowait_already_holding_mutex( pmt::pmt_t which_port); + + msg_queue_t::iterator get_iterator(pmt::pmt_t which_port){ + return msg_queue[which_port].begin(); + } + void erase_msg(pmt::pmt_t which_port, msg_queue_t::iterator it){ + msg_queue[which_port].erase(it); + } + /*! * \brief Confirm that ninputs and noutputs is an acceptable combination. @@ -147,8 +215,13 @@ public: * If the block inherits from gr_hier_block2, the runtime system will * ensure that no reentrant calls are made to msg_handler. */ - template void set_msg_handler(T msg_handler){ - d_msg_handler = msg_handler_t(msg_handler); + //template void set_msg_handler(T msg_handler){ + // d_msg_handler = msg_handler_t(msg_handler); + //} + template void set_msg_handler(pmt::pmt_t which_port, T msg_handler){ + if(msg_queue.find(which_port) == msg_queue.end()){ + throw std::runtime_error("attempt to set_msg_handler() on bad input message port!"); } + d_msg_handlers[which_port] = msg_handler_t(msg_handler); } }; diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index e43cc114c..0a8473ba2 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -37,11 +37,14 @@ protected: public: virtual ~gr_basic_block(); std::string name() const; + std::string symbol_name() const; gr_io_signature_sptr input_signature() const; gr_io_signature_sptr output_signature() const; long unique_id() const; gr_basic_block_sptr to_basic_block(); bool check_topology (int ninputs, int noutputs); + std::string alias(); + void set_block_alias(std::string name); }; %rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 2792cd471..337c9518e 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -127,12 +127,6 @@ gr_block_detail::produce_each (int how_many_items) } -void -gr_block_detail::_post(pmt_t msg) -{ - d_tpb.insert_tail(msg); -} - uint64_t gr_block_detail::nitems_read(unsigned int which_input) { diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index c96f00db8..16d9f4d42 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -85,11 +85,6 @@ class GR_CORE_API gr_block_detail { */ 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); - // Return the number of items read on input stream which_input uint64_t nitems_read(unsigned int which_input); diff --git a/gnuradio-core/src/lib/runtime/gr_block_registry.cc b/gnuradio-core/src/lib/runtime/gr_block_registry.cc new file mode 100644 index 000000000..2478e0019 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block_registry.cc @@ -0,0 +1,58 @@ +#include +#include + +gr_block_registry global_block_registry; + +gr_block_registry::gr_block_registry(){ + d_ref_map = pmt::pmt_make_dict(); +} + +long gr_block_registry::block_register(gr_basic_block* block){ + if(d_map.find(block->name()) == d_map.end()){ + d_map[block->name()] = blocksubmap_t(); + d_map[block->name()][0] = block; + return 0; + } else { + for(size_t i=0; i<=d_map[block->name()].size(); i++){ + if(d_map[block->name()].find(i) == d_map[block->name()].end()){ + d_map[block->name()][i] = block; + return i; + } + } + } + throw std::runtime_error("should not reach this"); +} + +void gr_block_registry::block_unregister(gr_basic_block* block){ + d_map[block->name()].erase( d_map[block->name()].find(block->symbolic_id())); + d_ref_map = pmt::pmt_dict_delete(d_ref_map, pmt::pmt_intern(block->symbol_name())); + if(block->alias_set()){ + d_ref_map = pmt::pmt_dict_delete(d_ref_map, pmt::pmt_intern(block->alias())); + } +} + +std::string gr_block_registry::register_symbolic_name(gr_basic_block* block){ + std::stringstream ss; + ss << block->name() << block->symbolic_id(); + //std::cout << "register_symbolic_name: " << ss.str() << std::endl; + register_symbolic_name(block, ss.str()); + return ss.str(); +} + +void gr_block_registry::register_symbolic_name(gr_basic_block* block, std::string name){ + if(pmt_dict_has_key(d_ref_map, pmt::pmt_intern(name))){ + throw std::runtime_error("symbol already exists, can not re-use!"); + } + d_ref_map = pmt_dict_add(d_ref_map, pmt::pmt_intern(name), pmt::pmt_make_any(block)); +} + +gr_basic_block_sptr gr_block_registry::block_lookup(pmt::pmt_t symbol){ + pmt::pmt_t ref = pmt_dict_ref(d_ref_map, symbol, pmt::PMT_NIL); + if(pmt::pmt_eq(ref, pmt::PMT_NIL)){ + throw std::runtime_error("block lookup failed! block not found!"); + } + gr_basic_block* blk = boost::any_cast( pmt::pmt_any_ref(ref) ); + return blk->shared_from_this(); +} + + diff --git a/gnuradio-core/src/lib/runtime/gr_block_registry.h b/gnuradio-core/src/lib/runtime/gr_block_registry.h new file mode 100644 index 000000000..8f1982984 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/gr_block_registry.h @@ -0,0 +1,36 @@ +#ifndef GR_BLOCK_REGISTRY_H +#define GR_BLOCK_REGISTRY_H + +#include + +#ifndef GR_BASIC_BLOCK_H +class gr_basic_block; +#endif + +class gr_block_registry { + public: + gr_block_registry(); + + long block_register(gr_basic_block* block); + void block_unregister(gr_basic_block* block); + + std::string register_symbolic_name(gr_basic_block* block); + void register_symbolic_name(gr_basic_block* block, std::string name); + + gr_basic_block_sptr block_lookup(pmt::pmt_t symbol); + + private: + + //typedef std::map< long, gr_basic_block_sptr > blocksubmap_t; + typedef std::map< long, gr_basic_block* > blocksubmap_t; + typedef std::map< std::string, blocksubmap_t > blockmap_t; + + blockmap_t d_map; + pmt::pmt_t d_ref_map; + +}; + +extern gr_block_registry global_block_registry; + +#endif + diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index 756852df8..a19bfe195 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -80,6 +80,36 @@ gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, d_detail->connect(src, src_port, dst, dst_port); } +void +gr_hier_block2::msg_connect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport) +{ + if(!pmt::pmt_is_symbol(srcport)){throw std::runtime_error("bad port id"); } + d_detail->msg_connect(src, srcport, dst, dstport); +} + +void +gr_hier_block2::msg_connect(gr_basic_block_sptr src, std::string srcport, + gr_basic_block_sptr dst, std::string dstport) +{ + d_detail->msg_connect(src, pmt::mp(srcport), dst, pmt::mp(dstport)); +} + +void +gr_hier_block2::msg_disconnect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport) +{ + if(!pmt::pmt_is_symbol(srcport)){throw std::runtime_error("bad port id"); } + d_detail->msg_disconnect(src, srcport, dst, dstport); +} + +void +gr_hier_block2::msg_disconnect(gr_basic_block_sptr src, std::string srcport, + gr_basic_block_sptr dst, std::string dstport) +{ + d_detail->msg_disconnect(src, pmt::mp(srcport), dst, pmt::mp(dstport)); +} + void gr_hier_block2::disconnect(gr_basic_block_sptr block) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 123178724..e8364a740 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -97,6 +97,21 @@ public: void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); + /*! + * \brief Add gr-blocks or hierarchical blocks to internal graph and wire together + * + * This adds (if not done earlier by another connect) a pair of gr-blocks or + * hierarchical blocks to the internal message port subscription + */ + void msg_connect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport); + void msg_connect(gr_basic_block_sptr src, std::string srcport, + gr_basic_block_sptr dst, std::string dstport); + void msg_disconnect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport); + void msg_disconnect(gr_basic_block_sptr src, std::string srcport, + gr_basic_block_sptr dst, std::string dstport); + /*! * \brief Remove a gr-block or hierarchical block from the internal flowgraph. * diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index eefb965b4..7c0e62f28 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -38,6 +38,8 @@ gr_hier_block2_sptr gr_make_hier_block2(const std::string name, // better interface in scripting land. %rename(primitive_connect) gr_hier_block2::connect; %rename(primitive_disconnect) gr_hier_block2::disconnect; +%rename(primitive_msg_connect) gr_hier_block2::msg_connect; +%rename(primitive_msg_disconnect) gr_hier_block2::msg_disconnect; class gr_hier_block2 : public gr_basic_block { @@ -54,6 +56,19 @@ public: void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port) throw (std::invalid_argument); + void msg_connect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport) + throw (std::runtime_error); + void msg_connect(gr_basic_block_sptr src, std::string srcport, + gr_basic_block_sptr dst, std::string dstport) + throw (std::runtime_error); + void msg_disconnect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport) + throw (std::runtime_error); + void msg_disconnect(gr_basic_block_sptr src, std::string srcport, + gr_basic_block_sptr dst, std::string dstport) + throw (std::runtime_error); + void disconnect(gr_basic_block_sptr block) throw (std::invalid_argument); void disconnect(gr_basic_block_sptr src, int src_port, diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 76c5ce06f..099b2f8e8 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -143,6 +143,28 @@ gr_hier_block2_detail::connect(gr_basic_block_sptr src, int src_port, // TODO: connects to NC } +void +gr_hier_block2_detail::msg_connect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport) +{ + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "connecting message port..." << std::endl; + + // register the subscription + src->message_port_sub(srcport, pmt::pmt_cons(dst->alias_pmt(), dstport)); +} + +void +gr_hier_block2_detail::msg_disconnect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport) +{ + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "disconnecting message port..." << std::endl; + + // register the subscription + src->message_port_unsub(srcport, pmt::pmt_cons(dst->alias_pmt(), dstport)); +} + void gr_hier_block2_detail::disconnect(gr_basic_block_sptr block) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index f4f950e9d..f2d2b3c4e 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -39,6 +39,10 @@ public: void connect(gr_basic_block_sptr block); void connect(gr_basic_block_sptr src, int src_port, gr_basic_block_sptr dst, int dst_port); + void msg_connect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport); + void msg_disconnect(gr_basic_block_sptr src, pmt::pmt_t srcport, + gr_basic_block_sptr dst, pmt::pmt_t dstport); void disconnect(gr_basic_block_sptr block); void disconnect(gr_basic_block_sptr, int src_port, gr_basic_block_sptr, int dst_port); diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc index 5018ee9e6..93d5fb20e 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.cc @@ -41,12 +41,12 @@ gr_msg_accepter::~gr_msg_accepter() } void -gr_msg_accepter::post(pmt_t msg) +gr_msg_accepter::post(pmt_t which_port, pmt_t msg) { // Notify derived class, handled case by case gr_block *p = dynamic_cast(this); if (p) { - p->detail()->_post(msg); + p->_post(which_port,msg); return; } gr_hier_block2 *p2 = dynamic_cast(this); diff --git a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h index 3e5c97638..a497ba6e7 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_accepter.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_accepter.h @@ -36,7 +36,7 @@ public: gr_msg_accepter(); ~gr_msg_accepter(); - void post(pmt::pmt_t msg); + void post(pmt::pmt_t which_port, pmt::pmt_t msg); }; diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc b/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc index 46b33d91f..46eb6bbe0 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.cc @@ -68,43 +68,3 @@ gr_tpb_detail::notify_neighbors(gr_block_detail *d) notify_upstream(d); } -void -gr_tpb_detail::insert_tail(pmt::pmt_t msg) -{ - gruel::scoped_lock guard(mutex); - - msg_queue.push_back(msg); - - // wake up thread if BLKD_IN or BLKD_OUT - input_cond.notify_one(); - output_cond.notify_one(); -} - -pmt_t -gr_tpb_detail::delete_head_nowait() -{ - gruel::scoped_lock guard(mutex); - - if (empty_p()) - return pmt_t(); - - pmt_t m(msg_queue.front()); - msg_queue.pop_front(); - - return m; -} - -/* - * Caller must already be holding the mutex - */ -pmt_t -gr_tpb_detail::delete_head_nowait_already_holding_mutex() -{ - if (empty_p()) - return pmt_t(); - - pmt_t m(msg_queue.front()); - msg_queue.pop_front(); - - return m; -} diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h index b6e342dee..69feb6007 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h @@ -39,9 +39,6 @@ struct GR_CORE_API gr_tpb_detail { bool output_changed; gruel::condition_variable output_cond; -private: - std::deque msg_queue; - public: gr_tpb_detail() : input_changed(false), output_changed(false) { } @@ -55,6 +52,12 @@ public: //! Called by us to notify both upstream and downstream void notify_neighbors(gr_block_detail *d); + //! Called by pmt msg posters + void notify_msg(){ + input_cond.notify_one(); + output_cond.notify_one(); + } + //! Called by us void clear_changed() { @@ -63,23 +66,6 @@ public: output_changed = false; } - //! is the queue empty? - bool empty_p() const { return msg_queue.empty(); } - - //| Acquires and release the mutex - void insert_tail(pmt::pmt_t msg); - - /*! - * \returns returns pmt at head of queue or pmt_t() if empty. - */ - pmt::pmt_t delete_head_nowait(); - - /*! - * \returns returns pmt at head of queue or pmt_t() if empty. - * Caller must already be holding the mutex - */ - pmt::pmt_t delete_head_nowait_already_holding_mutex(); - private: //! Used by notify_downstream diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index a5aabb379..1bd3014ad 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -25,6 +25,7 @@ #include #include #include +#include using namespace pmt; @@ -42,8 +43,14 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item boost::this_thread::interruption_point(); // handle any queued up messages - while ((msg = d->d_tpb.delete_head_nowait())) - block->dispatch_msg(msg); + //BOOST_FOREACH( pmt::pmt_t port, block->msg_queue.keys() ) + + BOOST_FOREACH( gr_basic_block::msg_queue_map_t::value_type &i, block->msg_queue ) + { + while ((msg = block->delete_head_nowait(i.first))){ + block->dispatch_msg(i.first,msg); + } + } d->d_tpb.clear_changed(); s = d_exec.run_one_iteration(); @@ -67,15 +74,18 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item while (!d->d_tpb.input_changed){ // wait for input or message - while(!d->d_tpb.input_changed && d->d_tpb.empty_p()) + while(!d->d_tpb.input_changed && block->empty_p()) d->d_tpb.input_cond.wait(guard); // handle all pending messages - while ((msg = d->d_tpb.delete_head_nowait_already_holding_mutex())){ - guard.unlock(); // release lock while processing msg - block->dispatch_msg(msg); - guard.lock(); - } + BOOST_FOREACH( gr_basic_block::msg_queue_map_t::value_type &i, block->msg_queue ) + { + while ((msg = block->delete_head_nowait_already_holding_mutex(i.first))){ + guard.unlock(); // release lock while processing msg + block->dispatch_msg(i.first, msg); + guard.lock(); + } + } } } break; @@ -87,15 +97,18 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item while (!d->d_tpb.output_changed){ // wait for output room or message - while(!d->d_tpb.output_changed && d->d_tpb.empty_p()) + while(!d->d_tpb.output_changed && block->empty_p()) d->d_tpb.output_cond.wait(guard); // handle all pending messages - while ((msg = d->d_tpb.delete_head_nowait_already_holding_mutex())){ - guard.unlock(); // release lock while processing msg - block->dispatch_msg(msg); - guard.lock(); - } + BOOST_FOREACH( gr_basic_block::msg_queue_map_t::value_type &i, block->msg_queue ) + { + while ((msg = block->delete_head_nowait_already_holding_mutex(i.first))){ + guard.unlock(); // release lock while processing msg + block->dispatch_msg(i.first,msg); + guard.lock(); + } + } } } break; diff --git a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc index 25ae0b1e1..dc8f0f8a9 100644 --- a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc +++ b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc @@ -65,14 +65,15 @@ void qa_set_msg_handler::t0() tb->start(); // Send them... + pmt_t port(pmt_intern("port")); for (int i = 0; i < NMSGS; i++){ - send(nop, mp(mp("example-msg"), mp(i))); + send(nop, port, mp(mp("example-msg"), mp(i))); } // And send a message to null_source to confirm that the default // message handling action (which should be a nop) doesn't dump // core. - send(src, mp(mp("example-msg"), mp(0))); + send(src, port, mp(mp("example-msg"), mp(0))); // Give the messages a chance to be processed boost::this_thread::sleep(boost::posix_time::milliseconds(100)); -- cgit From 4478cb86a5dc9fccf66c2cdd5806419b70c3837e Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 29 Nov 2012 19:46:29 -0800 Subject: Adding PDU to tagged stream and tagged stream to PDU blocks along with QA python non-stream-connected blocks still need a new thread context --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 22 +++++----------------- gnuradio-core/src/lib/runtime/gr_basic_block.h | 21 +++++++++------------ gnuradio-core/src/lib/runtime/gr_basic_block.i | 3 +++ gnuradio-core/src/lib/runtime/gr_block.cc | 3 +++ gnuradio-core/src/lib/runtime/gr_block_registry.cc | 18 ++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block_registry.h | 10 ++++++++-- .../src/lib/runtime/gr_tpb_thread_body.cc | 4 ++-- 7 files changed, 48 insertions(+), 33 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 3d08b63d1..7d2f275e8 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -52,6 +52,7 @@ gr_basic_block::gr_basic_block(const std::string &name, d_color(WHITE), message_subscribers(pmt::pmt_make_dict()) { + mutex.unlock(); s_ncurrently_allocated++; } @@ -130,7 +131,7 @@ void gr_basic_block::_post(pmt_t which_port, pmt_t msg) { insert_tail(which_port, msg); - //notify_msg(); + global_block_registry.notify_blk(alias()); } void @@ -151,8 +152,9 @@ gr_basic_block::delete_head_nowait(pmt::pmt_t which_port) { gruel::scoped_lock guard(mutex); - if (empty_p(which_port)) - return pmt_t(); + if (empty_p(which_port)){ + return pmt::pmt_t(); + } pmt_t m(msg_queue[which_port].front()); msg_queue[which_port].pop_front(); @@ -160,18 +162,4 @@ gr_basic_block::delete_head_nowait(pmt::pmt_t which_port) return m; } -/* - * Caller must already be holding the mutex - */ -pmt_t -gr_basic_block::delete_head_nowait_already_holding_mutex(pmt::pmt_t which_port) -{ - if (empty_p(which_port)) - return pmt_t(); - - pmt_t m(msg_queue[which_port].front()); - msg_queue[which_port].pop_front(); - - return m; -} diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 31026a2e4..2ee8161c1 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -115,7 +115,6 @@ protected: vcolor color() const { return d_color; } // Message passing interface - std::vector message_inputs; pmt::pmt_t message_subscribers; public: @@ -139,15 +138,18 @@ public: void message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target); void message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target); - /*! - * Accept msg, place in queue, arrange for thread to be awakened if it's not already. - */ - void _post(pmt::pmt_t which_port, pmt::pmt_t msg); - + /*! + * Accept msg, place in queue, arrange for thread to be awakened if it's not already. + */ + void _post(pmt::pmt_t which_port, pmt::pmt_t msg); //! is the queue empty? //bool empty_p(const pmt::pmt_t &which_port) const { return msg_queue[which_port].empty(); } - bool empty_p(pmt::pmt_t which_port) { return msg_queue[which_port].empty(); } + bool empty_p(pmt::pmt_t which_port) { + if(msg_queue.find(which_port) == msg_queue.end()) + throw std::runtime_error("port does not exist!"); + return msg_queue[which_port].empty(); + } bool empty_p() { bool rv = true; BOOST_FOREACH(msg_queue_map_t::value_type &i, msg_queue){ rv &= msg_queue[i.first].empty(); } @@ -160,11 +162,6 @@ public: * \returns returns pmt at head of queue or pmt_t() if empty. */ pmt::pmt_t delete_head_nowait( pmt::pmt_t which_port); - /*! - * \returns returns pmt at head of queue or pmt_t() if empty. - * Caller must already be holding the mutex - */ - pmt::pmt_t delete_head_nowait_already_holding_mutex( pmt::pmt_t which_port); msg_queue_t::iterator get_iterator(pmt::pmt_t which_port){ return msg_queue[which_port].begin(); diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 0a8473ba2..d6d6c3d16 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -23,6 +23,8 @@ class gr_basic_block; typedef boost::shared_ptr gr_basic_block_sptr; %template(gr_basic_block_sptr) boost::shared_ptr; +%include "pmt_swig.i" +using namespace pmt; // support vectors of these... namespace std { @@ -45,6 +47,7 @@ public: bool check_topology (int ninputs, int noutputs); std::string alias(); void set_block_alias(std::string name); + void _post(pmt_t which_port, pmt_t msg); }; %rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index a88052ee0..dc77128a3 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -28,6 +28,7 @@ #include #include #include +#include gr_block::gr_block (const std::string &name, gr_io_signature_sptr input_signature, @@ -46,10 +47,12 @@ gr_block::gr_block (const std::string &name, d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) { + global_block_registry.register_primitive(alias(), this); } gr_block::~gr_block () { + global_block_registry.unregister_primitive(alias()); } // stub implementation: 1:1 diff --git a/gnuradio-core/src/lib/runtime/gr_block_registry.cc b/gnuradio-core/src/lib/runtime/gr_block_registry.cc index 2478e0019..ff23d97eb 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_registry.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_registry.cc @@ -1,5 +1,9 @@ #include #include +#include +#include +#include +#include gr_block_registry global_block_registry; @@ -56,3 +60,17 @@ gr_basic_block_sptr gr_block_registry::block_lookup(pmt::pmt_t symbol){ } +void gr_block_registry::register_primitive(std::string blk, gr_block* ref){ + primitive_map[blk] = ref; +} + +void gr_block_registry::unregister_primitive(std::string blk){ + primitive_map.erase(primitive_map.find(blk)); +} + +void gr_block_registry::notify_blk(std::string blk){ + if(primitive_map.find(blk) == primitive_map.end()){ return; } + if(primitive_map[blk]->detail().get()) + primitive_map[blk]->detail()->d_tpb.notify_msg(); +} + diff --git a/gnuradio-core/src/lib/runtime/gr_block_registry.h b/gnuradio-core/src/lib/runtime/gr_block_registry.h index 8f1982984..6a2d939e5 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_registry.h +++ b/gnuradio-core/src/lib/runtime/gr_block_registry.h @@ -5,6 +5,7 @@ #ifndef GR_BASIC_BLOCK_H class gr_basic_block; +class gr_block; #endif class gr_block_registry { @@ -18,7 +19,11 @@ class gr_block_registry { void register_symbolic_name(gr_basic_block* block, std::string name); gr_basic_block_sptr block_lookup(pmt::pmt_t symbol); - + + void register_primitive(std::string blk, gr_block* ref); + void unregister_primitive(std::string blk); + void notify_blk(std::string blk); + private: //typedef std::map< long, gr_basic_block_sptr > blocksubmap_t; @@ -27,7 +32,8 @@ class gr_block_registry { blockmap_t d_map; pmt::pmt_t d_ref_map; - + std::map< std::string, gr_block*> primitive_map; + }; extern gr_block_registry global_block_registry; diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index 1bd3014ad..ff2afca10 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -80,7 +80,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item // handle all pending messages BOOST_FOREACH( gr_basic_block::msg_queue_map_t::value_type &i, block->msg_queue ) { - while ((msg = block->delete_head_nowait_already_holding_mutex(i.first))){ + while ((msg = block->delete_head_nowait(i.first))){ guard.unlock(); // release lock while processing msg block->dispatch_msg(i.first, msg); guard.lock(); @@ -103,7 +103,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item // handle all pending messages BOOST_FOREACH( gr_basic_block::msg_queue_map_t::value_type &i, block->msg_queue ) { - while ((msg = block->delete_head_nowait_already_holding_mutex(i.first))){ + while ((msg = block->delete_head_nowait(i.first))){ guard.unlock(); // release lock while processing msg block->dispatch_msg(i.first,msg); guard.lock(); -- cgit From 6cc818260128df57c51a41e4e6aa459de5faf4fe Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Fri, 30 Nov 2012 22:31:43 -0800 Subject: core: gr_blocks can now have only message ports with no general_work() * msg only blocks now get thread context * added blocking msg queue delete call * added gr_message_strobe block * added grc definitions for message_debug, message_strobe, pdu_to_tagged_stream, tagged_stream_to_pdu. * allow message fan-in connections in GRC --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 29 ++++++++++++++++++---- gnuradio-core/src/lib/runtime/gr_basic_block.h | 9 +++++++ gnuradio-core/src/lib/runtime/gr_block.cc | 9 +++++++ gnuradio-core/src/lib/runtime/gr_block.h | 2 +- gnuradio-core/src/lib/runtime/gr_flowgraph.cc | 9 +++++++ gnuradio-core/src/lib/runtime/gr_flowgraph.h | 3 +++ .../src/lib/runtime/gr_hier_block2_detail.cc | 9 +++++++ .../src/lib/runtime/gr_tpb_thread_body.cc | 9 +++++-- .../src/lib/runtime/qa_set_msg_handler.cc | 5 ---- 9 files changed, 71 insertions(+), 13 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 7d2f275e8..69f2e09f9 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -28,6 +28,7 @@ #include #include #include +#include using namespace pmt; @@ -79,6 +80,7 @@ gr_basic_block::set_block_alias(std::string name) // - register a new input message port void gr_basic_block::message_port_register_in(pmt::pmt_t port_id){ msg_queue[port_id] = msg_queue_t(); + msg_queue_ready[port_id] = boost::shared_ptr(new boost::condition_variable()); } // - register a new output message port @@ -131,7 +133,6 @@ void gr_basic_block::_post(pmt_t which_port, pmt_t msg) { insert_tail(which_port, msg); - global_block_registry.notify_blk(alias()); } void @@ -139,12 +140,16 @@ gr_basic_block::insert_tail(pmt::pmt_t which_port, pmt::pmt_t msg) { gruel::scoped_lock guard(mutex); + if( (msg_queue.find(which_port) == msg_queue.end()) || (msg_queue_ready.find(which_port) == msg_queue_ready.end())){ + std::cout << "target port = " << pmt::pmt_symbol_to_string(which_port) << std::endl; + throw std::runtime_error("attempted to insert_tail on invalid queue!"); + } + msg_queue[which_port].push_back(msg); + msg_queue_ready[which_port]->notify_one(); // wake up thread if BLKD_IN or BLKD_OUT - //input_cond.notify_one(); - //output_cond.notify_one(); - // TODO: reconsider the need for notification of input and output conditions! + global_block_registry.notify_blk(alias()); } pmt_t @@ -162,4 +167,18 @@ gr_basic_block::delete_head_nowait(pmt::pmt_t which_port) return m; } +pmt_t +gr_basic_block::delete_head_blocking(pmt::pmt_t which_port) +{ + gruel::scoped_lock guard(mutex); + + while (empty_p(which_port)){ + msg_queue_ready[which_port]->wait(guard); + } + + pmt_t m(msg_queue[which_port].front()); + msg_queue[which_port].pop_front(); + return m; +} + diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 2ee8161c1..e0fd5d2af 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -35,6 +35,7 @@ #include #include #include +#include /*! * \brief The abstract base class for all signal processing blocks. @@ -72,6 +73,9 @@ private: typedef std::deque msg_queue_t; typedef std::map msg_queue_map_t; msg_queue_map_t msg_queue; +// boost::condition_variable msg_queue_ready; + std::map, pmt::pmt_comperator> msg_queue_ready; + gruel::mutex mutex; //< protects all vars @@ -163,6 +167,11 @@ public: */ pmt::pmt_t delete_head_nowait( pmt::pmt_t which_port); + /*! + * \returns returns pmt at head of queue or pmt_t() if empty. + */ + pmt::pmt_t delete_head_blocking( pmt::pmt_t which_port); + msg_queue_t::iterator get_iterator(pmt::pmt_t which_port){ return msg_queue[which_port].begin(); } diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index dc77128a3..43aebf0bf 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -251,3 +251,12 @@ operator << (std::ostream& os, const gr_block *m) return os; } +int +gr_block::general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + throw std::runtime_error("gr_block::general_work() not implemented"); + return 0; +} diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 98339080d..57e3fda90 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -124,7 +124,7 @@ class GR_CORE_API gr_block : public gr_basic_block { virtual int general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) = 0; + gr_vector_void_star &output_items); /*! * \brief Called to enable drivers, etc for i/o devices. diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc index 78e1bc99a..69c304a3d 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.cc @@ -180,6 +180,11 @@ gr_flowgraph::calc_used_blocks() { gr_basic_block_vector_t tmp; + // make sure free standing message blocks are included + for (gr_basic_block_vector_t::iterator it=d_msgblocks.begin(); it!=d_msgblocks.end(); it++){ + tmp.push_back(*it); + } + // Collect all blocks in the edge list for (gr_edge_viter_t p = d_edges.begin(); p != d_edges.end(); p++) { tmp.push_back(p->src().block()); @@ -472,3 +477,7 @@ gr_flowgraph::topological_dfs_visit(gr_basic_block_sptr block, gr_basic_block_ve output.push_back(block); } +void gr_flowgraph::add_msg_block(gr_basic_block_sptr blk){ + d_msgblocks.push_back(blk); +} + diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flowgraph.h index a2c1580eb..860cb0ff1 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.h @@ -110,6 +110,8 @@ public: void disconnect(gr_basic_block_sptr src_block, int src_port, gr_basic_block_sptr dst_block, int dst_port); + void add_msg_block(gr_basic_block_sptr blk); + // Validate connectivity, raise exception if invalid void validate(); @@ -128,6 +130,7 @@ public: // Return vector of vectors of disjointly connected blocks, topologically // sorted. std::vector partition(); + gr_basic_block_vector_t d_msgblocks; protected: gr_basic_block_vector_t d_blocks; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index 099b2f8e8..ff2a5db8c 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -152,6 +152,14 @@ gr_hier_block2_detail::msg_connect(gr_basic_block_sptr src, pmt::pmt_t srcport, // register the subscription src->message_port_sub(srcport, pmt::pmt_cons(dst->alias_pmt(), dstport)); + + // add block uniquely to list to internal blocks + if (std::find(d_blocks.begin(), d_blocks.end(), dst) == d_blocks.end()){ + d_blocks.push_back(dst); + } + + // make sure we instantiate a thread for this block + d_fg->add_msg_block(dst); } void @@ -449,6 +457,7 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const } } } + sfg->d_msgblocks = d_fg->d_msgblocks; // Construct unique list of blocks used either in edges, inputs, // outputs, or by themselves. I still hate STL. diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index ff2afca10..9f17a48a8 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -32,7 +32,7 @@ using namespace pmt; gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_items) : d_exec(block, max_noutput_items) { - // std::cerr << "gr_tpb_thread_body: " << block << std::endl; + //std::cerr << "gr_tpb_thread_body: " << block << std::endl; gr_block_detail *d = block->detail().get(); gr_block_executor::state s; @@ -53,7 +53,12 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item } d->d_tpb.clear_changed(); - s = d_exec.run_one_iteration(); + // run one iteration if we are a connected stream block + if(d->noutputs() >0 || d->ninputs()>0){ + s = d_exec.run_one_iteration(); + } else { + s = gr_block_executor::BLKD_IN; + } switch(s){ case gr_block_executor::READY: // Tell neighbors we made progress. diff --git a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc index dc8f0f8a9..c84a219bd 100644 --- a/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc +++ b/gnuradio-core/src/lib/runtime/qa_set_msg_handler.cc @@ -70,11 +70,6 @@ void qa_set_msg_handler::t0() send(nop, port, mp(mp("example-msg"), mp(i))); } - // And send a message to null_source to confirm that the default - // message handling action (which should be a nop) doesn't dump - // core. - send(src, port, mp(mp("example-msg"), mp(0))); - // Give the messages a chance to be processed boost::this_thread::sleep(boost::posix_time::milliseconds(100)); -- cgit From f334b636ed46c62b23582ed512bb07dfb51399ef Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 3 Dec 2012 14:49:02 -0500 Subject: core: the mutex is unlocked to begin with and GR doesn't seem to like us forcing it unlocked here. --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 69f2e09f9..2c77c1c0c 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -53,7 +53,6 @@ gr_basic_block::gr_basic_block(const std::string &name, d_color(WHITE), message_subscribers(pmt::pmt_make_dict()) { - mutex.unlock(); s_ncurrently_allocated++; } -- cgit From 69990c3fb6d4c7a0daee0229407241aa1959095a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 6 Dec 2012 14:10:39 -0500 Subject: core: Adding function to retrieve the symbol names of a blocks message ports. Updated qa_pdu tests to verify this. --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 129 ++++++++++++++++-------- gnuradio-core/src/lib/runtime/gr_basic_block.h | 17 ++++ gnuradio-core/src/lib/runtime/gr_basic_block.i | 2 + 3 files changed, 106 insertions(+), 42 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 2c77c1c0c..0f7875a12 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -77,56 +77,101 @@ gr_basic_block::set_block_alias(std::string name) // ** Message passing interface ** // - register a new input message port -void gr_basic_block::message_port_register_in(pmt::pmt_t port_id){ - msg_queue[port_id] = msg_queue_t(); - msg_queue_ready[port_id] = boost::shared_ptr(new boost::condition_variable()); - } +void +gr_basic_block::message_port_register_in(pmt::pmt_t port_id) +{ + if(!pmt::pmt_is_symbol(port_id)) { + throw std::runtime_error("message_port_register_in: bad port id"); + } + msg_queue[port_id] = msg_queue_t(); + msg_queue_ready[port_id] = boost::shared_ptr(new boost::condition_variable()); +} + +pmt::pmt_t +gr_basic_block::message_ports_in() +{ + pmt::pmt_t port_names = pmt::pmt_make_vector(msg_queue.size(), pmt::PMT_NIL); + msg_queue_map_itr itr = msg_queue.begin(); + for(size_t i = 0; i < msg_queue.size(); i++) { + pmt::pmt_vector_set(port_names, i, (*itr).first); + itr++; + } + return port_names; +} // - register a new output message port -void gr_basic_block::message_port_register_out(pmt::pmt_t port_id){ - if(!pmt::pmt_is_symbol(port_id)){ throw std::runtime_error("bad port id"); } - if(pmt::pmt_dict_has_key(message_subscribers, port_id)){ throw std::runtime_error("port already in use"); } - message_subscribers = pmt::pmt_dict_add(message_subscribers, port_id, pmt::PMT_NIL); - } +void +gr_basic_block::message_port_register_out(pmt::pmt_t port_id) +{ + if(!pmt::pmt_is_symbol(port_id)) { + throw std::runtime_error("message_port_register_out: bad port id"); + } + if(pmt::pmt_dict_has_key(message_subscribers, port_id)) { + throw std::runtime_error("message_port_register_out: port already in use"); + } + message_subscribers = pmt::pmt_dict_add(message_subscribers, port_id, pmt::PMT_NIL); +} + +pmt::pmt_t +gr_basic_block::message_ports_out() +{ + size_t len = pmt::pmt_length(message_subscribers); + pmt::pmt_t port_names = pmt::pmt_make_vector(len, pmt::PMT_NIL); + pmt::pmt_t keys = pmt::pmt_dict_keys(message_subscribers); + for(size_t i = 0; i < len; i++) { + pmt::pmt_vector_set(port_names, i, pmt::pmt_nth(i, keys)); + } + return port_names; +} // - publish a message on a message port -void gr_basic_block::message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg){ - if(!pmt::pmt_dict_has_key(message_subscribers, port_id)){ throw std::runtime_error("port does not exist"); } - pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); - // iterate through subscribers on port - while( pmt::pmt_is_pair(currlist) ){ - pmt::pmt_t target = pmt::pmt_car(currlist); - - pmt::pmt_t block = pmt::pmt_car(target); - pmt::pmt_t port = pmt::pmt_cdr(target); +void gr_basic_block::message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg) +{ + if(!pmt::pmt_dict_has_key(message_subscribers, port_id)) { + throw std::runtime_error("port does not exist"); + } + + pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers, port_id, pmt::PMT_NIL); + // iterate through subscribers on port + while(pmt::pmt_is_pair(currlist)) { + pmt::pmt_t target = pmt::pmt_car(currlist); + + pmt::pmt_t block = pmt::pmt_car(target); + pmt::pmt_t port = pmt::pmt_cdr(target); - currlist = pmt::pmt_cdr(currlist); - gr_basic_block_sptr blk = global_block_registry.block_lookup(block); - //blk->post(msg); - blk->post(port, msg); - } - } + currlist = pmt::pmt_cdr(currlist); + gr_basic_block_sptr blk = global_block_registry.block_lookup(block); + //blk->post(msg); + blk->post(port, msg); + } +} // - subscribe to a message port -void gr_basic_block::message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target){ - if(!pmt::pmt_dict_has_key(message_subscribers, port_id)){ - std::stringstream ss; - ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) << "\" on block: " << pmt::pmt_write_string(target) << std::endl; - throw std::runtime_error(ss.str()); - } - pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); - message_subscribers = pmt::pmt_dict_add(message_subscribers,port_id,pmt::pmt_list_add(currlist,target)); - } +void gr_basic_block::message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target) +{ + if(!pmt::pmt_dict_has_key(message_subscribers, port_id)) { + std::stringstream ss; + ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) + << "\" on block: " << pmt::pmt_write_string(target) << std::endl; + throw std::runtime_error(ss.str()); + } + + pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); + message_subscribers = pmt::pmt_dict_add(message_subscribers,port_id,pmt::pmt_list_add(currlist,target)); +} -void gr_basic_block::message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target){ - if(!pmt::pmt_dict_has_key(message_subscribers, port_id)){ - std::stringstream ss; - ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) << "\" on block: " << pmt::pmt_write_string(target) << std::endl; - throw std::runtime_error(ss.str()); - } - pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); - message_subscribers = pmt::pmt_dict_add(message_subscribers,port_id,pmt::pmt_list_rm(currlist,target)); - } +void gr_basic_block::message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target) +{ + if(!pmt::pmt_dict_has_key(message_subscribers, port_id)) { + std::stringstream ss; + ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) + << "\" on block: " << pmt::pmt_write_string(target) << std::endl; + throw std::runtime_error(ss.str()); + } + + pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); + message_subscribers = pmt::pmt_dict_add(message_subscribers,port_id,pmt::pmt_list_rm(currlist,target)); +} void gr_basic_block::_post(pmt_t which_port, pmt_t msg) diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index e0fd5d2af..00e9c2192 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -72,6 +72,7 @@ private: typedef std::deque msg_queue_t; typedef std::map msg_queue_map_t; + typedef std::map::iterator msg_queue_map_itr; msg_queue_map_t msg_queue; // boost::condition_variable msg_queue_ready; std::map, pmt::pmt_comperator> msg_queue_ready; @@ -142,6 +143,22 @@ public: void message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target); void message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target); + /*! + * \brief Get input message port names. + * + * Returns the available input message ports for a block. The + * return object is a PMT vector that is filled with PMT symbols. + */ + pmt::pmt_t message_ports_in(); + + /*! + * \brief Get output message port names. + * + * Returns the available output message ports for a block. The + * return object is a PMT vector that is filled with PMT symbols. + */ + pmt::pmt_t message_ports_out(); + /*! * Accept msg, place in queue, arrange for thread to be awakened if it's not already. */ diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index d6d6c3d16..62f16462d 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -48,6 +48,8 @@ public: std::string alias(); void set_block_alias(std::string name); void _post(pmt_t which_port, pmt_t msg); + pmt_t message_ports_in(); + pmt_t message_ports_out(); }; %rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; -- cgit From 52ca5e2765b7a4532d26502b5b76b7c85c5019d7 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Fri, 7 Dec 2012 09:28:41 -0800 Subject: core: added gr_tuntap_pdu, gr_socket_pdu, and msg passing enhancements --- gnuradio-core/src/lib/runtime/gr_basic_block.cc | 41 +-- gnuradio-core/src/lib/runtime/gr_basic_block.h | 406 +++++++++++---------- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 34 +- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 4 +- gnuradio-core/src/lib/runtime/gr_flowgraph.cc | 40 +- gnuradio-core/src/lib/runtime/gr_flowgraph.h | 61 +++- gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 5 +- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 33 ++ gnuradio-core/src/lib/runtime/gr_hier_block2.i | 6 + .../src/lib/runtime/gr_hier_block2_detail.cc | 90 ++++- .../src/lib/runtime/gr_hier_block2_detail.h | 1 + 11 files changed, 488 insertions(+), 233 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index 0f7875a12..6ff57a1d6 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -38,7 +38,7 @@ static long s_ncurrently_allocated = 0; long gr_basic_block_ncurrently_allocated() { - return s_ncurrently_allocated; + return s_ncurrently_allocated; } gr_basic_block::gr_basic_block(const std::string &name, @@ -53,25 +53,25 @@ gr_basic_block::gr_basic_block(const std::string &name, d_color(WHITE), message_subscribers(pmt::pmt_make_dict()) { - s_ncurrently_allocated++; + s_ncurrently_allocated++; } gr_basic_block::~gr_basic_block() { - s_ncurrently_allocated--; - global_block_registry.block_unregister(this); + s_ncurrently_allocated--; + global_block_registry.block_unregister(this); } gr_basic_block_sptr gr_basic_block::to_basic_block() { - return shared_from_this(); + return shared_from_this(); } void gr_basic_block::set_block_alias(std::string name) { - global_block_registry.register_symbolic_name(this, name); + global_block_registry.register_symbolic_name(this, name); } // ** Message passing interface ** @@ -147,28 +147,29 @@ void gr_basic_block::message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg) } // - subscribe to a message port -void gr_basic_block::message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target) -{ - if(!pmt::pmt_dict_has_key(message_subscribers, port_id)) { +void +gr_basic_block::message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target){ + if(!pmt::pmt_dict_has_key(message_subscribers, port_id)){ std::stringstream ss; - ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) - << "\" on block: " << pmt::pmt_write_string(target) << std::endl; + ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) << "\" on block: " << pmt::pmt_write_string(target) << std::endl; throw std::runtime_error(ss.str()); } - pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); - message_subscribers = pmt::pmt_dict_add(message_subscribers,port_id,pmt::pmt_list_add(currlist,target)); + + // ignore re-adds of the same target + if(!pmt::pmt_list_has(currlist, target)) + message_subscribers = pmt::pmt_dict_add(message_subscribers,port_id,pmt::pmt_list_add(currlist,target)); } -void gr_basic_block::message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target) -{ - if(!pmt::pmt_dict_has_key(message_subscribers, port_id)) { +void +gr_basic_block::message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target){ + if(!pmt::pmt_dict_has_key(message_subscribers, port_id)){ std::stringstream ss; - ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) - << "\" on block: " << pmt::pmt_write_string(target) << std::endl; + ss << "Port does not exist: \"" << pmt::pmt_write_string(port_id) << "\" on block: " << pmt::pmt_write_string(target) << std::endl; throw std::runtime_error(ss.str()); } - + + // ignore unsubs of unknown targets pmt::pmt_t currlist = pmt::pmt_dict_ref(message_subscribers,port_id,pmt::PMT_NIL); message_subscribers = pmt::pmt_dict_add(message_subscribers,port_id,pmt::pmt_list_rm(currlist,target)); } @@ -224,5 +225,3 @@ gr_basic_block::delete_head_blocking(pmt::pmt_t which_port) msg_queue[which_port].pop_front(); return m; } - - diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 00e9c2192..f3b7b835b 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -36,6 +36,7 @@ #include #include #include +#include /*! * \brief The abstract base class for all signal processing blocks. @@ -50,202 +51,215 @@ class GR_CORE_API gr_basic_block : public gr_msg_accepter, public boost::enable_shared_from_this { - typedef boost::function msg_handler_t; - -private: - /* - * This function is called by the runtime system to dispatch messages. - * - * The thread-safety guarantees mentioned in set_msg_handler are implemented - * by the callers of this method. - */ - void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) - { - // AA Update this - if (d_msg_handlers.find(which_port) != d_msg_handlers.end()) // Is there a handler? - d_msg_handlers[which_port](msg); // Yes, invoke it. - }; - - //msg_handler_t d_msg_handler; - typedef std::map d_msg_handlers_t; - d_msg_handlers_t d_msg_handlers; - - typedef std::deque msg_queue_t; - typedef std::map msg_queue_map_t; - typedef std::map::iterator msg_queue_map_itr; - msg_queue_map_t msg_queue; -// boost::condition_variable msg_queue_ready; - std::map, pmt::pmt_comperator> msg_queue_ready; - - gruel::mutex mutex; //< protects all vars - - -protected: - friend class gr_flowgraph; - friend class gr_flat_flowgraph; // TODO: will be redundant - friend class gr_tpb_thread_body; - - enum vcolor { WHITE, GREY, BLACK }; - - std::string d_name; - gr_io_signature_sptr d_input_signature; - gr_io_signature_sptr d_output_signature; - long d_unique_id; - long d_symbolic_id; - std::string d_symbol_name; - std::string d_symbol_alias; - vcolor d_color; - - gr_basic_block(void){} //allows pure virtual interface sub-classes - - //! Protected constructor prevents instantiation by non-derived classes - gr_basic_block(const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - - //! may only be called during constructor - void set_input_signature(gr_io_signature_sptr iosig) { - d_input_signature = iosig; + typedef boost::function msg_handler_t; + + private: + /* + * This function is called by the runtime system to dispatch messages. + * + * The thread-safety guarantees mentioned in set_msg_handler are implemented + * by the callers of this method. + */ + void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) + { + // AA Update this + if (d_msg_handlers.find(which_port) != d_msg_handlers.end()) // Is there a handler? + d_msg_handlers[which_port](msg); // Yes, invoke it. + }; + + //msg_handler_t d_msg_handler; + typedef std::map d_msg_handlers_t; + d_msg_handlers_t d_msg_handlers; + + typedef std::deque msg_queue_t; + typedef std::map msg_queue_map_t; + typedef std::map::iterator msg_queue_map_itr; + std::map, pmt::pmt_comperator> msg_queue_ready; + + gruel::mutex mutex; //< protects all vars + + protected: + friend class gr_flowgraph; + friend class gr_flat_flowgraph; // TODO: will be redundant + friend class gr_tpb_thread_body; + + enum vcolor { WHITE, GREY, BLACK }; + + std::string d_name; + gr_io_signature_sptr d_input_signature; + gr_io_signature_sptr d_output_signature; + long d_unique_id; + long d_symbolic_id; + std::string d_symbol_name; + std::string d_symbol_alias; + vcolor d_color; + msg_queue_map_t msg_queue; + + gr_basic_block(void){} //allows pure virtual interface sub-classes + + //! Protected constructor prevents instantiation by non-derived classes + gr_basic_block(const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature); + + //! may only be called during constructor + void set_input_signature(gr_io_signature_sptr iosig) { + d_input_signature = iosig; + } + + //! may only be called during constructor + void set_output_signature(gr_io_signature_sptr iosig) { + d_output_signature = iosig; + } + + /*! + * \brief Allow the flowgraph to set for sorting and partitioning + */ + void set_color(vcolor color) { d_color = color; } + vcolor color() const { return d_color; } + + // Message passing interface + pmt::pmt_t message_subscribers; + + public: + virtual ~gr_basic_block(); + long unique_id() const { return d_unique_id; } + long symbolic_id() const { return d_symbolic_id; } + std::string name() const { return d_name; } + std::string symbol_name() const { return d_symbol_name; } + gr_io_signature_sptr input_signature() const { return d_input_signature; } + gr_io_signature_sptr output_signature() const { return d_output_signature; } + gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion + bool alias_set() { return !d_symbol_alias.empty(); } + std::string alias(){ return alias_set()?d_symbol_alias:symbol_name(); } + pmt::pmt_t alias_pmt(){ return pmt::pmt_intern(alias()); } + void set_block_alias(std::string name); + + // ** Message passing interface ** + void message_port_register_in(pmt::pmt_t port_id); + void message_port_register_out(pmt::pmt_t port_id); + void message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg); + void message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target); + void message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target); + + virtual bool message_port_is_hier(pmt::pmt_t port_id) { std::cout << "is_hier\n"; return false; } + virtual bool message_port_is_hier_in(pmt::pmt_t port_id) { std::cout << "is_hier_in\n"; return false; } + virtual bool message_port_is_hier_out(pmt::pmt_t port_id) { std::cout << "is_hier_out\n"; return false; } + + /*! + * \brief Get input message port names. + * + * Returns the available input message ports for a block. The + * return object is a PMT vector that is filled with PMT symbols. + */ + pmt::pmt_t message_ports_in(); + + /*! + * \brief Get output message port names. + * + * Returns the available output message ports for a block. The + * return object is a PMT vector that is filled with PMT symbols. + */ + pmt::pmt_t message_ports_out(); + + /*! + * Accept msg, place in queue, arrange for thread to be awakened if it's not already. + */ + void _post(pmt::pmt_t which_port, pmt::pmt_t msg); + + //! is the queue empty? + //bool empty_p(const pmt::pmt_t &which_port) const { return msg_queue[which_port].empty(); } + bool empty_p(pmt::pmt_t which_port) { + if(msg_queue.find(which_port) == msg_queue.end()) + throw std::runtime_error("port does not exist!"); + return msg_queue[which_port].empty(); + } + bool empty_p() { + bool rv = true; + BOOST_FOREACH(msg_queue_map_t::value_type &i, msg_queue){ rv &= msg_queue[i.first].empty(); } + return rv; + } + + //| Acquires and release the mutex + void insert_tail( pmt::pmt_t which_port, pmt::pmt_t msg); + /*! + * \returns returns pmt at head of queue or pmt_t() if empty. + */ + pmt::pmt_t delete_head_nowait( pmt::pmt_t which_port); + + /*! + * \returns returns pmt at head of queue or pmt_t() if empty. + */ + pmt::pmt_t delete_head_blocking( pmt::pmt_t which_port); + + msg_queue_t::iterator get_iterator(pmt::pmt_t which_port){ + return msg_queue[which_port].begin(); + } + + void erase_msg(pmt::pmt_t which_port, msg_queue_t::iterator it){ + msg_queue[which_port].erase(it); + } + + virtual bool has_msg_port(pmt::pmt_t which_port){ + if(msg_queue.find(which_port) != msg_queue.end()){ + return true; } - - //! may only be called during constructor - void set_output_signature(gr_io_signature_sptr iosig) { - d_output_signature = iosig; - } - - /*! - * \brief Allow the flowgraph to set for sorting and partitioning - */ - void set_color(vcolor color) { d_color = color; } - vcolor color() const { return d_color; } - - // Message passing interface - pmt::pmt_t message_subscribers; - -public: - virtual ~gr_basic_block(); - long unique_id() const { return d_unique_id; } - long symbolic_id() const { return d_symbolic_id; } - std::string name() const { return d_name; } - std::string symbol_name() const { return d_symbol_name; } - gr_io_signature_sptr input_signature() const { return d_input_signature; } - gr_io_signature_sptr output_signature() const { return d_output_signature; } - gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion - bool alias_set() { return !d_symbol_alias.empty(); } - std::string alias(){ return alias_set()?d_symbol_alias:symbol_name(); } - pmt::pmt_t alias_pmt(){ return pmt::pmt_intern(alias()); } - void set_block_alias(std::string name); - - // ** Message passing interface ** - void message_port_register_in(pmt::pmt_t port_id); - void message_port_register_out(pmt::pmt_t port_id); - void message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg); - void message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target); - void message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target); - - /*! - * \brief Get input message port names. - * - * Returns the available input message ports for a block. The - * return object is a PMT vector that is filled with PMT symbols. - */ - pmt::pmt_t message_ports_in(); - - /*! - * \brief Get output message port names. - * - * Returns the available output message ports for a block. The - * return object is a PMT vector that is filled with PMT symbols. - */ - pmt::pmt_t message_ports_out(); - - /*! - * Accept msg, place in queue, arrange for thread to be awakened if it's not already. - */ - void _post(pmt::pmt_t which_port, pmt::pmt_t msg); - - //! is the queue empty? - //bool empty_p(const pmt::pmt_t &which_port) const { return msg_queue[which_port].empty(); } - bool empty_p(pmt::pmt_t which_port) { - if(msg_queue.find(which_port) == msg_queue.end()) - throw std::runtime_error("port does not exist!"); - return msg_queue[which_port].empty(); - } - bool empty_p() { - bool rv = true; - BOOST_FOREACH(msg_queue_map_t::value_type &i, msg_queue){ rv &= msg_queue[i.first].empty(); } - return rv; - } - - //| Acquires and release the mutex - void insert_tail( pmt::pmt_t which_port, pmt::pmt_t msg); - /*! - * \returns returns pmt at head of queue or pmt_t() if empty. - */ - pmt::pmt_t delete_head_nowait( pmt::pmt_t which_port); - - /*! - * \returns returns pmt at head of queue or pmt_t() if empty. - */ - pmt::pmt_t delete_head_blocking( pmt::pmt_t which_port); - - msg_queue_t::iterator get_iterator(pmt::pmt_t which_port){ - return msg_queue[which_port].begin(); - } - void erase_msg(pmt::pmt_t which_port, msg_queue_t::iterator it){ - msg_queue[which_port].erase(it); - } - - - /*! - * \brief Confirm that ninputs and noutputs is an acceptable combination. - * - * \param ninputs number of input streams connected - * \param noutputs number of output streams connected - * - * \returns true if this is a valid configuration for this block. - * - * This function is called by the runtime system whenever the - * topology changes. Most classes do not need to override this. - * This check is in addition to the constraints specified by the input - * and output gr_io_signatures. - */ - virtual bool check_topology(int ninputs, int noutputs) { return true; } - - /*! - * \brief Set the callback that is fired when messages are available. - * - * \p msg_handler can be any kind of function pointer or function object - * that has the signature: - *
-     *    void msg_handler(pmt::pmt msg);
-     * 
- * - * (You may want to use boost::bind to massage your callable into the - * correct form. See gr_nop.{h,cc} for an example that sets up a class - * method as the callback.) - * - * Blocks that desire to handle messages must call this method in their - * constructors to register the handler that will be invoked when messages - * are available. - * - * If the block inherits from gr_block, the runtime system will ensure that - * msg_handler is called in a thread-safe manner, such that work and - * msg_handler will never be called concurrently. This allows msg_handler - * to update state variables without having to worry about thread-safety - * issues with work, general_work or another invocation of msg_handler. - * - * If the block inherits from gr_hier_block2, the runtime system will - * ensure that no reentrant calls are made to msg_handler. - */ - //template void set_msg_handler(T msg_handler){ - // d_msg_handler = msg_handler_t(msg_handler); - //} - template void set_msg_handler(pmt::pmt_t which_port, T msg_handler){ - if(msg_queue.find(which_port) == msg_queue.end()){ - throw std::runtime_error("attempt to set_msg_handler() on bad input message port!"); } - d_msg_handlers[which_port] = msg_handler_t(msg_handler); + if(pmt::pmt_dict_has_key(message_subscribers, which_port)){ + return true; } + return false; + } + + + /*! + * \brief Confirm that ninputs and noutputs is an acceptable combination. + * + * \param ninputs number of input streams connected + * \param noutputs number of output streams connected + * + * \returns true if this is a valid configuration for this block. + * + * This function is called by the runtime system whenever the + * topology changes. Most classes do not need to override this. + * This check is in addition to the constraints specified by the input + * and output gr_io_signatures. + */ + virtual bool check_topology(int ninputs, int noutputs) { return true; } + + /*! + * \brief Set the callback that is fired when messages are available. + * + * \p msg_handler can be any kind of function pointer or function object + * that has the signature: + *
+   *    void msg_handler(pmt::pmt msg);
+   * 
+ * + * (You may want to use boost::bind to massage your callable into the + * correct form. See gr_nop.{h,cc} for an example that sets up a class + * method as the callback.) + * + * Blocks that desire to handle messages must call this method in their + * constructors to register the handler that will be invoked when messages + * are available. + * + * If the block inherits from gr_block, the runtime system will ensure that + * msg_handler is called in a thread-safe manner, such that work and + * msg_handler will never be called concurrently. This allows msg_handler + * to update state variables without having to worry about thread-safety + * issues with work, general_work or another invocation of msg_handler. + * + * If the block inherits from gr_hier_block2, the runtime system will + * ensure that no reentrant calls are made to msg_handler. + */ + //template void set_msg_handler(T msg_handler){ + // d_msg_handler = msg_handler_t(msg_handler); + //} + template void set_msg_handler(pmt::pmt_t which_port, T msg_handler){ + if(msg_queue.find(which_port) == msg_queue.end()){ + throw std::runtime_error("attempt to set_msg_handler() on bad input message port!"); } + d_msg_handlers[which_port] = msg_handler_t(msg_handler); + } }; inline bool operator<(gr_basic_block_sptr lhs, gr_basic_block_sptr rhs) @@ -260,8 +274,8 @@ GR_CORE_API long gr_basic_block_ncurrently_allocated(); inline std::ostream &operator << (std::ostream &os, gr_basic_block_sptr basic_block) { - os << basic_block->name() << "(" << basic_block->unique_id() << ")"; - return os; + os << basic_block->name() << "(" << basic_block->unique_id() << ")"; + return os; } #endif /* INCLUDED_GR_BASIC_BLOCK_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index e04deb948..c19863f34 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -31,8 +31,9 @@ #include #include #include +#include -#define GR_FLAT_FLOWGRAPH_DEBUG 0 +#define GR_FLAT_FLOWGRAPH_DEBUG 0 // 32Kbyte buffer size between blocks #define GR_FIXED_BUFFER_SIZE (32*(1L<<10)) @@ -71,6 +72,15 @@ gr_flat_flowgraph::setup_connections() block->set_is_unaligned(false); } + // Connect message ports connetions + for(gr_msg_edge_viter_t i = d_msg_edges.begin(); i != d_msg_edges.end(); i++){ + if(GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << boost::format("flat_fg connecting msg primitives: (%s, %s)->(%s, %s)\n") % + i->src().block() % i->src().port() % + i->dst().block() % i->dst().port(); + i->src().block()->message_port_sub( i->src().port(), pmt::pmt_cons(i->dst().block()->alias_pmt(), i->dst().port()) ); + } + } gr_block_detail_sptr @@ -350,3 +360,25 @@ gr_flat_flowgraph::make_block_vector(gr_basic_block_vector_t &blocks) return result; } + + +void gr_flat_flowgraph::replace_endpoint(const gr_msg_endpoint &e, const gr_msg_endpoint &r, bool is_src){ + size_t n_replr(0); + if(GR_FLAT_FLOWGRAPH_DEBUG) + std::cout << boost::format("gr_flat_flowgraph::replace_endpoint( %s, %s, %d )\n") % e.block()% r.block()% is_src; + for(size_t i=0; ihas_msg_port(e.port())) + throw std::invalid_argument("invalid msg port in connect() or disconnect()"); +} + void gr_flowgraph::check_dst_not_used(const gr_endpoint &dst) { @@ -181,8 +191,10 @@ gr_flowgraph::calc_used_blocks() gr_basic_block_vector_t tmp; // make sure free standing message blocks are included - for (gr_basic_block_vector_t::iterator it=d_msgblocks.begin(); it!=d_msgblocks.end(); it++){ - tmp.push_back(*it); + for (gr_msg_edge_viter_t p = d_msg_edges.begin(); p != d_msg_edges.end(); p++) { +// for now only blocks receiving messages get a thread context - uncomment to allow senders to also obtain one +// tmp.push_back(p->src().block()); + tmp.push_back(p->dst().block()); } // Collect all blocks in the edge list @@ -477,7 +489,27 @@ gr_flowgraph::topological_dfs_visit(gr_basic_block_sptr block, gr_basic_block_ve output.push_back(block); } -void gr_flowgraph::add_msg_block(gr_basic_block_sptr blk){ - d_msgblocks.push_back(blk); +void gr_flowgraph::connect(const gr_msg_endpoint &src, const gr_msg_endpoint &dst){ + check_valid_port(src); + check_valid_port(dst); + for (gr_msg_edge_viter_t p = d_msg_edges.begin(); p != d_msg_edges.end(); p++) { + if(p->src() == src && p->dst() == dst){ + throw std::runtime_error("connect called on already connected edge!"); + } + } + d_msg_edges.push_back(gr_msg_edge(src,dst)); } +void gr_flowgraph::disconnect(const gr_msg_endpoint &src, const gr_msg_endpoint &dst){ + check_valid_port(src); + check_valid_port(dst); + for (gr_msg_edge_viter_t p = d_msg_edges.begin(); p != d_msg_edges.end(); p++) { + if(p->src() == src && p->dst() == dst){ + d_msg_edges.erase(p); + return; + } + } + throw std::runtime_error("disconnect called on non-connected edge!"); +} + + diff --git a/gnuradio-core/src/lib/runtime/gr_flowgraph.h b/gnuradio-core/src/lib/runtime/gr_flowgraph.h index 860cb0ff1..bef70f626 100644 --- a/gnuradio-core/src/lib/runtime/gr_flowgraph.h +++ b/gnuradio-core/src/lib/runtime/gr_flowgraph.h @@ -52,6 +52,31 @@ inline bool gr_endpoint::operator==(const gr_endpoint &other) const d_port == other.d_port); } +class GR_CORE_API gr_msg_endpoint +{ +private: + gr_basic_block_sptr d_basic_block; + pmt::pmt_t d_port; + bool d_is_hier; +public: + gr_msg_endpoint() : d_basic_block(), d_port(pmt::PMT_NIL) { } + gr_msg_endpoint(gr_basic_block_sptr block, pmt::pmt_t port, bool is_hier=false){ d_basic_block = block; d_port = port; d_is_hier = is_hier;} + gr_basic_block_sptr block() const { return d_basic_block; } + pmt::pmt_t port() const { return d_port; } + bool is_hier() const { return d_is_hier; } + void set_hier(bool h) { d_is_hier = h; } + + bool operator==(const gr_msg_endpoint &other) const; + +}; + +inline bool gr_msg_endpoint::operator==(const gr_msg_endpoint &other) const +{ + return (d_basic_block == other.d_basic_block && + pmt::pmt_equal(d_port, other.d_port)); +} + + // Hold vectors of gr_endpoint objects typedef std::vector gr_endpoint_vector_t; typedef std::vector::iterator gr_endpoint_viter_t; @@ -75,11 +100,35 @@ private: gr_endpoint d_dst; }; + // Hold vectors of gr_edge objects typedef std::vector gr_edge_vector_t; typedef std::vector::iterator gr_edge_viter_t; +/*! + *\brief Class representing a msg connection between to graph msg endpoints + * + */ +class GR_CORE_API gr_msg_edge +{ +public: + gr_msg_edge() : d_src(), d_dst() { }; + gr_msg_edge(const gr_msg_endpoint &src, const gr_msg_endpoint &dst) : d_src(src), d_dst(dst) { } + ~gr_msg_edge() {} + + const gr_msg_endpoint &src() const { return d_src; } + const gr_msg_endpoint &dst() const { return d_dst; } + +private: + gr_msg_endpoint d_src; + gr_msg_endpoint d_dst; +}; + +// Hold vectors of gr_edge objects +typedef std::vector gr_msg_edge_vector_t; +typedef std::vector::iterator gr_msg_edge_viter_t; + // Create a shared pointer to a heap allocated flowgraph // (types defined in gr_runtime_types.h) GR_CORE_API gr_flowgraph_sptr gr_make_flowgraph(); @@ -110,7 +159,11 @@ public: void disconnect(gr_basic_block_sptr src_block, int src_port, gr_basic_block_sptr dst_block, int dst_port); - void add_msg_block(gr_basic_block_sptr blk); + // Connect two msg endpoints + void connect(const gr_msg_endpoint &src, const gr_msg_endpoint &dst); + + // Disconnect two msg endpoints + void disconnect(const gr_msg_endpoint &src, const gr_msg_endpoint &dst); // Validate connectivity, raise exception if invalid void validate(); @@ -120,6 +173,9 @@ public: // Return vector of edges const gr_edge_vector_t &edges() const { return d_edges; } + + // Return vector of msg edges + const gr_msg_edge_vector_t &msg_edges() const { return d_msg_edges; } // Return vector of connected blocks gr_basic_block_vector_t calc_used_blocks(); @@ -130,11 +186,11 @@ public: // Return vector of vectors of disjointly connected blocks, topologically // sorted. std::vector partition(); - gr_basic_block_vector_t d_msgblocks; protected: gr_basic_block_vector_t d_blocks; gr_edge_vector_t d_edges; + gr_msg_edge_vector_t d_msg_edges; gr_flowgraph(); std::vector calc_used_ports(gr_basic_block_sptr block, bool check_inputs); @@ -146,6 +202,7 @@ protected: private: void check_valid_port(gr_io_signature_sptr sig, int port); + void check_valid_port(const gr_msg_endpoint &e); void check_dst_not_used(const gr_endpoint &dst); void check_type_match(const gr_endpoint &src, const gr_endpoint &dst); gr_edge_vector_t calc_connections(gr_basic_block_sptr block, bool check_inputs); // false=use outputs diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index a19bfe195..8c2794c63 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -44,7 +44,9 @@ gr_hier_block2::gr_hier_block2(const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature) : gr_basic_block(name, input_signature, output_signature), - d_detail(new gr_hier_block2_detail(this)) + d_detail(new gr_hier_block2_detail(this)), + hier_message_ports_in(pmt::PMT_NIL), + hier_message_ports_out(pmt::PMT_NIL) { // This bit of magic ensures that self() works in the constructors of derived classes. gnuradio::detail::sptr_magic::create_and_stash_initial_sptr(this); @@ -141,6 +143,7 @@ gr_hier_block2::unlock() d_detail->unlock(); } + gr_flat_flowgraph_sptr gr_hier_block2::flatten() const { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index e8364a740..f80dd73e4 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -166,6 +166,39 @@ public: gr_flat_flowgraph_sptr flatten() const; gr_hier_block2_sptr to_hier_block2(); // Needed for Python type coercion + + bool has_msg_port(pmt::pmt_t which_port){ + return message_port_is_hier(which_port) || gr_basic_block::has_msg_port(which_port); + } + + bool message_port_is_hier(pmt::pmt_t port_id){ + return message_port_is_hier_in(port_id) || message_port_is_hier_out(port_id); + } + bool message_port_is_hier_in(pmt::pmt_t port_id){ + return pmt::pmt_list_has(hier_message_ports_in, port_id); + } + bool message_port_is_hier_out(pmt::pmt_t port_id){ + return pmt::pmt_list_has(hier_message_ports_out, port_id); + } + + pmt::pmt_t hier_message_ports_in; + pmt::pmt_t hier_message_ports_out; + + void message_port_register_hier_in(pmt::pmt_t port_id){ + if(pmt::pmt_list_has(hier_message_ports_in, port_id)) + throw std::invalid_argument("hier msg in port by this name already registered"); + if(msg_queue.find(port_id) != msg_queue.end()) + throw std::invalid_argument("block already has a primitive input port by this name"); + hier_message_ports_in = pmt::pmt_list_add(hier_message_ports_in, port_id); + } + void message_port_register_hier_out(pmt::pmt_t port_id){ + if(pmt::pmt_list_has(hier_message_ports_out, port_id)) + throw std::invalid_argument("hier msg out port by this name already registered"); + if(pmt::pmt_dict_has_key(message_subscribers, port_id)) + throw std::invalid_argument("block already has a primitive output port by this name"); + hier_message_ports_out = pmt::pmt_list_add(hier_message_ports_out, port_id); + } + }; inline gr_hier_block2_sptr cast_to_hier_block2_sptr(gr_basic_block_sptr block) { diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.i b/gnuradio-core/src/lib/runtime/gr_hier_block2.i index 7c0e62f28..a857394ca 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.i +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.i @@ -40,6 +40,8 @@ gr_hier_block2_sptr gr_make_hier_block2(const std::string name, %rename(primitive_disconnect) gr_hier_block2::disconnect; %rename(primitive_msg_connect) gr_hier_block2::msg_connect; %rename(primitive_msg_disconnect) gr_hier_block2::msg_disconnect; +%rename(primitive_message_port_register_hier_in) gr_hier_block2::message_port_register_hier_in; +%rename(primitive_message_port_register_hier_out) gr_hier_block2::message_port_register_hier_out; class gr_hier_block2 : public gr_basic_block { @@ -78,5 +80,9 @@ public: void lock(); void unlock(); + void message_port_register_hier_in(pmt::pmt_t port_id); + void message_port_register_hier_out(pmt::pmt_t port_id); + + gr_hier_block2_sptr to_hier_block2(); // Needed for Python type coercion }; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc index ff2a5db8c..e70553ddc 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc @@ -27,6 +27,7 @@ #include #include #include +#include #define GR_HIER_BLOCK2_DETAIL_DEBUG 0 @@ -53,6 +54,7 @@ gr_hier_block2_detail::gr_hier_block2_detail(gr_hier_block2 *owner) : d_outputs = gr_endpoint_vector_t(max_outputs); } + gr_hier_block2_detail::~gr_hier_block2_detail() { d_owner = 0; // Don't use delete, we didn't allocate @@ -151,15 +153,39 @@ gr_hier_block2_detail::msg_connect(gr_basic_block_sptr src, pmt::pmt_t srcport, std::cout << "connecting message port..." << std::endl; // register the subscription - src->message_port_sub(srcport, pmt::pmt_cons(dst->alias_pmt(), dstport)); +// this is done later... +// src->message_port_sub(srcport, pmt::pmt_cons(dst->alias_pmt(), dstport)); // add block uniquely to list to internal blocks if (std::find(d_blocks.begin(), d_blocks.end(), dst) == d_blocks.end()){ + d_blocks.push_back(src); d_blocks.push_back(dst); } - // make sure we instantiate a thread for this block - d_fg->add_msg_block(dst); + bool hier_out = (d_owner == src.get()) && src->message_port_is_hier_out(srcport);; + bool hier_in = (d_owner == dst.get()) && dst->message_port_is_hier_in(dstport); + + gr_hier_block2_sptr src_block(cast_to_hier_block2_sptr(src)); + gr_hier_block2_sptr dst_block(cast_to_hier_block2_sptr(dst)); + + if (src_block && src.get() != d_owner) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "connect: src is hierarchical, setting parent to " << this << std::endl; + src_block->d_detail->d_parent_detail = this; + } + + if (dst_block && dst.get() != d_owner) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "connect: dst is hierarchical, setting parent to " << this << std::endl; + dst_block->d_detail->d_parent_detail = this; + } + + // add edge for this message connection + if(GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << boost::format("connect( (%s, %s, %d), (%s, %s, %d) )\n") % + src % srcport % hier_out % + dst % dstport % hier_in; + d_fg->connect( gr_msg_endpoint(src, srcport, hier_out), gr_msg_endpoint(dst, dstport, hier_in)); } void @@ -169,8 +195,13 @@ gr_hier_block2_detail::msg_disconnect(gr_basic_block_sptr src, pmt::pmt_t srcpor if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "disconnecting message port..." << std::endl; - // register the subscription + // unregister the subscription - if already subscribed src->message_port_unsub(srcport, pmt::pmt_cons(dst->alias_pmt(), dstport)); + + // remove edge for this message connection + bool hier_out = (d_owner == src.get()) && src->message_port_is_hier_out(srcport);; + bool hier_in = (d_owner == dst.get()) && dst->message_port_is_hier_in(dstport); + d_fg->disconnect( gr_msg_endpoint(src, srcport, hier_out), gr_msg_endpoint(dst, dstport, hier_in)); } void @@ -435,11 +466,16 @@ void gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const { if (GR_HIER_BLOCK2_DETAIL_DEBUG) - std::cout << "Flattening " << d_owner->name() << std::endl; + std::cout << " ** Flattening " << d_owner->name() << std::endl; // Add my edges to the flow graph, resolving references to actual endpoints gr_edge_vector_t edges = d_fg->edges(); + gr_msg_edge_vector_t msg_edges = d_fg->msg_edges(); gr_edge_viter_t p; + gr_msg_edge_viter_t q,u; + + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "Flattening stream connections: " << std::endl; for (p = edges.begin(); p != edges.end(); p++) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) @@ -457,7 +493,46 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const } } } - sfg->d_msgblocks = d_fg->d_msgblocks; + + // loop through flattening hierarchical connections + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << "Flattening msg connections: " << std::endl; + + for(q = msg_edges.begin(); q != msg_edges.end(); q++) { + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << boost::format(" flattening edge ( %s, %s, %d) -> ( %s, %s, %d)\n") % q->src().block() % q->src().port() % q->src().is_hier() % q->dst().block() % q->dst().port() % q->dst().is_hier(); + + bool normal_connection = true; + + // resolve existing connections to hier ports + if(q->dst().is_hier()){ + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << boost::format(" resolve hier output (%s, %s)") % q->dst().block() % q->dst().port() << std::endl; + sfg->replace_endpoint( q->dst(), q->src(), true ); + normal_connection = false; + } + + if(q->src().is_hier()){ + if (GR_HIER_BLOCK2_DETAIL_DEBUG) + std::cout << boost::format(" resolve hier input (%s, %s)") % q->src().block() % q->src().port() << std::endl; + sfg->replace_endpoint( q->src(), q->dst(), false ); + normal_connection = false; + } + + // propogate non hier connections through + if(normal_connection){ + sfg->connect( q->src(), q->dst() ); + } + } + +/* // connect primitive edges in the new fg + for(q = msg_edges.begin(); q != msg_edges.end(); q++) { + if( (!q->src().is_hier()) && (!q->dst().is_hier()) ){ + sfg->connect( q->src(), q->dst() ); + } else { + std::cout << "not connecting hier connection!" << std::endl; + } + }*/ // Construct unique list of blocks used either in edges, inputs, // outputs, or by themselves. I still hate STL. @@ -499,7 +574,7 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const // Recurse hierarchical children for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { gr_hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(*p)); - if (hier_block2) { + if (hier_block2 && (hier_block2.get() != d_owner)) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << "flatten_aux: recursing into hierarchical block " << hier_block2 << std::endl; hier_block2->d_detail->flatten_aux(sfg); @@ -530,3 +605,4 @@ gr_hier_block2_detail::unlock() else d_owner->unlock(); } + diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h index f2d2b3c4e..b38dae301 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h @@ -61,6 +61,7 @@ private: gr_endpoint_vector_t d_outputs; // Single internal endpoint per external output gr_basic_block_vector_t d_blocks; + void connect_input(int my_port, int port, gr_basic_block_sptr block); void connect_output(int my_port, int port, gr_basic_block_sptr block); void disconnect_input(int my_port, int port, gr_basic_block_sptr block); -- cgit From 74817aee3eda6a8878b14e016091277d978b8cb5 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Mon, 10 Dec 2012 19:56:54 -0500 Subject: 1. msg passing logic fix for fan-in to hier block outputs and fan-out from hier block inputs 2. adding hier msg passing example --- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 25 +++++++++++++++++++--- gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h | 1 + .../src/lib/runtime/gr_hier_block2_detail.cc | 7 ++++++ 3 files changed, 30 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index c19863f34..9294a5dca 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -362,6 +362,22 @@ gr_flat_flowgraph::make_block_vector(gr_basic_block_vector_t &blocks) } +void gr_flat_flowgraph::clear_endpoint(const gr_msg_endpoint &e, bool is_src){ + for(size_t i=0; i > resolved_endpoints; for(q = msg_edges.begin(); q != msg_edges.end(); q++) { if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << boost::format(" flattening edge ( %s, %s, %d) -> ( %s, %s, %d)\n") % q->src().block() % q->src().port() % q->src().is_hier() % q->dst().block() % q->dst().port() % q->dst().is_hier(); @@ -509,6 +511,7 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << boost::format(" resolve hier output (%s, %s)") % q->dst().block() % q->dst().port() << std::endl; sfg->replace_endpoint( q->dst(), q->src(), true ); + resolved_endpoints.push_back(std::pair(q->dst(),true)); normal_connection = false; } @@ -516,6 +519,7 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const if (GR_HIER_BLOCK2_DETAIL_DEBUG) std::cout << boost::format(" resolve hier input (%s, %s)") % q->src().block() % q->src().port() << std::endl; sfg->replace_endpoint( q->src(), q->dst(), false ); + resolved_endpoints.push_back(std::pair(q->src(),false)); normal_connection = false; } @@ -524,6 +528,9 @@ gr_hier_block2_detail::flatten_aux(gr_flat_flowgraph_sptr sfg) const sfg->connect( q->src(), q->dst() ); } } + for(std::vector >::iterator it = resolved_endpoints.begin(); it != resolved_endpoints.end(); it++){ + sfg->clear_endpoint( (*it).first, (*it).second ); + } /* // connect primitive edges in the new fg for(q = msg_edges.begin(); q != msg_edges.end(); q++) { -- cgit From 79284e93f738d389b452f8829bf4876d3fd513b4 Mon Sep 17 00:00:00 2001 From: Alexandru Csete Date: Mon, 31 Dec 2012 12:54:12 -0800 Subject: core: fixed some unused parameter warnings --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 8 ++++---- gnuradio-core/src/lib/runtime/gr_complex.h | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index f3b7b835b..9cc2ad775 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -142,9 +142,9 @@ class GR_CORE_API gr_basic_block : public gr_msg_accepter, public boost::enable_ void message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target); void message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target); - virtual bool message_port_is_hier(pmt::pmt_t port_id) { std::cout << "is_hier\n"; return false; } - virtual bool message_port_is_hier_in(pmt::pmt_t port_id) { std::cout << "is_hier_in\n"; return false; } - virtual bool message_port_is_hier_out(pmt::pmt_t port_id) { std::cout << "is_hier_out\n"; return false; } + virtual bool message_port_is_hier(pmt::pmt_t port_id) { (void) port_id; std::cout << "is_hier\n"; return false; } + virtual bool message_port_is_hier_in(pmt::pmt_t port_id) { (void) port_id; std::cout << "is_hier_in\n"; return false; } + virtual bool message_port_is_hier_out(pmt::pmt_t port_id) { (void) port_id; std::cout << "is_hier_out\n"; return false; } /*! * \brief Get input message port names. @@ -224,7 +224,7 @@ class GR_CORE_API gr_basic_block : public gr_msg_accepter, public boost::enable_ * This check is in addition to the constraints specified by the input * and output gr_io_signatures. */ - virtual bool check_topology(int ninputs, int noutputs) { return true; } + virtual bool check_topology(int ninputs, int noutputs) { (void) ninputs; (void) noutputs; return true; } /*! * \brief Set the callback that is fired when messages are available. diff --git a/gnuradio-core/src/lib/runtime/gr_complex.h b/gnuradio-core/src/lib/runtime/gr_complex.h index 758002106..58d1525b4 100644 --- a/gnuradio-core/src/lib/runtime/gr_complex.h +++ b/gnuradio-core/src/lib/runtime/gr_complex.h @@ -27,13 +27,13 @@ typedef std::complex gr_complex; typedef std::complex gr_complexd; -inline bool is_complex (gr_complex x) { return true;} -inline bool is_complex (gr_complexd x) { return true;} -inline bool is_complex (float x) { return false;} -inline bool is_complex (double x) { return false;} -inline bool is_complex (int x) { return false;} -inline bool is_complex (char x) { return false;} -inline bool is_complex (short x) { return false;} +inline bool is_complex (gr_complex x) { (void) x; return true;} +inline bool is_complex (gr_complexd x) { (void) x; return true;} +inline bool is_complex (float x) { (void) x; return false;} +inline bool is_complex (double x) { (void) x; return false;} +inline bool is_complex (int x) { (void) x; return false;} +inline bool is_complex (char x) { (void) x; return false;} +inline bool is_complex (short x) { (void) x; return false;} // this doesn't really belong here, but there are worse places for it... -- cgit From e826097e09fdfb04d14bf87861646b88229db881 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 13 Jan 2013 13:51:46 -0800 Subject: gras: support changeset for 3.6.4 used volk from next branch cf5c930d89ac89ba5a0da4a616c88d3c37e018ae for grextras support (it uses the dispatcher) empty stubs for the gr_basic_block msg passing. This is going to be difficult to figure out. The alias stuff may or may not be related most qa pass, there seems to be some additional issues, will be working through them on futher commits Conflicts: gnuradio-core/CMakeLists.txt gnuradio-core/src/lib/runtime/CMakeLists.txt gnuradio-core/src/lib/runtime/gr_block.cc gnuradio-core/src/lib/runtime/gr_block.h gnuradio-core/src/lib/runtime/gr_hier_block2.h gnuradio-core/src/lib/runtime/gr_top_block.h gnuradio-core/src/python/gnuradio/gr/__init__.py gr-audio/examples/c++/CMakeLists.txt gr-fcd/examples/c++/CMakeLists.txt grc/python/Port.py --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 44 +- gnuradio-core/src/lib/runtime/gr_block.cc | 528 +++++++++----- gnuradio-core/src/lib/runtime/gr_block.h | 777 ++++++++------------- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 252 ++----- gnuradio-core/src/lib/runtime/gr_io_signature.h | 202 +++--- gnuradio-core/src/lib/runtime/gr_sync_block.cc | 58 +- gnuradio-core/src/lib/runtime/gr_sync_block.h | 105 ++- gnuradio-core/src/lib/runtime/gr_sync_decimator.cc | 46 +- gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 87 +-- .../src/lib/runtime/gr_sync_interpolator.cc | 47 +- .../src/lib/runtime/gr_sync_interpolator.h | 88 +-- gnuradio-core/src/lib/runtime/gr_top_block.h | 158 ++--- gnuradio-core/src/lib/runtime/gr_types.h | 97 ++- gnuradio-core/src/lib/runtime/pmx_helper.hpp | 263 +++++++ gnuradio-core/src/lib/runtime/qa_runtime.cc | 6 +- gnuradio-core/src/lib/runtime/runtime.i | 121 ++-- 16 files changed, 1398 insertions(+), 1481 deletions(-) create mode 100644 gnuradio-core/src/lib/runtime/pmx_helper.hpp (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 70938a0f1..cec02b360 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -48,40 +48,40 @@ # Append gnuradio-core library sources ######################################################################## list(APPEND gnuradio_core_sources - ${CMAKE_CURRENT_SOURCE_DIR}/gr_basic_block.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_flowgraph.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_flat_flowgraph.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_basic_block.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_flowgraph.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_flat_flowgraph.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_block.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_detail.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_executor.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_block_registry.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2_detail.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_block_detail.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_block_executor.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_block_registry.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2_detail.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_buffer.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_dispatcher.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_local_sighandler.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_queue.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_pagesize.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_preferences.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_realtime.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler_sts.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler_tpb.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_single_threaded_scheduler.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_sptr_magic.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler_sts.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_scheduler_tpb.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_single_threaded_scheduler.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_sptr_magic.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_decimator.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_interpolator.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_sys_paths.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block_impl.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_detail.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_thread_body.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block_impl.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_detail.cc + #${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_thread_body.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf_mmap_shm_open.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_vmcircbuf_mmap_tmpfile.cc @@ -98,13 +98,13 @@ list(APPEND test_gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_hier_block2.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_hier_block2_derived.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_buffer.cc - ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_flowgraph.cc + #${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_flowgraph.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_top_block.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_io_signature.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_vmcircbuf.cc - ${CMAKE_CURRENT_SOURCE_DIR}/qa_block_tags.cc + #${CMAKE_CURRENT_SOURCE_DIR}/qa_block_tags.cc ${CMAKE_CURRENT_SOURCE_DIR}/qa_runtime.cc - ${CMAKE_CURRENT_SOURCE_DIR}/qa_set_msg_handler.cc + #${CMAKE_CURRENT_SOURCE_DIR}/qa_set_msg_handler.cc ) ######################################################################## diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 43aebf0bf..8032b29fc 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -1,262 +1,456 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2009,2010 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#include "pmx_helper.hpp" #include -#include -#include +#include #include -#include -gr_block::gr_block (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature) - : gr_basic_block(name, input_signature, output_signature), - d_output_multiple (1), - d_output_multiple_set(false), - d_unaligned(0), - d_is_unaligned(false), - d_relative_rate (1.0), - d_history(1), - d_fixed_rate(false), - d_max_noutput_items_set(false), - d_max_noutput_items(0), - d_tag_propagation_policy(TPP_ALL_TO_ALL), - d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), - d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) +gr_block::gr_block(void) { - global_block_registry.register_primitive(alias(), this); + //NOP } -gr_block::~gr_block () +gr_block::gr_block( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +): + gras::Block(name) { - global_block_registry.unregister_primitive(alias()); + //this initializes private vars, order matters + this->set_fixed_rate(false); + this->set_output_multiple(1); + this->set_history(1); + this->set_relative_rate(1.0); + this->set_decimation(1); + this->set_interpolation(1); + this->set_tag_propagation_policy(TPP_ALL_TO_ALL); + this->set_input_signature(input_signature); + this->set_output_signature(output_signature); } -// stub implementation: 1:1 +void gr_block::notify_topology(const size_t num_inputs, const size_t num_outputs) +{ + _fcast_ninput_items.resize(num_inputs); + _work_ninput_items.resize(num_inputs); + _work_input_items.resize(num_inputs); + _work_output_items.resize(num_outputs); + this->check_topology(num_inputs, num_outputs); +} -void -gr_block::forecast (int noutput_items, gr_vector_int &ninput_items_required) +bool gr_block::check_topology(int, int) { - unsigned ninputs = ninput_items_required.size (); - for (unsigned i = 0; i < ninputs; i++) - ninput_items_required[i] = noutput_items + history() - 1; + return true; } -// default implementation +void gr_block::work( + const InputItems &input_items, + const OutputItems &output_items +){ + _work_io_ptr_mask = 0; + #define REALLY_BIG size_t(1 << 30) + const size_t num_inputs = input_items.size(); + const size_t num_outputs = output_items.size(); + + //------------------------------------------------------------------ + //-- initialize input buffers before work + //------------------------------------------------------------------ + size_t num_input_items = REALLY_BIG; //so big that it must std::min + for (size_t i = 0; i < num_inputs; i++) + { + _work_ninput_items[i] = input_items[i].size(); + _work_input_items[i] = input_items[i].get(); + _work_io_ptr_mask |= ptrdiff_t(_work_input_items[i]); + size_t items = input_items[i].size(); + if (_enable_fixed_rate) + { + if (items <= _input_history_items) + { + return this->mark_input_fail(i); + } + items -= _input_history_items; + } + + num_input_items = std::min(num_input_items, items); + } + + //------------------------------------------------------------------ + //-- initialize output buffers before work + //------------------------------------------------------------------ + size_t num_output_items = REALLY_BIG; //so big that it must std::min + for (size_t i = 0; i < num_outputs; i++) + { + _work_output_items[i] = output_items[i].get(); + _work_io_ptr_mask |= ptrdiff_t(_work_output_items[i]); + size_t items = output_items[i].size(); + items /= _output_multiple_items; + items *= _output_multiple_items; + num_output_items = std::min(num_output_items, items); + } + + //------------------------------------------------------------------ + //-- calculate the work_noutput_items given: + //-- min of num_input_items + //-- min of num_output_items + //-- relative rate and output multiple items + //------------------------------------------------------------------ + size_t work_noutput_items = num_output_items; + if (num_inputs and (_enable_fixed_rate or not num_outputs)) + { + size_t calc_output_items = size_t(num_input_items*_relative_rate); + calc_output_items += _output_multiple_items-1; + calc_output_items /= _output_multiple_items; + calc_output_items *= _output_multiple_items; + if (calc_output_items and calc_output_items < work_noutput_items) + work_noutput_items = calc_output_items; + } + + //------------------------------------------------------------------ + //-- forecast + //------------------------------------------------------------------ + if (num_inputs or num_outputs) + { + forecast_again_you_jerk: + _fcast_ninput_items = _work_ninput_items; //init for NOP case + this->forecast(work_noutput_items, _fcast_ninput_items); + for (size_t i = 0; i < input_items.size(); i++) + { + if (_fcast_ninput_items[i] <= _work_ninput_items[i]) continue; + + //handle the case of forecast failing + if (work_noutput_items <= _output_multiple_items) + { + return this->mark_input_fail(i); + } + + work_noutput_items = work_noutput_items/2; //backoff regime + work_noutput_items += _output_multiple_items-1; + work_noutput_items /= _output_multiple_items; + work_noutput_items *= _output_multiple_items; + goto forecast_again_you_jerk; + } + } + + const int work_ret = this->general_work( + work_noutput_items, + _work_ninput_items, + _work_input_items, + _work_output_items + ); + + if (work_ret > 0) for (size_t i = 0; i < num_outputs; i++) + { + this->produce(i, work_ret); + } + + if (work_ret == -1) this->mark_done(); +} -bool -gr_block::start() +static inline unsigned long long myullround(const double x) { - return true; + return (unsigned long long)(x + 0.5); } -bool -gr_block::stop() +void gr_block::propagate_tags(const size_t which_input, const gras::TagIter &iter) { - return true; + const size_t num_outputs = _work_output_items.size(); + + switch (_tag_prop_policy) + { + case TPP_DONT: break; //well that was ez + case TPP_ALL_TO_ALL: + for (size_t out_i = 0; out_i < num_outputs; out_i++) + { + BOOST_FOREACH(gras::Tag t, iter) + { + t.offset = myullround(t.offset * _relative_rate); + this->post_output_tag(out_i, t); + } + } + break; + case TPP_ONE_TO_ONE: + if (which_input < num_outputs) + { + BOOST_FOREACH(gras::Tag t, iter) + { + t.offset = myullround(t.offset * _relative_rate); + this->post_output_tag(which_input, t); + } + } + break; + }; } -void -gr_block::set_output_multiple (int multiple) +void gr_block::forecast(int noutput_items, std::vector &ninputs_req) { - if (multiple < 1) - throw std::invalid_argument ("gr_block::set_output_multiple"); + for (size_t i = 0; i < ninputs_req.size(); i++) + { + ninputs_req[i] = fixed_rate_noutput_to_ninput(noutput_items); + } +} - d_output_multiple_set = true; - d_output_multiple = multiple; +int gr_block::general_work( + int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items +){ + throw std::runtime_error("gr_block subclasses must overload general_work!"); } -void -gr_block::set_alignment (int multiple) +void gr_block::consume_each(const int how_many_items) { - if (multiple < 1) - throw std::invalid_argument ("gr_block::set_alignment_multiple"); + if (how_many_items < 0) return; + gras::Block::consume(size_t(how_many_items)); +} - d_output_multiple = multiple; +void gr_block::consume(const size_t i, const int how_many_items) +{ + if (how_many_items < 0) return; + gras::Block::consume(i, size_t(how_many_items)); } -void -gr_block::set_unaligned (int na) +void gr_block::produce(const size_t o, const int how_many_items) { - // unaligned value must be less than 0 and it doesn't make sense - // that it's larger than the alignment value. - if ((na < 0) || (na > d_output_multiple)) - throw std::invalid_argument ("gr_block::set_unaligned"); + if (how_many_items < 0) return; + gras::Block::produce(o, size_t(how_many_items)); +} - d_unaligned = na; +uint64_t gr_block::nitems_read(const size_t which_input) +{ + return Block::get_consumed(which_input); } -void -gr_block::set_is_unaligned (bool u) +uint64_t gr_block::nitems_written(const size_t which_output) { - d_is_unaligned = u; + return Block::get_produced(which_output); } -void -gr_block::set_relative_rate (double relative_rate) +void gr_block::set_alignment(const size_t) { - if (relative_rate < 0.0) - throw std::invalid_argument ("gr_block::set_relative_rate"); + //TODO + //probably dont need this since buffers always start aligned + //and therefore alignment is always re-acheived +} - d_relative_rate = relative_rate; +bool gr_block::is_unaligned(void) +{ + //TODO + //probably dont need this since volk dispatcher checks alignment + //32 byte aligned is good enough for you + return (_work_io_ptr_mask & ptrdiff_t(GRAS_MAX_ALIGNMENT-1)) != 0; } +size_t gr_block::fixed_rate_noutput_to_ninput(const size_t noutput_items) +{ + return ((decimation()*noutput_items)/interpolation()) + _input_history_items; +} -void -gr_block::consume (int which_input, int how_many_items) +size_t gr_block::interpolation(void) const { - d_detail->consume (which_input, how_many_items); + return _interp; } -void -gr_block::consume_each (int how_many_items) +void gr_block::set_interpolation(const size_t interp) { - d_detail->consume_each (how_many_items); + _interp = interp; + this->set_relative_rate(1.0*interp); + this->set_output_multiple(interp); } -void -gr_block::produce (int which_output, int how_many_items) +size_t gr_block::decimation(void) const { - d_detail->produce (which_output, how_many_items); + return _decim; } -int -gr_block::fixed_rate_ninput_to_noutput(int ninput) +void gr_block::set_decimation(const size_t decim) { - throw std::runtime_error("Unimplemented"); + _decim = decim; + this->set_relative_rate(1.0/decim); } -int -gr_block::fixed_rate_noutput_to_ninput(int noutput) +unsigned gr_block::history(void) const { - throw std::runtime_error("Unimplemented"); + //implement off-by-one history compat + return _input_history_items+1; } -uint64_t -gr_block::nitems_read(unsigned int which_input) +void gr_block::set_history(unsigned history) { - if(d_detail) { - return d_detail->nitems_read(which_input); - } - else { - //throw std::runtime_error("No block_detail associated with block yet"); - return 0; - } + gras::InputPortConfig config = this->get_input_config(0); + //implement off-by-one history compat + if (history == 0) history++; + _input_history_items = history-1; + config.preload_items = _input_history_items; + this->set_input_config(0, config); } -uint64_t -gr_block::nitems_written(unsigned int which_output) +void gr_block::set_fixed_rate(const bool fixed_rate) { - if(d_detail) { - return d_detail->nitems_written(which_output); - } - else { - //throw std::runtime_error("No block_detail associated with block yet"); - return 0; - } + _enable_fixed_rate = fixed_rate; } -void -gr_block::add_item_tag(unsigned int which_output, - const gr_tag_t &tag) +bool gr_block::fixed_rate(void) const { - d_detail->add_item_tag(which_output, tag); + return _enable_fixed_rate; } -void -gr_block::get_tags_in_range(std::vector &v, - unsigned int which_output, - uint64_t start, uint64_t end) +void gr_block::_update_input_reserve(void) { - d_detail->get_tags_in_range(v, which_output, start, end); + /*! + * Set an input reserve for fixed rate blocks. + * + * FIXME: Also do this when output multiple is large, + * This makes gr-trellis pass under conditions where not fixed rate set, + * but the output multiple is so large that default input isnt sufficient. + */ + if (_enable_fixed_rate or _output_multiple_items > 1024) + { + gras::InputPortConfig config = this->get_input_config(0); + config.reserve_items = size_t(0.5 + _output_multiple_items/_relative_rate); + if (config.reserve_items) this->set_input_config(0, config); + } } -void -gr_block::get_tags_in_range(std::vector &v, - unsigned int which_output, - uint64_t start, uint64_t end, - const pmt::pmt_t &key) +void gr_block::set_output_multiple(const size_t multiple) { - d_detail->get_tags_in_range(v, which_output, start, end, key); + _output_multiple_items = multiple; + gras::OutputPortConfig config = this->get_output_config(0); + config.reserve_items = multiple; + this->set_output_config(0, config); + this->_update_input_reserve(); } -gr_block::tag_propagation_policy_t -gr_block::tag_propagation_policy() +size_t gr_block::output_multiple(void) const { - return d_tag_propagation_policy; + return _output_multiple_items; } -void -gr_block::set_tag_propagation_policy(tag_propagation_policy_t p) +void gr_block::set_relative_rate(double relative_rate) { - d_tag_propagation_policy = p; + _relative_rate = relative_rate; + this->_update_input_reserve(); } +double gr_block::relative_rate(void) const +{ + return _relative_rate; +} -int -gr_block::max_noutput_items() +int gr_block::max_noutput_items(void) const { - return d_max_noutput_items; + return this->get_output_config(0).maximum_items; } -void -gr_block::set_max_noutput_items(int m) +void gr_block::set_max_noutput_items(int max_items) { - if(m <= 0) - throw std::runtime_error("gr_block::set_max_noutput_items: value for max_noutput_items must be greater than 0.\n"); + gras::OutputPortConfig config = this->get_output_config(0); + config.maximum_items = max_items; + this->set_output_config(0, config); +} + +void gr_block::unset_max_noutput_items(void) +{ + this->set_max_noutput_items(0); +} + +bool gr_block::is_set_max_noutput_items(void) const +{ + return this->max_noutput_items() != 0; +} - d_max_noutput_items = m; - d_max_noutput_items_set = true; +static gr_tag_t Tag2gr_tag(const gras::Tag &tag) +{ + gr_tag_t t; + t.offset = tag.offset; + const gras::StreamTag &st = tag.object.as(); + t.key = pmt::pmc_to_pmt(st.key); + t.value = pmt::pmc_to_pmt(st.val); + t.srcid = pmt::pmc_to_pmt(st.src); + return t; } -void -gr_block::unset_max_noutput_items() +static gras::Tag gr_tag2Tag(const gr_tag_t &tag) { - d_max_noutput_items_set = false; + return gras::Tag + ( + tag.offset, + PMC_M(gras::StreamTag( + pmt::pmt_to_pmc(tag.key), + pmt::pmt_to_pmc(tag.value), + pmt::pmt_to_pmc(tag.srcid) + )) + ); +} + +void gr_block::add_item_tag( + const size_t which_output, const gr_tag_t &tag +){ + this->post_output_tag(which_output, gr_tag2Tag(tag)); +} + +void gr_block::add_item_tag( + const size_t which_output, + uint64_t abs_offset, + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid +){ + gr_tag_t t; + t.offset = abs_offset; + t.key = key; + t.value = value; + t.srcid = srcid; + this->add_item_tag(which_output, t); +} + +void gr_block::get_tags_in_range( + std::vector &tags, + const size_t which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key +){ + tags.clear(); + BOOST_FOREACH(const gras::Tag &tag, this->get_input_tags(which_input)) + { + if (tag.offset >= abs_start and tag.offset <= abs_end) + { + gr_tag_t t = Tag2gr_tag(tag); + if (key or pmt::pmt_equal(t.key, key)) tags.push_back(t); + } + } } -bool -gr_block::is_set_max_noutput_items() +gr_block::tag_propagation_policy_t gr_block::tag_propagation_policy(void) { - return d_max_noutput_items_set; + return _tag_prop_policy; } -std::ostream& -operator << (std::ostream& os, const gr_block *m) +void gr_block::set_tag_propagation_policy(gr_block::tag_propagation_policy_t p) { - os << "name() << " (" << m->unique_id() << ")>"; - return os; + _tag_prop_policy = p; } -int -gr_block::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gras::BufferQueueSptr gr_block::input_buffer_allocator(const size_t, const gras::SBufferConfig &config) { - throw std::runtime_error("gr_block::general_work() not implemented"); - return 0; + if (_input_history_items) + { + return gras::BufferQueue::make_circ(config, 32/*many*/); + } + return gras::BufferQueueSptr(); } diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 57e3fda90..48bb2fc97 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -1,481 +1,322 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2007,2009,2010 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_BLOCK_H -#define INCLUDED_GR_BLOCK_H +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#ifndef INCLUDED_GNURADIO_GR_BLOCK_H +#define INCLUDED_GNURADIO_GR_BLOCK_H #include -#include +#include +#include +#include #include +#include +#include +#include +#include -/*! - * \brief The abstract base class for all 'terminal' processing blocks. - * \ingroup base_blk - * - * A signal processing flow is constructed by creating a tree of - * hierarchical blocks, which at any level may also contain terminal nodes - * that actually implement signal processing functions. This is the base - * class for all such leaf nodes. - - * Blocks have a set of input streams and output streams. The - * input_signature and output_signature define the number of input - * streams and output streams respectively, and the type of the data - * items in each stream. - * - * Although blocks may consume data on each input stream at a - * different rate, all outputs streams must produce data at the same - * rate. That rate may be different from any of the input rates. - * - * User derived blocks override two methods, forecast and general_work, - * to implement their signal processing behavior. forecast is called - * by the system scheduler to determine how many items are required on - * each input stream in order to produce a given number of output - * items. - * - * general_work is called to perform the signal processing in the block. - * It reads the input items and writes the output items. - */ - -class GR_CORE_API gr_block : public gr_basic_block { - - public: - - //! Magic return values from general_work - enum { - WORK_CALLED_PRODUCE = -2, - WORK_DONE = -1 - }; - - enum tag_propagation_policy_t { - TPP_DONT = 0, - TPP_ALL_TO_ALL = 1, - TPP_ONE_TO_ONE = 2 - }; - - virtual ~gr_block (); - - /*! - * Assume block computes y_i = f(x_i, x_i-1, x_i-2, x_i-3...) - * History is the number of x_i's that are examined to produce one y_i. - * This comes in handy for FIR filters, where we use history to - * ensure that our input contains the appropriate "history" for the - * filter. History should be equal to the number of filter taps. - */ - unsigned history () const { return d_history; } - void set_history (unsigned history) { d_history = history; } - - /*! - * \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. - */ - bool fixed_rate() const { return d_fixed_rate; } - - // ---------------------------------------------------------------- - // override these to define your behavior - // ---------------------------------------------------------------- - - /*! - * \brief Estimate input requirements given output request - * - * \param noutput_items number of output items to produce - * \param ninput_items_required number of input items required on each input stream - * - * Given a request to product \p noutput_items, estimate the number of - * data items required on each input stream. The estimate doesn't have - * to be exact, but should be close. - */ - virtual void forecast (int noutput_items, - gr_vector_int &ninput_items_required); - - /*! - * \brief compute output items from input items - * - * \param noutput_items number of output items to write on each output stream - * \param ninput_items number of input items available on each input stream - * \param input_items vector of pointers to the input items, one entry per input stream - * \param output_items vector of pointers to the output items, one entry per output stream - * - * \returns number of items actually written to each output stream, or -1 on EOF. - * It is OK to return a value less than noutput_items. -1 <= return value <= noutput_items - * - * general_work must call consume or consume_each to indicate how many items - * were consumed on each input stream. - */ - virtual int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - /*! - * \brief Called to enable drivers, etc for i/o devices. - * - * This allows a block to enable an associated driver to begin - * transfering data just before we start to execute the scheduler. - * The end result is that this reduces latency in the pipeline when - * dealing with audio devices, usrps, etc. - */ - virtual bool start(); - - /*! - * \brief Called to disable drivers, etc for i/o devices. - */ - virtual bool stop(); - - // ---------------------------------------------------------------- - - /*! - * \brief Constrain the noutput_items argument passed to forecast and general_work - * - * set_output_multiple causes the scheduler to ensure that the noutput_items - * argument passed to forecast and general_work will be an integer multiple - * of \param multiple The default value of output multiple is 1. - */ - void set_output_multiple (int multiple); - int output_multiple () const { return d_output_multiple; } - bool output_multiple_set () const { return d_output_multiple_set; } - - /*! - * \brief Constrains buffers to work on a set item alignment (for SIMD) - * - * set_alignment_multiple causes the scheduler to ensure that the noutput_items - * argument passed to forecast and general_work will be an integer multiple - * of \param multiple The default value is 1. - * - * This control is similar to the output_multiple setting, except - * that if the number of items passed to the block is less than the - * output_multiple, this value is ignored and the block can produce - * like normal. The d_unaligned value is set to the number of items - * the block is off by. In the next call to general_work, the - * noutput_items is set to d_unaligned or less until - * d_unaligned==0. The buffers are now aligned again and the aligned - * calls can be performed again. - */ - void set_alignment (int multiple); - int alignment () const { return d_output_multiple; } - - void set_unaligned (int na); - int unaligned () const { return d_unaligned; } - void set_is_unaligned (bool u); - bool is_unaligned () const { return d_is_unaligned; } - - /*! - * \brief Tell the scheduler \p how_many_items of input stream \p which_input were consumed. - */ - void consume (int which_input, int how_many_items); - - /*! - * \brief Tell the scheduler \p how_many_items were consumed on each input stream. - */ - 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. - * The default relative_rate is 1.0 - * - * decimators have relative_rates < 1.0 - * interpolators have relative_rates > 1.0 - */ - void set_relative_rate (double relative_rate); - - /*! - * \brief return the approximate output rate / input rate - */ - double relative_rate () const { return d_relative_rate; } - - /* - * The following two methods provide special case info to the - * scheduler in the event that a block has a fixed input to output - * ratio. gr_sync_block, gr_sync_decimator and gr_sync_interpolator - * override these. If you're fixed rate, subclass one of those. - */ - /*! - * \brief Given ninput samples, return number of output samples that will be produced. - * N.B. this is only defined if fixed_rate returns true. - * Generally speaking, you don't need to override this. - */ - virtual int fixed_rate_ninput_to_noutput(int ninput); - - /*! - * \brief Given noutput samples, return number of input samples required to produce noutput. - * N.B. this is only defined if fixed_rate returns true. - * Generally speaking, you don't need to override this. - */ - virtual int fixed_rate_noutput_to_ninput(int noutput); - - /*! - * \brief Return the number of items read on input stream which_input - */ - uint64_t nitems_read(unsigned int which_input); - - /*! - * \brief Return the number of items written on output stream which_output - */ - uint64_t nitems_written(unsigned int which_output); - - /*! - * \brief Asks for the policy used by the scheduler to moved tags downstream. - */ - tag_propagation_policy_t tag_propagation_policy(); - - /*! - * \brief Set the policy by the scheduler to determine how tags are moved downstream. - */ - void set_tag_propagation_policy(tag_propagation_policy_t p); - - /*! - * \brief Return the maximum number of output items this block will - * handle during a call to work. - */ - int max_noutput_items(); - - /*! - * \brief Set the maximum number of ouput items htis block will - * handle during a call to work. - * - * \param m the maximum noutput_items this block will handle. - */ - void set_max_noutput_items(int m); - - /*! - * \brief Clear the switch for using the max_noutput_items value of this block. - * - * When is_set_max_noutput_items() returns 'true', the scheduler - * will use the value returned by max_noutput_items() to limit the - * size of the number of items possible for this block's work - * function. If is_set_max_notput_items() returns 'false', then the - * scheduler ignores the internal value and uses the value set - * globally in the top_block. - * - * Use this value to clear the 'is_set' flag so the scheduler will - * ignore this. Use the set_max_noutput_items(m) call to both set a - * new value for max_noutput_items and to reenable its use in the - * scheduler. - */ - void unset_max_noutput_items(); - - /*! - * \brief Ask the block if the flag is or is not set to use the - * internal value of max_noutput_items during a call to work. - */ - bool is_set_max_noutput_items(); - - /* - * Used to expand the vectors that hold the min/max buffer sizes. - * - * Specifically, when -1 is used, the vectors are just initialized - * with 1 value; this is used by the flat_flowgraph to expand when - * required to add a new value for new ports on these blocks. - */ - void expand_minmax_buffer(int port) { - if((size_t)port >= d_max_output_buffer.size()) - set_max_output_buffer(port, -1); - if((size_t)port >= d_min_output_buffer.size()) - set_min_output_buffer(port, -1); - } - - /*! - * \brief Returns max buffer size on output port \p i. - */ - long max_output_buffer(size_t i) { - if(i >= d_max_output_buffer.size()) - throw std::invalid_argument("gr_basic_block::max_output_buffer: port out of range."); - return d_max_output_buffer[i]; - } - - /*! - * \brief Sets max buffer size on all output ports. - */ - void set_max_output_buffer(long max_output_buffer) { - for(int i = 0; i < output_signature()->max_streams(); i++) { - set_max_output_buffer(i, max_output_buffer); +typedef std::vector gr_vector_int; +typedef std::vector gr_vector_void_star; +typedef std::vector gr_vector_const_void_star; + +namespace gnuradio +{ +//! dummy entry, just here for legacy purposes +template +boost::shared_ptr get_initial_sptr(T *p) +{ + return boost::shared_ptr(p); +} +} + +struct GR_CORE_API gr_block : gras::Block +{ + + gr_block(void); + + gr_block( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature + ); + + virtual bool check_topology(int ninputs, int noutputs); + + //! Overload me! I am the forecast + virtual void forecast(int, std::vector &); + + //! Return options for the work call + enum + { + WORK_CALLED_PRODUCE = -2, + WORK_DONE = -1 + }; + + /*! + * \brief compute output items from input items + * + * \param noutput_items number of output items to write on each output stream + * \param ninput_items number of input items available on each input stream + * \param input_items vector of pointers to the input items, one entry per input stream + * \param output_items vector of pointers to the output items, one entry per output stream + * + * \returns number of items actually written to each output stream, or -1 on EOF. + * It is OK to return a value less than noutput_items. -1 <= return value <= noutput_items + * + * general_work must call consume or consume_each to indicate how many items + * were consumed on each input stream. + */ + virtual int general_work( + int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ); + + //! Call during work to consume items + void consume_each(const int how_many_items); + + void consume(const size_t i, const int how_many_items); + + void produce(const size_t o, const int how_many_items); + + //! Get absolute count of all items consumed on the given input port + uint64_t nitems_read(const size_t which_input = 0); + + //! Get absolute count of all items produced on the given output port + uint64_t nitems_written(const size_t which_output = 0); + + void add_item_tag( + const size_t which_output, const gr_tag_t &tag + ); + + void add_item_tag( + const size_t which_output, + uint64_t abs_offset, + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid=pmt::PMT_F + ); + + void get_tags_in_range( + std::vector &tags, + const size_t which_input, + uint64_t abs_start, + uint64_t abs_end, + const pmt::pmt_t &key = pmt::pmt_t() + ); + + void set_alignment(const size_t alignment); + + bool is_unaligned(void); + + size_t fixed_rate_noutput_to_ninput(const size_t noutput_items); + + size_t interpolation(void) const; + + void set_interpolation(const size_t); + + size_t decimation(void) const; + + void set_decimation(const size_t); + + int max_noutput_items(void) const; + + void set_max_noutput_items(int); + + void unset_max_noutput_items(void); + + bool is_set_max_noutput_items(void) const; + + /******************************************************************* + * Deal with input and output port configuration + ******************************************************************/ + + unsigned history(void) const; + + void set_history(unsigned history); + + /*! + * Enable fixed rate logic. + * When enabled, relative rate is assumed to be set, + * and forecast is automatically called. + * Also, consume will be called automatically. + */ + void set_fixed_rate(const bool fixed_rate); + + //! Get the fixed rate setting + bool fixed_rate(void) const; + + /*! + * The relative rate can be thought of as interpolation/decimation. + * In other words, relative rate is the ratio of output items to input items. + */ + void set_relative_rate(const double relative_rate); + + //! Get the relative rate setting + double relative_rate(void) const; + + /*! + * The output multiple setting controls work output buffer sizes. + * Buffers will be number of items modulo rounted to the multiple. + */ + void set_output_multiple(const size_t multiple); + + //! Get the output multiple setting + size_t output_multiple(void) const; + + /******************************************************************* + * Deal with tag handling and tag configuration + ******************************************************************/ + + enum tag_propagation_policy_t + { + TPP_DONT = 0, + TPP_ALL_TO_ALL = 1, + TPP_ONE_TO_ONE = 2 + }; + + tag_propagation_policy_t tag_propagation_policy(void); + + void set_tag_propagation_policy(tag_propagation_policy_t p); + + ///////////// TODO ////////////////////// + void set_max_output_buffer(long){} + void set_max_output_buffer(int, long){} + long max_output_buffer(size_t){return 0;} + void set_min_output_buffer(long){} + void set_min_output_buffer(int, long){} + long min_output_buffer(size_t){return 0;} + + ///////////// ALIAS stuff - is it used? ////////////////////// + std::string d_symbol_alias; + std::string d_symbol_name; + std::string symbol_name() const { return d_symbol_name; } + bool alias_set() { return !d_symbol_alias.empty(); } + std::string alias(){ return alias_set()?d_symbol_alias:symbol_name(); } + pmt::pmt_t alias_pmt(){ return pmt::pmt_intern(alias()); } + void set_block_alias(std::string name){d_symbol_alias = name;} + + ///////////// MSG stuff not implemented ////////////////////// + typedef std::deque msg_queue_t; + typedef std::map msg_queue_map_t; + typedef std::map::iterator msg_queue_map_itr; + msg_queue_map_t msg_queue; + pmt::pmt_t message_subscribers; + + template void set_msg_handler(pmt::pmt_t which_port, T msg_handler){} + + void message_port_register_in(pmt::pmt_t /*port_id*/){} + void message_port_register_out(pmt::pmt_t /*port_id*/){} + void message_port_pub(pmt::pmt_t /*port_id*/, pmt::pmt_t /*msg*/){} + void message_port_sub(pmt::pmt_t /*port_id*/, pmt::pmt_t /*target*/){} + void message_port_unsub(pmt::pmt_t /*port_id*/, pmt::pmt_t /*target*/){} + + virtual bool message_port_is_hier(pmt::pmt_t port_id) { (void) port_id; /*std::cout << "is_hier\n";*/ return false; } + virtual bool message_port_is_hier_in(pmt::pmt_t port_id) { (void) port_id; /*std::cout << "is_hier_in\n";*/ return false; } + virtual bool message_port_is_hier_out(pmt::pmt_t port_id) { (void) port_id; /*std::cout << "is_hier_out\n";*/ return false; } + + /*! + * \brief Get input message port names. + * + * Returns the available input message ports for a block. The + * return object is a PMT vector that is filled with PMT symbols. + */ + pmt::pmt_t message_ports_in(){return pmt::PMT_NIL;} + + /*! + * \brief Get output message port names. + * + * Returns the available output message ports for a block. The + * return object is a PMT vector that is filled with PMT symbols. + */ + pmt::pmt_t message_ports_out(){return pmt::PMT_NIL;} + + //! is the queue empty? + bool empty_p(pmt::pmt_t which_port) { + if(msg_queue.find(which_port) == msg_queue.end()) + throw std::runtime_error("port does not exist!"); + return msg_queue[which_port].empty(); } - } - - /*! - * \brief Sets max buffer size on output port \p port. - */ - void set_max_output_buffer(int port, long max_output_buffer) { - if((size_t)port >= d_max_output_buffer.size()) - d_max_output_buffer.push_back(max_output_buffer); - else - d_max_output_buffer[port] = max_output_buffer; - } - - /*! - * \brief Returns min buffer size on output port \p i. - */ - long min_output_buffer(size_t i) { - if(i >= d_min_output_buffer.size()) - throw std::invalid_argument("gr_basic_block::min_output_buffer: port out of range."); - return d_min_output_buffer[i]; - } - - /*! - * \brief Sets min buffer size on all output ports. - */ - void set_min_output_buffer(long min_output_buffer) { - for(int i=0; imax_streams(); i++) { - set_min_output_buffer(i, min_output_buffer); + bool empty_p() { + bool rv = true; + BOOST_FOREACH(msg_queue_map_t::value_type &i, msg_queue){ rv &= msg_queue[i.first].empty(); } + return rv; } - } - - /*! - * \brief Sets min buffer size on output port \p port. - */ - void set_min_output_buffer(int port, long min_output_buffer) { - if((size_t)port >= d_min_output_buffer.size()) - d_min_output_buffer.push_back(min_output_buffer); - else - d_min_output_buffer[port] = min_output_buffer; - } - - // ---------------------------------------------------------------------------- - - private: - - int d_output_multiple; - bool d_output_multiple_set; - int d_unaligned; - bool d_is_unaligned; - double d_relative_rate; // approx output_rate / input_rate - gr_block_detail_sptr d_detail; // implementation details - unsigned d_history; - bool d_fixed_rate; - bool d_max_noutput_items_set; // if d_max_noutput_items is valid - int d_max_noutput_items; // value of max_noutput_items for this block - tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream - - protected: - gr_block (void){} //allows pure virtual interface sub-classes - gr_block (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - - void set_fixed_rate(bool fixed_rate){ d_fixed_rate = fixed_rate; } - - - /*! - * \brief Adds a new tag onto the given output buffer. - * - * \param which_output an integer of which output stream to attach the tag - * \param abs_offset a uint64 number of the absolute item number - * assicated with the tag. Can get from nitems_written. - * \param key the tag key as a PMT symbol - * \param value any PMT holding any value for the given key - * \param srcid optional source ID specifier; defaults to PMT_F - */ - inline void add_item_tag(unsigned int which_output, - uint64_t abs_offset, - const pmt::pmt_t &key, - const pmt::pmt_t &value, - const pmt::pmt_t &srcid=pmt::PMT_F) - { - gr_tag_t tag; - tag.offset = abs_offset; - tag.key = key; - tag.value = value; - tag.srcid = srcid; - this->add_item_tag(which_output, tag); + + //| Acquires and release the mutex + void insert_tail( pmt::pmt_t /*which_port*/, pmt::pmt_t /*msg*/){} + /*! + * \returns returns pmt at head of queue or pmt_t() if empty. + */ + pmt::pmt_t delete_head_nowait( pmt::pmt_t /*which_port*/){return pmt::PMT_NIL;} + + /*! + * \returns returns pmt at head of queue or pmt_t() if empty. + */ + pmt::pmt_t delete_head_blocking( pmt::pmt_t /*which_port*/){return pmt::PMT_NIL;} + + msg_queue_t::iterator get_iterator(pmt::pmt_t which_port){ + return msg_queue[which_port].begin(); } - /*! - * \brief Adds a new tag onto the given output buffer. - * - * \param which_output an integer of which output stream to attach the tag - * \param tag the tag object to add - */ - void add_item_tag(unsigned int which_output, const gr_tag_t &tag); - - /*! - * \brief Given a [start,end), returns a vector of all tags in the range. - * - * Range of counts is from start to end-1. - * - * Tags are tuples of: - * (item count, source id, key, value) - * - * \param v a vector reference to return tags into - * \param which_input an integer of which input stream to pull from - * \param abs_start a uint64 count of the start of the range of interest - * \param abs_end a uint64 count of the end of the range of interest - */ - void get_tags_in_range(std::vector &v, - unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end); - - /*! - * \brief Given a [start,end), returns a vector of all tags in the range - * with a given key. - * - * Range of counts is from start to end-1. - * - * Tags are tuples of: - * (item count, source id, key, value) - * - * \param v a vector reference to return tags into - * \param which_input an integer of which input stream to pull from - * \param abs_start a uint64 count of the start of the range of interest - * \param abs_end a uint64 count of the end of the range of interest - * \param key a PMT symbol key to filter only tags of this key - */ - void get_tags_in_range(std::vector &v, - unsigned int which_input, - uint64_t abs_start, - uint64_t abs_end, - const pmt::pmt_t &key); - - std::vector d_max_output_buffer; - std::vector d_min_output_buffer; - - - // These are really only for internal use, but leaving them public avoids - // having to work up an ever-varying list of friend GR_CORE_APIs - - public: - gr_block_detail_sptr detail () const { return d_detail; } - void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } -}; + void erase_msg(pmt::pmt_t which_port, msg_queue_t::iterator it){ + msg_queue[which_port].erase(it); + } -typedef std::vector gr_block_vector_t; -typedef std::vector::iterator gr_block_viter_t; + virtual bool has_msg_port(pmt::pmt_t which_port){ + if(msg_queue.find(which_port) != msg_queue.end()){ + return true; + } + if(pmt::pmt_dict_has_key(message_subscribers, which_port)){ + return true; + } + return false; + } -inline gr_block_sptr cast_to_block_sptr(gr_basic_block_sptr p) -{ - return boost::dynamic_pointer_cast(p); -} + ///////////////// private vars ////////////////////// + + gr_vector_int _work_ninput_items; + gr_vector_int _fcast_ninput_items; + gr_vector_const_void_star _work_input_items; + gr_vector_void_star _work_output_items; + ptrdiff_t _work_io_ptr_mask; + size_t _output_multiple_items; + double _relative_rate; + bool _enable_fixed_rate; + size_t _input_history_items; + tag_propagation_policy_t _tag_prop_policy; + size_t _interp, _decim; + ///////////////// the Block overloads ////////////////////// + + //! implements work -> calls general work + void work(const InputItems &, const OutputItems &); + + //! notifications of new topological commits + void notify_topology(const size_t, const size_t); + + //! implements tag_propagation_policy() + virtual void propagate_tags(const size_t, const gras::TagIter &); + + void _update_input_reserve(void); + + gras::BufferQueueSptr input_buffer_allocator(const size_t, const gras::SBufferConfig &); + +}; -std::ostream& -operator << (std::ostream& os, const gr_block *m); +typedef boost::shared_ptr gr_block_sptr; -#endif /* INCLUDED_GR_BLOCK_H */ +#endif /*INCLUDED_GNURADIO_GR_BLOCK_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index f80dd73e4..4163557ca 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -1,208 +1,74 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008,2009 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDED_GR_HIER_BLOCK2_H -#define INCLUDED_GR_HIER_BLOCK2_H +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#ifndef INCLUDED_GNURADIO_GR_HIER_BLOCK2_H +#define INCLUDED_GNURADIO_GR_HIER_BLOCK2_H #include -#include +#include +#include -/*! - * \brief public constructor for gr_hier_block2 - - */ -GR_CORE_API gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - -class gr_hier_block2_detail; - -/*! - * \brief Hierarchical container class for gr_block's and gr_hier_block2's - * \ingroup container_blk - * \ingroup base_blk - * - */ -class GR_CORE_API gr_hier_block2 : public gr_basic_block +struct GR_CORE_API gr_hier_block2 : gras::HierBlock { -private: - friend class gr_hier_block2_detail; - friend GR_CORE_API gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - - /*! - * \brief Private implementation details of gr_hier_block2 - */ - gr_hier_block2_detail *d_detail; - -protected: - gr_hier_block2 (void){} //allows pure virtual interface sub-classes - gr_hier_block2(const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - -public: - virtual ~gr_hier_block2(); - - /*! - * \brief typedef for object returned from self(). - * - * This type is only guaranteed to be passable to connect and disconnect. - * No other assumptions should be made about it. - */ - typedef gr_basic_block_sptr opaque_self; - - /*! - * \brief Return an object, representing the current block, which can be passed to connect. - * - * The returned object may only be used as an argument to connect or disconnect. - * Any other use of self() results in unspecified (erroneous) behavior. - */ - opaque_self self(); - - /*! - * \brief Add a stand-alone (possibly hierarchical) block to internal graph - * - * This adds a gr-block or hierarchical block to the internal graph - * without wiring it to anything else. - */ - void connect(gr_basic_block_sptr block); - - /*! - * \brief Add gr-blocks or hierarchical blocks to internal graph and wire together - * - * This adds (if not done earlier by another connect) a pair of gr-blocks or - * hierarchical blocks to the internal flowgraph, and wires the specified output - * port to the specified input port. - */ - void connect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port); - - /*! - * \brief Add gr-blocks or hierarchical blocks to internal graph and wire together - * - * This adds (if not done earlier by another connect) a pair of gr-blocks or - * hierarchical blocks to the internal message port subscription - */ - void msg_connect(gr_basic_block_sptr src, pmt::pmt_t srcport, - gr_basic_block_sptr dst, pmt::pmt_t dstport); - void msg_connect(gr_basic_block_sptr src, std::string srcport, - gr_basic_block_sptr dst, std::string dstport); - void msg_disconnect(gr_basic_block_sptr src, pmt::pmt_t srcport, - gr_basic_block_sptr dst, pmt::pmt_t dstport); - void msg_disconnect(gr_basic_block_sptr src, std::string srcport, - gr_basic_block_sptr dst, std::string dstport); - - /*! - * \brief Remove a gr-block or hierarchical block from the internal flowgraph. - * - * This removes a gr-block or hierarchical block from the internal flowgraph, - * disconnecting it from other blocks as needed. - * - */ - void disconnect(gr_basic_block_sptr block); - - /*! - * \brief Disconnect a pair of gr-blocks or hierarchical blocks in internal - * flowgraph. - * - * This disconnects the specified input port from the specified output port - * of a pair of gr-blocks or hierarchical blocks. - */ - void disconnect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port); - /*! - * \brief Disconnect all connections in the internal flowgraph. - * - * This call removes all output port to input port connections in the internal - * flowgraph. - */ - void disconnect_all(); + gr_hier_block2(void); - /*! - * Lock a flowgraph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flowgraph - * will be reconfigured. - * - * N.B. lock() and unlock() may not be called from a flowgraph thread - * (E.g., gr_block::work method) or deadlock will occur when - * reconfiguration happens. - */ - virtual void lock(); + gr_hier_block2( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature + ); - /*! - * Unlock a flowgraph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flowgraph - * will be reconfigured. - * - * N.B. lock() and unlock() may not be called from a flowgraph thread - * (E.g., gr_block::work method) or deadlock will occur when - * reconfiguration happens. - */ - virtual void unlock(); + const gr_hier_block2 &self(void) const + { + return *this; + } - // This is a public method for ease of code organization, but should be - // ignored by the user. - gr_flat_flowgraph_sptr flatten() const; +}; - gr_hier_block2_sptr to_hier_block2(); // Needed for Python type coercion +typedef boost::shared_ptr gr_hier_block2_sptr; - bool has_msg_port(pmt::pmt_t which_port){ - return message_port_is_hier(which_port) || gr_basic_block::has_msg_port(which_port); - } - - bool message_port_is_hier(pmt::pmt_t port_id){ - return message_port_is_hier_in(port_id) || message_port_is_hier_out(port_id); - } - bool message_port_is_hier_in(pmt::pmt_t port_id){ - return pmt::pmt_list_has(hier_message_ports_in, port_id); - } - bool message_port_is_hier_out(pmt::pmt_t port_id){ - return pmt::pmt_list_has(hier_message_ports_out, port_id); - } - - pmt::pmt_t hier_message_ports_in; - pmt::pmt_t hier_message_ports_out; +GR_CORE_API gr_hier_block2_sptr gr_make_hier_block2( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +); - void message_port_register_hier_in(pmt::pmt_t port_id){ - if(pmt::pmt_list_has(hier_message_ports_in, port_id)) - throw std::invalid_argument("hier msg in port by this name already registered"); - if(msg_queue.find(port_id) != msg_queue.end()) - throw std::invalid_argument("block already has a primitive input port by this name"); - hier_message_ports_in = pmt::pmt_list_add(hier_message_ports_in, port_id); - } - void message_port_register_hier_out(pmt::pmt_t port_id){ - if(pmt::pmt_list_has(hier_message_ports_out, port_id)) - throw std::invalid_argument("hier msg out port by this name already registered"); - if(pmt::pmt_dict_has_key(message_subscribers, port_id)) - throw std::invalid_argument("block already has a primitive output port by this name"); - hier_message_ports_out = pmt::pmt_list_add(hier_message_ports_out, port_id); - } +inline gr_hier_block2::gr_hier_block2(void) +{ + //NOP +} -}; +inline gr_hier_block2::gr_hier_block2( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +): + gras::HierBlock(name) +{ + this->set_input_signature(input_signature); + this->set_output_signature(output_signature); +} -inline gr_hier_block2_sptr cast_to_hier_block2_sptr(gr_basic_block_sptr block) { - return boost::dynamic_pointer_cast(block); +inline gr_hier_block2_sptr gr_make_hier_block2( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +){ + return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); } -#endif /* INCLUDED_GR_HIER_BLOCK2_H */ +#endif /*INCLUDED_GNURADIO_GR_HIER_BLOCK2_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index fd1825797..78b1502f0 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -1,117 +1,85 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2007 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_IO_SIGNATURE_H -#define INCLUDED_IO_SIGNATURE_H - -#include -#include - -/*! - * \brief Create an i/o signature - * - * \ingroup internal - * \param min_streams specify minimum number of streams (>= 0) - * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) - * \param sizeof_stream_item specify the size of the items in each stream - */ -GR_CORE_API gr_io_signature_sptr -gr_make_io_signature(int min_streams, int max_streams, - int sizeof_stream_item); - -/*! - * \brief Create an i/o signature - * - * \param min_streams specify minimum number of streams (>= 0) - * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) - * \param sizeof_stream_item1 specify the size of the items in the first stream - * \param sizeof_stream_item2 specify the size of the items in the second and subsequent streams - */ -GR_CORE_API gr_io_signature_sptr -gr_make_io_signature2(int min_streams, int max_streams, - int sizeof_stream_item1, - int sizeof_stream_item2 - ); - -/*! - * \brief Create an i/o signature - * - * \param min_streams specify minimum number of streams (>= 0) - * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) - * \param sizeof_stream_item1 specify the size of the items in the first stream - * \param sizeof_stream_item2 specify the size of the items in the second stream - * \param sizeof_stream_item3 specify the size of the items in the third and subsequent streams - */ -GR_CORE_API gr_io_signature_sptr -gr_make_io_signature3(int min_streams, int max_streams, - int sizeof_stream_item1, - int sizeof_stream_item2, - int sizeof_stream_item3 - ); - -/*! - * \brief Create an i/o signature - * - * \param min_streams specify minimum number of streams (>= 0) - * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) - * \param sizeof_stream_items specify the size of the items in the streams - * - * If there are more streams than there are entries in sizeof_stream_items, the - * value of the last entry in sizeof_stream_items is used for the missing values. - * sizeof_stream_items must contain at least 1 entry. - */ -GR_CORE_API gr_io_signature_sptr -gr_make_io_signaturev(int min_streams, int max_streams, - const std::vector &sizeof_stream_items); - - -/*! - * \brief i/o signature for input and output ports. - * \brief misc - */ -class GR_CORE_API gr_io_signature { - int d_min_streams; - int d_max_streams; - std::vector d_sizeof_stream_item; - - gr_io_signature(int min_streams, int max_streams, - const std::vector &sizeof_stream_items); - - friend GR_CORE_API gr_io_signature_sptr - gr_make_io_signaturev(int min_streams, - int max_streams, - const std::vector &sizeof_stream_items); - - public: - - static const int IO_INFINITE = -1; - - ~gr_io_signature (); - - int min_streams () const { return d_min_streams; } - int max_streams () const { return d_max_streams; } - int sizeof_stream_item (int index) const; - std::vector sizeof_stream_items() const; -}; - - -#endif /* INCLUDED_IO_SIGNATURE_H */ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#ifndef INCLUDED_GNURADIO_GR_IO_SIGNATURE_H +#define INCLUDED_GNURADIO_GR_IO_SIGNATURE_H + +#include +#include + +typedef gras::IOSignature gr_io_signature; +typedef gr_io_signature gr_io_signature_sptr; + +inline gr_io_signature_sptr gr_make_io_signature( + int min_streams, + int max_streams, + int sizeof_stream_item +){ + gr_io_signature io_sig(min_streams, max_streams); + + if (io_sig.max_streams() != gr_io_signature::IO_INFINITE) + { + io_sig.resize(io_sig.max_streams(), sizeof_stream_item); + } + else + { + io_sig.resize(1, sizeof_stream_item); + } + + return io_sig; +} + +inline gr_io_signature_sptr gr_make_io_signature2( + int min_streams, + int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2 +){ + gr_io_signature io_sig(min_streams, max_streams); + io_sig.push_back(sizeof_stream_item1); + io_sig.push_back(sizeof_stream_item2); + return io_sig; +} + +inline gr_io_signature_sptr gr_make_io_signature3( + int min_streams, + int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2, + int sizeof_stream_item3 +){ + gr_io_signature io_sig(min_streams, max_streams); + io_sig.push_back(sizeof_stream_item1); + io_sig.push_back(sizeof_stream_item2); + io_sig.push_back(sizeof_stream_item3); + return io_sig; +} + +template +inline gr_io_signature_sptr gr_make_io_signaturev( + int min_streams, + int max_streams, + const std::vector &sizeof_stream_items +){ + gr_io_signature io_sig(min_streams, max_streams); + for (unsigned i = 0; i < sizeof_stream_items.size(); i++) + { + io_sig.push_back(sizeof_stream_items[i]); + } + return io_sig; +} + +#endif /*INCLUDED_GNURADIO_GR_IO_SIGNATURE_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.cc b/gnuradio-core/src/lib/runtime/gr_sync_block.cc index 94efcdc8e..492fe2c2a 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.cc @@ -26,43 +26,39 @@ #include -gr_sync_block::gr_sync_block (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature) - : gr_block(name, input_signature, output_signature) +gr_sync_block::gr_sync_block(void) { - set_fixed_rate(true); + //NOP } - -void -gr_sync_block::forecast (int noutput_items, gr_vector_int &ninput_items_required) -{ - unsigned ninputs = ninput_items_required.size(); - for (unsigned i = 0; i < ninputs; i++) - ninput_items_required[i] = fixed_rate_noutput_to_ninput (noutput_items); -} - -int -gr_sync_block::fixed_rate_noutput_to_ninput(int noutput_items) +gr_sync_block::gr_sync_block( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +): + gr_block(name, input_signature, output_signature) { - return noutput_items + history() - 1; + this->set_fixed_rate(true); } -int -gr_sync_block::fixed_rate_ninput_to_noutput(int ninput_items) -{ - return std::max(0, ninput_items - (int)history() + 1); +int gr_sync_block::work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items +){ + throw std::runtime_error("gr_block subclasses must overload general_work!"); } -int -gr_sync_block::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - int r = work (noutput_items, input_items, output_items); - if (r > 0) - consume_each (r); - return r; +int gr_sync_block::general_work( + int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items +){ + const int work_ret = this->work(noutput_items, input_items, output_items); + if (work_ret > 0) + { + this->consume_each((decimation()*size_t(work_ret))/interpolation()); + } + return work_ret; } diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index 1e4109b03..d0ce95bca 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -1,66 +1,53 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#ifndef INCLUDED_GNURADIO_GR_SYNC_BLOCK_H +#define INCLUDED_GNURADIO_GR_SYNC_BLOCK_H -#ifndef INCLUDED_GR_SYNC_BLOCK_H -#define INCLUDED_GR_SYNC_BLOCK_H - -#include #include -/*! - * \brief synchronous 1:1 input to output with history - * \ingroup base_blk - * - * Override work to provide the signal processing implementation. - */ -class GR_CORE_API gr_sync_block : public gr_block +struct GR_CORE_API gr_sync_block : public gr_block { - protected: - gr_sync_block (void){} //allows pure virtual interface sub-classes - gr_sync_block (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature); - - public: - - /*! - * \brief just like gr_block::general_work, only this arranges to call consume_each for you - * - * The user must override work to define the signal processing code - */ - virtual int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) = 0; - - - // gr_sync_block overrides these to assist work - void forecast (int noutput_items, gr_vector_int &ninput_items_required); - int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + gr_sync_block(void); + + gr_sync_block( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature + ); + + //! implements work -> calls work + int general_work( + int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ); + + /*! + * \brief just like gr_block::general_work, only this arranges to call consume_each for you + * + * The user must override work to define the signal processing code + */ + virtual int work( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ); - int fixed_rate_ninput_to_noutput(int ninput); - int fixed_rate_noutput_to_ninput(int noutput); }; -#endif /* INCLUDED_GR_SYNC_BLOCK_H */ +#endif /*INCLUDED_GNURADIO_GR_SYNC_BLOCK_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc index a0f907db5..4574116bc 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc @@ -26,44 +26,18 @@ #include -gr_sync_decimator::gr_sync_decimator (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature, - unsigned decimation) - : gr_sync_block (name, input_signature, output_signature) +gr_sync_decimator::gr_sync_decimator(void) { - set_decimation (decimation); + //NOP } -void -gr_sync_decimator::forecast (int noutput_items, gr_vector_int &ninput_items_required) +gr_sync_decimator::gr_sync_decimator( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + const size_t decim_rate +): + gr_sync_block(name, input_signature, output_signature) { - unsigned ninputs = ninput_items_required.size (); - for (unsigned i = 0; i < ninputs; i++) - ninput_items_required[i] = fixed_rate_noutput_to_ninput(noutput_items); + this->set_decimation(decim_rate); } - -int -gr_sync_decimator::fixed_rate_noutput_to_ninput(int noutput_items) -{ - return noutput_items * decimation() + history() - 1; -} - -int -gr_sync_decimator::fixed_rate_ninput_to_noutput(int ninput_items) -{ - return std::max(0, ninput_items - (int)history() + 1) / decimation(); -} - -int -gr_sync_decimator::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - int r = work (noutput_items, input_items, output_items); - if (r > 0) - consume_each (r * decimation ()); - return r; -} - diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h index 657aba985..6f366037f 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -1,69 +1,36 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#ifndef INCLUDED_GNURADIO_GR_SYNC_DECIMATOR_H +#define INCLUDED_GNURADIO_GR_SYNC_DECIMATOR_H -#ifndef INCLUDED_GR_SYNC_DECIMATOR_H -#define INCLUDED_GR_SYNC_DECIMATOR_H - -#include #include -/*! - * \brief synchronous N:1 input to output with history - * \ingroup base_blk - * - * Override work to provide the signal processing implementation. - */ -class GR_CORE_API gr_sync_decimator : public gr_sync_block +struct GR_CORE_API gr_sync_decimator : gr_sync_block { - private: - unsigned d_decimation; - - protected: - gr_sync_decimator (void){} //allows pure virtual interface sub-classes - gr_sync_decimator (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature, - unsigned decimation); - public: - unsigned decimation () const { return d_decimation; } - void set_decimation (unsigned decimation) - { - d_decimation = decimation; - set_relative_rate (1.0 / decimation); - } + gr_sync_decimator(void); - // gr_sync_decimator overrides these to assist work - void forecast (int noutput_items, gr_vector_int &ninput_items_required); - int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + gr_sync_decimator( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + const size_t decim_rate + ); - // derived classes should override work - - int fixed_rate_ninput_to_noutput(int ninput); - int fixed_rate_noutput_to_ninput(int noutput); }; - -#endif /* INCLUDED_GR_SYNC_DECIMATOR_H */ +#endif /*INCLUDED_GNURADIO_GR_SYNC_DECIMATOR_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc index ece873c14..28a878eb2 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc @@ -26,45 +26,18 @@ #include -gr_sync_interpolator::gr_sync_interpolator (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature, - unsigned interpolation) - : gr_sync_block (name, input_signature, output_signature) +gr_sync_interpolator::gr_sync_interpolator(void) { - set_interpolation (interpolation); + //NOP } -void -gr_sync_interpolator::forecast (int noutput_items, gr_vector_int &ninput_items_required) +gr_sync_interpolator::gr_sync_interpolator( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + const size_t interp_rate +): + gr_sync_block(name, input_signature, output_signature) { - unsigned ninputs = ninput_items_required.size (); - for (unsigned i = 0; i < ninputs; i++) - ninput_items_required[i] = fixed_rate_noutput_to_ninput(noutput_items); + this->set_interpolation(interp_rate); } - -int -gr_sync_interpolator::fixed_rate_noutput_to_ninput(int noutput_items) -{ - return noutput_items / interpolation() + history() - 1; -} - -int -gr_sync_interpolator::fixed_rate_ninput_to_noutput(int ninput_items) -{ - return std::max(0, ninput_items - (int)history() + 1) * interpolation(); -} - -int -gr_sync_interpolator::general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - int r = work (noutput_items, input_items, output_items); - if (r > 0) - consume_each (r / interpolation ()); - return r; -} - - diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index 86d2fde43..485e5c101 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -1,70 +1,36 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#ifndef INCLUDED_GNURADIO_GR_SYNC_INTERPOLATOR_H +#define INCLUDED_GNURADIO_GR_SYNC_INTERPOLATOR_H -#ifndef INCLUDED_GR_SYNC_INTERPOLATOR_H -#define INCLUDED_GR_SYNC_INTERPOLATOR_H - -#include #include -/*! - * \brief synchronous 1:N input to output with history - * \ingroup base_blk - * - * Override work to provide the signal processing implementation. - */ -class GR_CORE_API gr_sync_interpolator : public gr_sync_block +struct GR_CORE_API gr_sync_interpolator : gr_sync_block { - private: - unsigned d_interpolation; - - protected: - gr_sync_interpolator (void){} //allows pure virtual interface sub-classes - gr_sync_interpolator (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature, - unsigned interpolation); - public: - unsigned interpolation () const { return d_interpolation; } - void set_interpolation (unsigned interpolation) - { - d_interpolation = interpolation; - set_relative_rate (1.0 * interpolation); - set_output_multiple (interpolation); - } + gr_sync_interpolator(void); - // gr_sync_interpolator overrides these to assist work - void forecast (int noutput_items, gr_vector_int &ninput_items_required); - int general_work (int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + gr_sync_interpolator( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature, + const size_t interp_rate + ); - // derived classes should override work - - int fixed_rate_ninput_to_noutput(int ninput); - int fixed_rate_noutput_to_ninput(int noutput); }; - -#endif /* INCLUDED_GR_SYNC_INTERPOLATOR_H */ +#endif /*INCLUDED_GNURADIO_GR_SYNC_INTERPOLATOR_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 04d1e95e5..0e033f7c1 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -1,133 +1,55 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_TOP_BLOCK_H -#define INCLUDED_GR_TOP_BLOCK_H +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#ifndef INCLUDED_GNURADIO_GR_TOP_BLOCK_H +#define INCLUDED_GNURADIO_GR_TOP_BLOCK_H #include +#include #include -class gr_top_block_impl; - -GR_CORE_API gr_top_block_sptr gr_make_top_block(const std::string &name); - -/*! - *\brief Top-level hierarchical block representing a flowgraph - * \ingroup container_blk - * - */ -class GR_CORE_API gr_top_block : public gr_hier_block2 +struct GR_CORE_API gr_top_block : gras::TopBlock { -private: - friend GR_CORE_API gr_top_block_sptr gr_make_top_block(const std::string &name); - - gr_top_block_impl *d_impl; - -protected: - gr_top_block(const std::string &name); - -public: - ~gr_top_block(); - - /*! - * \brief The simple interface to running a flowgraph. - * - * Calls start() then wait(). Used to run a flowgraph that will stop - * on its own, or when another thread will call stop(). - * - * \param max_noutput_items the maximum number of output items - * allowed for any block in the flowgraph. This passes through to - * the start function; see that function for more details. - */ - void run(int max_noutput_items=100000); - - /*! - * Start the contained flowgraph. Creates one or more threads to - * execute the flow graph. Returns to the caller once the threads - * are created. Calling start() on a top_block that is already - * started IS an error. - * - * \param max_noutput_items the maximum number of output items - * allowed for any block in the flowgraph; the noutput_items can - * always be less than this, but this will cap it as a maximum. Use - * this to adjust the maximum latency a flowgraph can exhibit. - */ - void start(int max_noutput_items=100000); - - /*! - * Stop the running flowgraph. Notifies each thread created by the - * scheduler to shutdown, then returns to caller. Calling stop() on - * a top_block that is already stopped IS NOT an error. - */ - void stop(); - /*! - * Wait for a flowgraph to complete. Flowgraphs complete when - * either (1) all blocks indicate that they are done (typically only - * when using gr.file_source, or gr.head, or (2) after stop() has been - * called to request shutdown. Calling wait on a top_block that is - * not running IS NOT an error (wait returns w/o blocking). - */ - void wait(); + gr_top_block(void); - /*! - * Lock a flowgraph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flowgraph - * will be reconfigured. - * - * N.B. lock() and unlock() may not be called from a flowgraph thread - * (E.g., gr_block::work method) or deadlock will occur when - * reconfiguration happens. - */ - virtual void lock(); + gr_top_block(const std::string &name); - /*! - * Unlock a flowgraph in preparation for reconfiguration. When an equal - * number of calls to lock() and unlock() have occurred, the flowgraph - * will be reconfigured. - * - * N.B. lock() and unlock() may not be called from a flowgraph thread - * (E.g., gr_block::work method) or deadlock will occur when - * reconfiguration happens. - */ - virtual void unlock(); - - /*! - * Displays flattened flowgraph edges and block connectivity - */ - void dump(); +}; - //! Get the number of max noutput_items in the flowgraph - int max_noutput_items(); +typedef boost::shared_ptr gr_top_block_sptr; - //! Set the maximum number of noutput_items in the flowgraph - void set_max_noutput_items(int nmax); +GR_CORE_API gr_top_block_sptr gr_make_top_block(const std::string &name); - gr_top_block_sptr to_top_block(); // Needed for Python type coercion -}; +inline gr_top_block::gr_top_block(void): + //cannot make a null top block, use name constructor + gras::TopBlock("top") +{ + //NOP +} -inline gr_top_block_sptr cast_to_top_block_sptr(gr_basic_block_sptr block) { - return boost::dynamic_pointer_cast(block); +inline gr_top_block::gr_top_block(const std::string &name): + gras::TopBlock(name) +{ + //NOP } +inline gr_top_block_sptr gr_make_top_block(const std::string &name) +{ + return gr_top_block_sptr(new gr_top_block(name)); +} -#endif /* INCLUDED_GR_TOP_BLOCK_H */ +#endif /*INCLUDED_GNURADIO_GR_TOP_BLOCK_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h index ad6cee768..7b25a6811 100644 --- a/gnuradio-core/src/lib/runtime/gr_types.h +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -1,64 +1,45 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . -#ifndef INCLUDED_GR_TYPES_H -#define INCLUDED_GR_TYPES_H +#ifndef INCLUDED_GRNURADIO_TYPES_H +#define INCLUDED_GRNURADIO_TYPES_H -#include -#include -#include -#include // size_t +// this section is to satisfy swig includes for gras.i +// since gras.i includes gr_types.h, we only have to edit this file +#include +#include +#include +#include +#include -#include +// and gnuradio apparently needs its own typedefs for stdint... +#ifdef __cplusplus -typedef std::vector gr_vector_int; -typedef std::vector gr_vector_float; -typedef std::vector gr_vector_double; -typedef std::vector gr_vector_void_star; -typedef std::vector gr_vector_const_void_star; +#include +typedef boost::int16_t gr_int16; +typedef boost::int32_t gr_int32; +typedef boost::int64_t gr_int64; +typedef boost::uint16_t gr_uint16; +typedef boost::uint32_t gr_uint32; +typedef boost::uint64_t gr_uint64; -/* - * #include must be placed beforehand - * in the source file including gr_types.h for - * the following to work correctly - */ -#ifdef HAVE_STDINT_H -#include -typedef int16_t gr_int16; -typedef int32_t gr_int32; -typedef int64_t gr_int64; -typedef uint16_t gr_uint16; -typedef uint32_t gr_uint32; -typedef uint64_t gr_uint64; -#else -/* - * Note: these defaults may be wrong on 64-bit systems - */ -typedef short gr_int16; -typedef int gr_int32; -typedef long long gr_int64; -typedef unsigned short gr_uint16; -typedef unsigned int gr_uint32; -typedef unsigned long long gr_uint64; -#endif /* HAVE_STDINT_H */ +#include +typedef std::complex gr_complex; +typedef std::complex gr_complexd; -#endif /* INCLUDED_GR_TYPES_H */ +#endif + +#endif /* INCLUDED_GRNURADIO_TYPES_H */ diff --git a/gnuradio-core/src/lib/runtime/pmx_helper.hpp b/gnuradio-core/src/lib/runtime/pmx_helper.hpp new file mode 100644 index 000000000..4178daa06 --- /dev/null +++ b/gnuradio-core/src/lib/runtime/pmx_helper.hpp @@ -0,0 +1,263 @@ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +#ifndef INCLUDED_LIBGRAS_PMX_HELPER_HPP +#define INCLUDED_LIBGRAS_PMX_HELPER_HPP + +#include +#include +#include +#include + +namespace pmt +{ + +inline pmt_t pmc_to_pmt(const PMCC &p) +{ + //the container is null + if (not p) return pmt::pmt_t(); + + #define decl_pmc_to_pmt(type, conv) if (p.is()) return conv(p.as()) + + //bool + decl_pmc_to_pmt(bool, pmt_from_bool); + + //string + decl_pmc_to_pmt(std::string, pmt_string_to_symbol); + + //numeric types + decl_pmc_to_pmt(int8_t, pmt_from_long); + decl_pmc_to_pmt(int16_t, pmt_from_long); + decl_pmc_to_pmt(int32_t, pmt_from_long); + decl_pmc_to_pmt(uint8_t, pmt_from_long); + decl_pmc_to_pmt(uint16_t, pmt_from_long); + decl_pmc_to_pmt(uint32_t, pmt_from_long); + decl_pmc_to_pmt(int64_t, pmt_from_uint64); + decl_pmc_to_pmt(uint64_t, pmt_from_uint64); + decl_pmc_to_pmt(float, pmt_from_double); + decl_pmc_to_pmt(double, pmt_from_double); + #define pmt_from_complex(x) pmt_make_rectangular((x).real(), (x).imag()) + decl_pmc_to_pmt(std::complex, pmt_from_complex); + decl_pmc_to_pmt(std::complex, pmt_from_complex); + + //pair container + if (p.is()) + { + const PMCPair &pr = p.as(); + return pmt_cons(pmc_to_pmt(pr.first), pmc_to_pmt(pr.second)); + } + + //fucking tuples +/* +for i in range(11): + args = list() + for j in range(i): + args.append('pmc_to_pmt(p.as >()[%d])'%(i, j)) + print ' if (p.is >())'%i + print ' return pmt_make_tuple(%s);'%(', '.join(args),) +*/ + if (p.is >()) + return pmt_make_tuple(); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0])); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1])); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2])); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3])); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4])); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5])); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5]), pmc_to_pmt(p.as >()[6])); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5]), pmc_to_pmt(p.as >()[6]), pmc_to_pmt(p.as >()[7])); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5]), pmc_to_pmt(p.as >()[6]), pmc_to_pmt(p.as >()[7]), pmc_to_pmt(p.as >()[8])); + if (p.is >()) + return pmt_make_tuple(pmc_to_pmt(p.as >()[0]), pmc_to_pmt(p.as >()[1]), pmc_to_pmt(p.as >()[2]), pmc_to_pmt(p.as >()[3]), pmc_to_pmt(p.as >()[4]), pmc_to_pmt(p.as >()[5]), pmc_to_pmt(p.as >()[6]), pmc_to_pmt(p.as >()[7]), pmc_to_pmt(p.as >()[8]), pmc_to_pmt(p.as >()[9])); + + //vector container + if (p.is()) + { + const PMCList &l = p.as(); + pmt_t v = pmt_make_vector(l.size(), pmt_t()); + for (size_t i = 0; i < l.size(); i++) + { + pmt_vector_set(v, i, pmc_to_pmt(l[i])); + } + return v; + } + + //numeric arrays + #define decl_pmc_to_pmt_numeric_array(type, suffix) \ + if (p.is >()) return pmt_init_ ## suffix ## vector(p.as >().size(), &p.as >()[0]) + decl_pmc_to_pmt_numeric_array(uint8_t, u8); + decl_pmc_to_pmt_numeric_array(uint16_t, u16); + decl_pmc_to_pmt_numeric_array(uint32_t, u32); + decl_pmc_to_pmt_numeric_array(uint64_t, u64); + decl_pmc_to_pmt_numeric_array(int8_t, s8); + decl_pmc_to_pmt_numeric_array(int16_t, s16); + decl_pmc_to_pmt_numeric_array(int32_t, s32); + decl_pmc_to_pmt_numeric_array(int64_t, s64); + decl_pmc_to_pmt_numeric_array(float, f32); + decl_pmc_to_pmt_numeric_array(double, f64); + decl_pmc_to_pmt_numeric_array(std::complex, c32); + decl_pmc_to_pmt_numeric_array(std::complex, c64); + + //dictionary container + if (p.is()) + { + const PMCDict &m = p.as(); + pmt_t d = pmt_make_dict(); + BOOST_FOREACH(const PMCPair &pr, m) + { + d = pmt_dict_add(d, pmc_to_pmt(pr.first), pmc_to_pmt(pr.second)); + } + return d; + } + + //set container + if (p.is()) + { + const PMCSet &s = p.as(); + pmt_t l = PMT_NIL; + BOOST_FOREACH(const PMCC &elem, s) + { + l = pmt_list_add(l, pmc_to_pmt(elem)); + } + return l; + } + + //is it already a pmt? + if (p.is()) return p.as(); + + //backup plan... boost::any + return pmt_make_any(p); + +} + +inline PMCC pmt_to_pmc(const pmt_t &p) +{ + //if the container null? + if (not p) return PMC(); + + #define decl_pmt_to_pmc(check, conv) if (check(p)) return PMC_M(conv(p)) + + //bool + decl_pmt_to_pmc(pmt_is_bool, pmt_to_bool); + + //string (do object interning for strings) + decl_pmt_to_pmc(pmt_is_symbol, pmt_symbol_to_string).intern(); + + //numeric types + decl_pmt_to_pmc(pmt_is_integer, pmt_to_long); + decl_pmt_to_pmc(pmt_is_uint64, pmt_to_uint64); + decl_pmt_to_pmc(pmt_is_real, pmt_to_double); + decl_pmt_to_pmc(pmt_is_complex, pmt_to_complex); + + //is it a boost any holding a PMCC? + if (pmt_is_any(p)) + { + const boost::any a = pmt_any_ref(p); + if (a.type() == typeid(PMCC)) return boost::any_cast(a); + } + + //pair container + if (pmt_is_pair(p)) + { + PMCPair pr(pmt_to_pmc(pmt_car(p)), pmt_to_pmc(pmt_cdr(p))); + return PMC_M(pr); + } + + //fucking tuples + #define decl_pmt_to_pmc_tuple(n) \ + if (pmt_is_tuple(p) and pmt_length(p) == n) \ + { \ + PMCTuple t; \ + for (size_t i = 0; i < n; i++) t[i] = pmt_to_pmc(pmt_tuple_ref(p, i)); \ + return PMC_M(t); \ + } + decl_pmt_to_pmc_tuple(0); + decl_pmt_to_pmc_tuple(1); + decl_pmt_to_pmc_tuple(2); + decl_pmt_to_pmc_tuple(3); + decl_pmt_to_pmc_tuple(4); + decl_pmt_to_pmc_tuple(5); + decl_pmt_to_pmc_tuple(6); + decl_pmt_to_pmc_tuple(7); + decl_pmt_to_pmc_tuple(8); + decl_pmt_to_pmc_tuple(9); + decl_pmt_to_pmc_tuple(10); + + //vector container + if (pmt_is_vector(p)) + { + PMCList l(pmt_length(p)); + for (size_t i = 0; i < l.size(); i++) + { + l[i] = pmt_to_pmc(pmt_vector_ref(p, i)); + } + return PMC_M(l); + } + + //numeric arrays + #define decl_pmt_to_pmc_numeric_array(type, suffix) \ + if (pmt_is_ ## suffix ## vector(p)) \ + { \ + size_t n; const type* i = pmt_ ## suffix ## vector_elements(p, n); \ + return PMC_M(std::vector(i, i+n)); \ + } + decl_pmt_to_pmc_numeric_array(uint8_t, u8); + decl_pmt_to_pmc_numeric_array(uint16_t, u16); + decl_pmt_to_pmc_numeric_array(uint32_t, u32); + decl_pmt_to_pmc_numeric_array(uint64_t, u64); + decl_pmt_to_pmc_numeric_array(int8_t, s8); + decl_pmt_to_pmc_numeric_array(int16_t, s16); + decl_pmt_to_pmc_numeric_array(int32_t, s32); + decl_pmt_to_pmc_numeric_array(int64_t, s64); + decl_pmt_to_pmc_numeric_array(float, f32); + decl_pmt_to_pmc_numeric_array(double, f64); + decl_pmt_to_pmc_numeric_array(std::complex, c32); + decl_pmt_to_pmc_numeric_array(std::complex, c64); + + //dictionary container + if (pmt_is_dict(p)) + { + PMCDict m; + pmt_t items = pmt_dict_items(p); + for (size_t i = 0; i < pmt_length(items); i++) + { + pmt_t item = pmt_nth(i, items); + PMCC key = pmt_to_pmc(pmt_car(item)); + PMCC val = pmt_to_pmc(pmt_cdr(item)); + m[key] = val; + } + return PMC_M(m); + } + + //set container + //FIXME no pmt_is_list... + + //backup plan... store the pmt + return PMC_M(p); +} + +} + +#endif /*INCLUDED_LIBGRAS_PMX_HELPER_HPP*/ diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc index 5e62c7991..9091d5c00 100644 --- a/gnuradio-core/src/lib/runtime/qa_runtime.cc +++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc @@ -49,13 +49,13 @@ qa_runtime::suite () s->addTest (qa_gr_vmcircbuf::suite ()); s->addTest (qa_gr_io_signature::suite ()); s->addTest (qa_gr_block::suite ()); - s->addTest (qa_gr_flowgraph::suite ()); + //s->addTest (qa_gr_flowgraph::suite ()); s->addTest (qa_gr_top_block::suite ()); s->addTest (qa_gr_hier_block2::suite ()); s->addTest (qa_gr_hier_block2_derived::suite ()); s->addTest (qa_gr_buffer::suite ()); - s->addTest (qa_block_tags::suite ()); - s->addTest (qa_set_msg_handler::suite ()); + //s->addTest (qa_block_tags::suite ()); + //s->addTest (qa_set_msg_handler::suite ()); return s; } diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 8e35df834..c8927f336 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -1,69 +1,88 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . #define GR_CORE_API +//not here to fight you swig, reference() is ambigi with shared ptr, but whatevs +%ignore gri_agc_cc::reference(); +%ignore gri_agc2_ff::reference(); +%ignore gri_agc2_cc::reference(); + %{ -#include + +#include +#include +#include +#include #include -#include #include -#include +#include #include -#include #include #include #include -#include -#include -#include #include #include #include -#include -%} -%constant int sizeof_char = sizeof(char); -%constant int sizeof_short = sizeof(short); -%constant int sizeof_int = sizeof(int); -%constant int sizeof_float = sizeof(float); -%constant int sizeof_double = sizeof(double); -%constant int sizeof_gr_complex = sizeof(gr_complex); +%} -%include -%include -%include -%include -%include -%include -%include -%include %include %include %include -%include -%include -%include -%include -%include -%include -%include +%include + +#ifdef SW_RUNTIME + +%rename(io_signature) gr_make_io_signature; +%rename(io_signature2) gr_make_io_signature2; +%rename(io_signature3) gr_make_io_signature3; +%rename(io_signaturev) gr_make_io_signaturev; + +//const size types used by blocks in python +%constant int sizeof_char = sizeof(char); +%constant int sizeof_short = sizeof(short); +%constant int sizeof_int = sizeof(int); +%constant int sizeof_float = sizeof(float); +%constant int sizeof_double = sizeof(double); +%constant int sizeof_gr_complex = sizeof(gr_complex); + +%import +%include +%include +%include +%include +%include +%include +%include + +#else + +//the bare minimum block inheritance interface to make things work but keep swig cxx file size down +%include +%include +namespace gras +{ + struct Block : gras::Element{}; + struct HierBlock : gras::Element{}; +} +struct gr_hier_block2 : gras::HierBlock{}; +struct gr_block : gras::Block{}; +struct gr_sync_block : gr_block{}; +struct gr_sync_interpolator : gr_sync_block{}; +struct gr_sync_decimator : gr_sync_block{}; + +#endif -- cgit From b383c4ec3fe6c5f2bbace2f529760b91b77122ef Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 13 Jan 2013 17:28:01 -0800 Subject: gras: fixed the misc issues w/ gr python block There was an bug in the get_tags_in_range impl, found incidentally. Just a little swig + python misc changes. --- gnuradio-core/src/lib/runtime/gr_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_io_signature.h | 3 +-- gnuradio-core/src/lib/runtime/runtime.i | 11 ++++++----- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 8032b29fc..63df6aa18 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -431,7 +431,7 @@ void gr_block::get_tags_in_range( if (tag.offset >= abs_start and tag.offset <= abs_end) { gr_tag_t t = Tag2gr_tag(tag); - if (key or pmt::pmt_equal(t.key, key)) tags.push_back(t); + if (not key or pmt::pmt_equal(t.key, key)) tags.push_back(t); } } } diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index 78b1502f0..4c1eec4e8 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -68,11 +68,10 @@ inline gr_io_signature_sptr gr_make_io_signature3( return io_sig; } -template inline gr_io_signature_sptr gr_make_io_signaturev( int min_streams, int max_streams, - const std::vector &sizeof_stream_items + const std::vector &sizeof_stream_items ){ gr_io_signature io_sig(min_streams, max_streams); for (unsigned i = 0; i < sizeof_stream_items.size(); i++) diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index c8927f336..4dff7fabe 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -40,18 +40,19 @@ %} +%rename(io_signature) gr_make_io_signature; +%rename(io_signature2) gr_make_io_signature2; +%rename(io_signature3) gr_make_io_signature3; +%rename(io_signaturev) gr_make_io_signaturev; + %include %include %include %include +%include #ifdef SW_RUNTIME -%rename(io_signature) gr_make_io_signature; -%rename(io_signature2) gr_make_io_signature2; -%rename(io_signature3) gr_make_io_signature3; -%rename(io_signaturev) gr_make_io_signaturev; - //const size types used by blocks in python %constant int sizeof_char = sizeof(char); %constant int sizeof_short = sizeof(short); -- cgit From f2bf6fbb5617f0d26654821fb1eb30bc2a1c16a2 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 7 Jan 2013 15:54:56 +0100 Subject: core: added operator == for tags --- gnuradio-core/src/lib/runtime/gr_tags.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_tags.h b/gnuradio-core/src/lib/runtime/gr_tags.h index 8bffcd0fe..a9ca90235 100644 --- a/gnuradio-core/src/lib/runtime/gr_tags.h +++ b/gnuradio-core/src/lib/runtime/gr_tags.h @@ -45,6 +45,11 @@ struct GR_CORE_API gr_tag_t{ ){ return x.offset < y.offset; } + + inline bool operator == (const gr_tag_t &t) const + { + return (t.key == key) && (t.value == value) && (t.srcid == srcid) && (t.offset == offset); + } }; #endif /*INCLUDED_GR_TAGS_H*/ -- cgit From f676197e6dd2a638f294e350654e32d3ffc45af8 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 7 Jan 2013 17:10:20 +0100 Subject: core: added remove_tag_item() --- gnuradio-core/src/lib/runtime/gr_block.cc | 7 +++++ gnuradio-core/src/lib/runtime/gr_block.h | 36 ++++++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 12 ++++++++ gnuradio-core/src/lib/runtime/gr_block_detail.h | 13 +++++++-- gnuradio-core/src/lib/runtime/gr_buffer.cc | 12 ++++++++ gnuradio-core/src/lib/runtime/gr_buffer.h | 9 ++++++ 6 files changed, 87 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 43aebf0bf..5ba30955f 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -186,6 +186,13 @@ gr_block::add_item_tag(unsigned int which_output, d_detail->add_item_tag(which_output, tag); } +void +gr_block::remove_item_tag(unsigned int which_input, + const gr_tag_t &tag) +{ + d_detail->remove_item_tag(which_input, tag); +} + void gr_block::get_tags_in_range(std::vector &v, unsigned int which_output, diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 57e3fda90..7a70bdaf0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -415,6 +415,42 @@ class GR_CORE_API gr_block : public gr_basic_block { */ void add_item_tag(unsigned int which_output, const gr_tag_t &tag); + /*! + * \brief Removes a tag from the given input buffer. + * + * \param which_input an integer of which input stream to remove the tag from + * \param abs_offset a uint64 number of the absolute item number + * assicated with the tag. Can get from nitems_written. + * \param key the tag key as a PMT symbol + * \param value any PMT holding any value for the given key + * \param srcid optional source ID specifier; defaults to PMT_F + * + * If no such tag is found, does nothing. + */ + inline void remove_item_tag(unsigned int which_input, + uint64_t abs_offset, + const pmt::pmt_t &key, + const pmt::pmt_t &value, + const pmt::pmt_t &srcid=pmt::PMT_F) + { + gr_tag_t tag; + tag.offset = abs_offset; + tag.key = key; + tag.value = value; + tag.srcid = srcid; + this->remove_item_tag(which_input, tag); + } + + /*! + * \brief Removes a tag from the given input buffer. + * + * If no such tag is found, does nothing. + * + * \param which_input an integer of which input stream to remove the tag from + * \param tag the tag object to remove + */ + void remove_item_tag(unsigned int which_input, const gr_tag_t &tag); + /*! * \brief Given a [start,end), returns a vector of all tags in the range. * diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 337c9518e..c65493473 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -155,6 +155,18 @@ gr_block_detail::add_item_tag(unsigned int which_output, const gr_tag_t &tag) } } +void +gr_block_detail::remove_item_tag(unsigned int which_input, const gr_tag_t &tag) +{ + if(!pmt_is_symbol(tag.key)) { + throw pmt_wrong_type("gr_block_detail::add_item_tag key", tag.key); + } + else { + // Add tag to gr_buffer's deque tags + d_input[which_input]->buffer()->remove_item_tag(tag); + } +} + void gr_block_detail::get_tags_in_range(std::vector &v, unsigned int which_input, diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 16d9f4d42..af00ea7c7 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -95,8 +95,7 @@ class GR_CORE_API gr_block_detail { /*! * \brief Adds a new tag to the given output stream. * - * This takes the input parameters and builds a PMT tuple - * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t), + * Calls gr_buffer::add_item_tag(), * which appends the tag onto its deque. * * \param which_output an integer of which output stream to attach the tag @@ -104,6 +103,16 @@ class GR_CORE_API gr_block_detail { */ void add_item_tag(unsigned int which_output, const gr_tag_t &tag); + /*! + * \brief Removes a tag from the given input stream. + * + * Calls gr_buffer::remove_item_tag(), which removes the tag from its deque. + * + * \param which_input an integer of which input stream to remove the tag from + * \param tag the tag object to add + */ + void remove_item_tag(unsigned int which_input, const gr_tag_t &tag); + /*! * \brief Given a [start,end), returns a vector of all tags in the range. * diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index b923ca57a..369959d65 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -233,6 +233,18 @@ gr_buffer::add_item_tag(const gr_tag_t &tag) d_item_tags.push_back(tag); } +void +gr_buffer::remove_item_tag(const gr_tag_t &tag) +{ + gruel::scoped_lock guard(*mutex()); + for (std::deque::iterator it = d_item_tags.begin(); it != d_item_tags.end(); ++it) { + if (*it == tag) { + d_item_tags.erase(it); + break; + } + } +} + void gr_buffer::prune_tags(uint64_t max_time) { diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index 67d48fb2d..28ea97726 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -102,6 +102,15 @@ class GR_CORE_API gr_buffer { */ void add_item_tag(const gr_tag_t &tag); + /*! + * \brief Removes an existing tag from the buffer. + * + * If no such tag is found, does nothing. + * + * \param tag the tag that needs to be removed + */ + void remove_item_tag(const gr_tag_t &tag); + /*! * \brief Removes all tags before \p max_time from buffer * -- cgit From 97ff82dd63f06ad51992222c160a9673260b13f7 Mon Sep 17 00:00:00 2001 From: Ben Reynwar Date: Tue, 22 Jan 2013 12:46:01 -0700 Subject: core: Add min_noutput_items to gr_block. --- gnuradio-core/src/lib/runtime/gr_block.cc | 5 ++-- gnuradio-core/src/lib/runtime/gr_block.h | 20 ++++++++++++++- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 29 +++++++++++----------- 3 files changed, 36 insertions(+), 18 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 5ba30955f..b39a680c5 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -31,8 +31,8 @@ #include gr_block::gr_block (const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature) + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature) : gr_basic_block(name, input_signature, output_signature), d_output_multiple (1), d_output_multiple_set(false), @@ -43,6 +43,7 @@ gr_block::gr_block (const std::string &name, d_fixed_rate(false), d_max_noutput_items_set(false), d_max_noutput_items(0), + d_min_noutput_items(0), d_tag_propagation_policy(TPP_ALL_TO_ALL), d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 7a70bdaf0..52cf723a9 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -251,6 +251,23 @@ class GR_CORE_API gr_block : public gr_basic_block { */ void set_tag_propagation_policy(tag_propagation_policy_t p); + /*! + * \brief Return the minimum number of output items this block can + * produce during a call to work. + * + * Should be 0 for most blocks. Useful if we're dealing with packets and + * the block produces one packet per call to work. + */ + int min_noutput_items() const { return d_min_noutput_items; } + + /*! + * \brief Set the minimum number of output items this block can + * produce during a call to work. + * + * \param m the minimum noutput_items this block can produce. + */ + void set_min_noutput_items(int m) { d_min_noutput_items = m; } + /*! * \brief Return the maximum number of output items this block will * handle during a call to work. @@ -258,7 +275,7 @@ class GR_CORE_API gr_block : public gr_basic_block { int max_noutput_items(); /*! - * \brief Set the maximum number of ouput items htis block will + * \brief Set the maximum number of output items this block will * handle during a call to work. * * \param m the maximum noutput_items this block will handle. @@ -370,6 +387,7 @@ class GR_CORE_API gr_block : public gr_basic_block { gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; + int d_min_noutput_items; bool d_max_noutput_items_set; // if d_max_noutput_items is valid int d_max_noutput_items; // value of max_noutput_items for this block tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 375b58f56..8aadb201a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -64,22 +64,21 @@ round_down (unsigned int n, unsigned int multiple) // on is done. // static int -min_available_space (gr_block_detail *d, int output_multiple) +min_available_space (gr_block_detail *d, int output_multiple, int min_noutput_items) { - int min_space = std::numeric_limits::max(); - + int min_space = std::numeric_limits::max(); + if (min_noutput_items == 0) + min_noutput_items = 1; for (int i = 0; i < d->noutputs (); i++){ gruel::scoped_lock guard(*d->output(i)->mutex()); -#if 0 - int n = round_down(d->output(i)->space_available(), output_multiple); -#else - int n = round_down(std::min(d->output(i)->space_available(), - d->output(i)->bufsize()/2), - output_multiple); -#endif - if (n == 0){ // We're blocked on output. - if (d->output(i)->done()){ // Downstream is done, therefore we're done. - return -1; + int avail_n = round_down(d->output(i)->space_available(), output_multiple); + int best_n = round_down(d->output(i)->bufsize()/2, output_multiple); + if (best_n < min_noutput_items) + throw std::runtime_error("Buffer too small for min_noutput_items"); + int n = std::min(avail_n, best_n); + if (n < min_noutput_items){ // We're blocked on output. + if (d->output(i)->done()){ // Downstream is done, therefore we're done. + return -1; } return 0; } @@ -205,7 +204,7 @@ gr_block_executor::run_one_iteration() d_start_nitems_read.resize(0); // determine the minimum available output space - noutput_items = min_available_space (d, m->output_multiple ()); + noutput_items = min_available_space (d, m->output_multiple (), m->min_noutput_items ()); noutput_items = std::min(noutput_items, max_noutput_items); LOG(*d_log << " source\n noutput_items = " << noutput_items << std::endl); if (noutput_items == -1) // we're done @@ -286,7 +285,7 @@ gr_block_executor::run_one_iteration() } // determine the minimum available output space - noutput_items = min_available_space (d, m->output_multiple ()); + noutput_items = min_available_space (d, m->output_multiple (), m->min_noutput_items ()); if (ENABLE_LOGGING){ *d_log << " regular "; if (m->relative_rate() >= 1.0) -- cgit From 5ab960295f00991fa9447819b3ff9eaf8d88d28e Mon Sep 17 00:00:00 2001 From: Roy Thompson Date: Thu, 31 Jan 2013 13:16:12 -0700 Subject: core: Enabling msg_connect within python blocks. --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 9cc2ad775..b4935d8ac 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -54,18 +54,6 @@ class GR_CORE_API gr_basic_block : public gr_msg_accepter, public boost::enable_ typedef boost::function msg_handler_t; private: - /* - * This function is called by the runtime system to dispatch messages. - * - * The thread-safety guarantees mentioned in set_msg_handler are implemented - * by the callers of this method. - */ - void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) - { - // AA Update this - if (d_msg_handlers.find(which_port) != d_msg_handlers.end()) // Is there a handler? - d_msg_handlers[which_port](msg); // Yes, invoke it. - }; //msg_handler_t d_msg_handler; typedef std::map d_msg_handlers_t; @@ -117,6 +105,19 @@ class GR_CORE_API gr_basic_block : public gr_msg_accepter, public boost::enable_ */ void set_color(vcolor color) { d_color = color; } vcolor color() const { return d_color; } + + /* + * This function is called by the runtime system to dispatch messages. + * + * The thread-safety guarantees mentioned in set_msg_handler are implemented + * by the callers of this method. + */ + virtual void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) + { + // AA Update this + if (d_msg_handlers.find(which_port) != d_msg_handlers.end()) // Is there a handler? + d_msg_handlers[which_port](msg); // Yes, invoke it. + }; // Message passing interface pmt::pmt_t message_subscribers; -- cgit From 01eab0c7e283db9c1cfff0a26296a49128062cca Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 19 Dec 2012 13:38:24 -0500 Subject: core: working thread affinity concept into gr_blocks. Example in gnuradio-core/src/examples/mp-sched/affinity_set.py Documentation describing API in docs/doxygen/other/thread_affinity.dox --- gnuradio-core/src/lib/runtime/gr_block.cc | 18 ++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 21 +++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block.i | 5 +++++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 21 +++++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block_detail.h | 14 ++++++++++++++ gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc | 7 +++++++ 6 files changed, 86 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 5ba30955f..dca1fcf83 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -251,6 +251,24 @@ gr_block::is_set_max_noutput_items() return d_max_noutput_items_set; } +void +gr_block::set_processor_affinity(const std::vector &mask) +{ + d_affinity = mask; + if(d_detail) { + d_detail->set_processor_affinity(d_affinity); + } +} + +void +gr_block::unset_processor_affinity() +{ + d_affinity.clear(); + if(d_detail) { + d_detail->unset_processor_affinity(); + } +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 7a70bdaf0..9906d3632 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -359,6 +359,26 @@ class GR_CORE_API gr_block : public gr_basic_block { } // ---------------------------------------------------------------------------- + // Functions to handle thread affinity + + /*! + * \brief Set the thread's affinity to processor core \p n. + * + * \param mask a vector of unsigned ints of the core numbers available to this block. + */ + void set_processor_affinity(const std::vector &mask); + + /*! + * \brief Remove processor affinity to a specific core. + */ + void unset_processor_affinity(); + + /*! + * \brief Get the current processor affinity. + */ + std::vector processor_affinity() { return d_affinity; } + + // ---------------------------------------------------------------------------- private: @@ -373,6 +393,7 @@ class GR_CORE_API gr_block : public gr_basic_block { bool d_max_noutput_items_set; // if d_max_noutput_items is valid int d_max_noutput_items; // value of max_noutput_items for this block tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream + std::vector d_affinity; // thread affinity proc. mask protected: gr_block (void){} //allows pure virtual interface sub-classes diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index db6c1d04a..89685d41f 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -66,6 +66,11 @@ class gr_block : public gr_basic_block { void set_min_output_buffer(long min_output_buffer); void set_min_output_buffer(int port, long min_output_buffer); + // Methods to manage processor affinity. + void set_processor_affinity(const std::vector &mask); + void unset_processor_affinity(); + std::vector processor_affinity(); + // internal use gr_block_detail_sptr detail () const { return d_detail; } void set_detail (gr_block_detail_sptr detail) { d_detail = detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index c65493473..e6199be37 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -201,3 +201,24 @@ gr_block_detail::get_tags_in_range(std::vector &v, } } } + +void +gr_block_detail::set_processor_affinity(const std::vector &mask) +{ + if(threaded) { + try { + gruel::thread_bind_to_processor(thread, mask); + } + catch (std::runtime_error e) { + std::cerr << "set_processor_affinity: invalid mask." << std::endl;; + } + } +} + +void +gr_block_detail::unset_processor_affinity() +{ + if(threaded) { + gruel::thread_unbind(thread); + } +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index af00ea7c7..bcc42c7a0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -155,6 +155,20 @@ class GR_CORE_API gr_block_detail { uint64_t abs_end, const pmt::pmt_t &key); + /*! + * \brief Set core affinity of block to the cores in the vector mask. + * + * \param mask a vector of unsigned ints of the core numbers available to this block. + */ + void set_processor_affinity(const std::vector &mask); + + /*! + * \brief Unset core affinity. + */ + void unset_processor_affinity(); + + bool threaded; // set if thread is currently running. + gruel::gr_thread_t thread; // portable thread handle gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index 9f17a48a8..cea374fac 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -38,6 +38,13 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item gr_block_executor::state s; pmt_t msg; + d->threaded = true; + d->thread = gruel::get_current_thread_id(); + + // Set thread affinity if it was set before fg was started. + if(block->processor_affinity().size() > 0) { + gruel::thread_bind_to_processor(d->thread, block->processor_affinity()); + } while (1){ boost::this_thread::interruption_point(); -- cgit From 256b438259469ff9ab58572c73f6444c79c24f1c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 19 Dec 2012 14:38:22 -0500 Subject: QA: adding a test to make sure the set_processor_affinity calls work and top_block starts correctly. --- gnuradio-core/src/lib/runtime/qa_gr_top_block.cc | 21 +++++++++++++++++++++ gnuradio-core/src/lib/runtime/qa_gr_top_block.h | 7 +++++++ 2 files changed, 28 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc index a0b4755a8..1d3dafadf 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc @@ -262,3 +262,24 @@ void qa_gr_top_block::t10_reconfig_max_output_buffer() // Wait for flowgraph to end on its own tb->wait(); } + +void qa_gr_top_block::t11_set_block_affinity() +{ + gr_top_block_sptr tb = gr_make_top_block("top"); + gr_block_sptr src (gr_make_null_source(sizeof(float))); + gr_block_sptr snk (gr_make_null_sink(sizeof(float))); + + std::vector set(1, 0), ret; + src->set_processor_affinity(set); + + tb->connect(src, 0, snk, 0); + tb->start(); + tb->stop(); + tb->wait(); + + ret = src->processor_affinity(); + + // We only set the core affinity to 0 because we always know at + // least one thread core exists to use. + CPPUNIT_ASSERT_EQUAL(set[0], ret[0]); +} diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h index bb891abca..634eeab1f 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.h @@ -38,6 +38,11 @@ class qa_gr_top_block : public CppUnit::TestCase CPPUNIT_TEST(t4_reconfigure); // triggers 'join never returns' bug CPPUNIT_TEST(t5_max_noutputs); CPPUNIT_TEST(t6_reconfig_max_noutputs); + CPPUNIT_TEST(t7_max_noutputs_per_block); + CPPUNIT_TEST(t8_reconfig_max_noutputs_per_block); + CPPUNIT_TEST(t9_max_output_buffer); + CPPUNIT_TEST(t10_reconfig_max_output_buffer); + CPPUNIT_TEST(t11_set_block_affinity); CPPUNIT_TEST_SUITE_END(); @@ -54,6 +59,8 @@ private: void t8_reconfig_max_noutputs_per_block(); void t9_max_output_buffer(); void t10_reconfig_max_output_buffer(); + void t11_set_block_affinity(); + }; #endif /* INCLUDED_QA_GR_TOP_BLOCK_H */ -- cgit From 0c46b36ed5c52f0003f0cd45195bdee1193a2a33 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Wed, 6 Feb 2013 12:36:13 -0800 Subject: gruel: renamed mask to dword_mask --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index e6199be37..fdcde85a0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -26,6 +26,7 @@ #include #include +#include using namespace pmt; -- cgit From 8b425118da3a09e490486b83a91208d2530d9897 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 25 Jan 2013 16:35:26 -0500 Subject: sched: adding in perf counters to measure performance of blocks during exectution of flowgraph. Conflicts: CMakeLists.txt gnuradio-core/src/lib/runtime/gr_block.cc gnuradio-core/src/lib/runtime/gr_block_detail.cc gnuradio-core/src/lib/runtime/gr_block_detail.h --- gnuradio-core/src/lib/runtime/gr_block.cc | 77 +++++++++++++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 38 ++++++++++ gnuradio-core/src/lib/runtime/gr_block_detail.cc | 86 +++++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_block_detail.h | 22 ++++++ gnuradio-core/src/lib/runtime/gr_block_executor.cc | 9 +++ 5 files changed, 231 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index dca1fcf83..fd82ab580 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -269,6 +269,83 @@ gr_block::unset_processor_affinity() } } +float +gr_block::pc_noutput_items() +{ + if(d_detail) { + return d_detail->pc_noutput_items(); + } + else { + return 0; + } +} + +float +gr_block::pc_nproduced() +{ + if(d_detail) { + return d_detail->pc_nproduced(); + } + else { + return 0; + } +} + +float +gr_block::pc_input_buffers_full(int which) +{ + if(d_detail) { + return d_detail->pc_input_buffers_full(static_cast(which)); + } + else { + return 0; + } +} + +std::vector +gr_block::pc_input_buffers_full() +{ + if(d_detail) { + return d_detail->pc_input_buffers_full(); + } + else { + return std::vector(1,0); + } +} + +float +gr_block::pc_output_buffers_full(int which) +{ + if(d_detail) { + return d_detail->pc_output_buffers_full(static_cast(which)); + } + else { + return 0; + } +} + +std::vector +gr_block::pc_output_buffers_full() +{ + if(d_detail) { + return d_detail->pc_output_buffers_full(); + } + else { + return std::vector(1,0); + } +} + +float +gr_block::pc_work_time() +{ + if(d_detail) { + return d_detail->pc_work_time(); + } + else { + return 0; + } +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 9906d3632..c9d2d8f53 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -358,6 +358,44 @@ class GR_CORE_API gr_block : public gr_basic_block { d_min_output_buffer[port] = min_output_buffer; } + // --------------- Performance counter functions ------------- + + /*! + * \brief Gets average noutput_items performance counter. + */ + float pc_noutput_items(); + + /*! + * \brief Gets average num items produced performance counter. + */ + float pc_nproduced(); + + /*! + * \brief Gets average average fullness of \p which input buffer. + */ + float pc_input_buffers_full(int which); + + /*! + * \brief Gets average fullness of all input buffers. + */ + std::vector pc_input_buffers_full(); + + /*! + * \brief Gets average fullness of \p which input buffer. + */ + float pc_output_buffers_full(int which); + + /*! + * \brief Gets average fullness of all output buffers. + */ + std::vector pc_output_buffers_full(); + + /*! + * \brief Gets average clock cycles spent in work. + */ + float pc_work_time(); + + // ---------------------------------------------------------------------------- // Functions to handle thread affinity diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index fdcde85a0..ff20e0e85 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -42,7 +42,11 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) : d_produce_or(0), d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), - d_done (false) + d_done (false), + d_avg_noutput_items(0), d_avg_nproduced(0), + d_avg_input_buffers_full(ninputs, 0), + d_avg_output_buffers_full(noutputs, 0), + d_avg_work_time(0) { s_ncurrently_allocated++; } @@ -223,3 +227,83 @@ gr_block_detail::unset_processor_affinity() gruel::thread_unbind(thread); } } + +void +gr_block_detail::start_perf_counters() +{ + d_start_of_work = gruel::high_res_timer_now(); +} + +void +gr_block_detail::stop_perf_counters(int noutput_items, int nproduced) +{ + float alpha = 0.05; + float beta = 1.0-alpha; + + d_end_of_work = gruel::high_res_timer_now(); + gruel::high_res_timer_type diff = d_end_of_work - d_start_of_work; + d_avg_work_time = beta*d_avg_work_time + alpha*diff; + + d_avg_nproduced = beta*d_avg_nproduced + alpha*nproduced; + d_avg_noutput_items = beta*d_avg_noutput_items + alpha*noutput_items; + + for(size_t i=0; i < d_input.size(); i++) { + float pfull = static_cast(d_input[i]->items_available()) / + static_cast(d_input[i]->max_possible_items_available()); + d_avg_input_buffers_full[i] = beta*d_avg_input_buffers_full[i] + alpha*pfull; + } + + for(size_t i=0; i < d_output.size(); i++) { + float pfull = 1.0f - static_cast(d_output[i]->space_available()) / + static_cast(d_output[i]->bufsize()); + d_avg_output_buffers_full[i] = beta*d_avg_output_buffers_full[i] + alpha*pfull; + } +} + +float +gr_block_detail::pc_noutput_items() +{ + return d_avg_noutput_items; +} + +float +gr_block_detail::pc_nproduced() +{ + return d_avg_nproduced; +} + +float +gr_block_detail::pc_input_buffers_full(size_t which) +{ + if(which < d_avg_input_buffers_full.size()) + return d_avg_input_buffers_full[which]; + else + return 0; +} + +std::vector +gr_block_detail::pc_input_buffers_full() +{ + return d_avg_input_buffers_full; +} + +float +gr_block_detail::pc_output_buffers_full(size_t which) +{ + if(which < d_avg_output_buffers_full.size()) + return d_avg_output_buffers_full[which]; + else + return 0; +} + +std::vector +gr_block_detail::pc_output_buffers_full() +{ + return d_avg_output_buffers_full; +} + +float +gr_block_detail::pc_work_time() +{ + return d_avg_work_time; +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index bcc42c7a0..a8ed8da90 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -27,6 +27,7 @@ #include #include #include +#include #include /*! @@ -169,6 +170,19 @@ class GR_CORE_API gr_block_detail { bool threaded; // set if thread is currently running. gruel::gr_thread_t thread; // portable thread handle + + void start_perf_counters(); + void stop_perf_counters(int noutput_items, int nproduced); + + // Calls to get performance counter items + float pc_noutput_items(); + float pc_nproduced(); + float pc_input_buffers_full(size_t which); + std::vector pc_input_buffers_full(); + float pc_output_buffers_full(size_t which); + std::vector pc_output_buffers_full(); + float pc_work_time(); + gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -181,6 +195,14 @@ class GR_CORE_API gr_block_detail { std::vector d_output; bool d_done; + // Performance counters + float d_avg_noutput_items; + float d_avg_nproduced; + std::vector d_avg_input_buffers_full; + std::vector d_avg_output_buffers_full; + gruel::high_res_timer_type d_start_of_work, d_end_of_work; + float d_avg_work_time; + gr_block_detail (unsigned int ninputs, unsigned int noutputs); friend struct gr_tpb_detail; diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 375b58f56..ee0ab9e37 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -420,9 +420,18 @@ gr_block_executor::run_one_iteration() for (int i = 0; i < d->ninputs(); i++) d_start_nitems_read[i] = d->nitems_read(i); +#ifdef GR_PERFORMANCE_COUNTERS + d->start_perf_counters(); +#endif /* GR_PERFORMANCE_COUNTERS */ + // Do the actual work of the block int n = m->general_work (noutput_items, d_ninput_items, d_input_items, d_output_items); + +#ifdef GR_PERFORMANCE_COUNTERS + d->stop_perf_counters(noutput_items, n); +#endif /* GR_PERFORMANCE_COUNTERS */ + LOG(*d_log << " general_work: noutput_items = " << noutput_items << " result = " << n << std::endl); -- cgit From f5d6f054a2a8c460ab0f4d41d44b8a0f0995d2aa Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 7 Feb 2013 17:05:28 -0500 Subject: sched: swiging perf counters into Python. --- gnuradio-core/src/lib/runtime/gr_block.i | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index 89685d41f..0a2fb61f4 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -66,6 +66,15 @@ class gr_block : public gr_basic_block { void set_min_output_buffer(long min_output_buffer); void set_min_output_buffer(int port, long min_output_buffer); + // Methods to access performance counters + float pc_noutput_items(); + float pc_nproduced(); + float pc_input_buffers_full(int which); + std::vector pc_input_buffers_full(); + float pc_output_buffers_full(int which); + std::vector pc_output_buffers_full(); + float pc_work_time(); + // Methods to manage processor affinity. void set_processor_affinity(const std::vector &mask); void unset_processor_affinity(); -- cgit From 37f297f892b9f1248915e119119a6ba3237f571f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 12 Feb 2013 18:21:13 -0500 Subject: core: typedef vector so SWIG can handle including it multiple times. --- gnuradio-core/src/lib/runtime/gr_block.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_types.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index 0a2fb61f4..c016f2c28 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -76,9 +76,9 @@ class gr_block : public gr_basic_block { float pc_work_time(); // Methods to manage processor affinity. - void set_processor_affinity(const std::vector &mask); + void set_processor_affinity(const gr_vector_uint &mask); void unset_processor_affinity(); - std::vector processor_affinity(); + gr_vector_uint processor_affinity(); // internal use gr_block_detail_sptr detail () const { return d_detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h index ad6cee768..db13e456a 100644 --- a/gnuradio-core/src/lib/runtime/gr_types.h +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -31,6 +31,7 @@ #include typedef std::vector gr_vector_int; +typedef std::vector gr_vector_uint; typedef std::vector gr_vector_float; typedef std::vector gr_vector_double; typedef std::vector gr_vector_void_star; -- cgit From dc4bb4a2dcab344c5e397686fd43c5e98b85ba72 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Wed, 13 Feb 2013 11:28:48 -0500 Subject: core: adding necessary include to gr_block_registry.h --- gnuradio-core/src/lib/runtime/gr_block_registry.h | 1 + 1 file changed, 1 insertion(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_registry.h b/gnuradio-core/src/lib/runtime/gr_block_registry.h index 6a2d939e5..3a9d9868f 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_registry.h +++ b/gnuradio-core/src/lib/runtime/gr_block_registry.h @@ -2,6 +2,7 @@ #define GR_BLOCK_REGISTRY_H #include +#include #ifndef GR_BASIC_BLOCK_H class gr_basic_block; -- cgit From d1735360bc7bfb04be56f2b255a0b84b4db31b84 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 15 Feb 2013 16:24:39 -0500 Subject: core: adding variance calcs to perf. counters. Using running mean/variance algorithm from Knuth's Art of Computer Programming. --- gnuradio-core/src/lib/runtime/gr_block.cc | 85 ++++++++++++++ gnuradio-core/src/lib/runtime/gr_block.h | 41 ++++++- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 137 ++++++++++++++++++++--- gnuradio-core/src/lib/runtime/gr_block_detail.h | 15 +++ 4 files changed, 260 insertions(+), 18 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index f52f7a6ba..54d267620 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -281,6 +281,17 @@ gr_block::pc_noutput_items() } } +float +gr_block::pc_noutput_items_var() +{ + if(d_detail) { + return d_detail->pc_noutput_items_var(); + } + else { + return 0; + } +} + float gr_block::pc_nproduced() { @@ -292,6 +303,17 @@ gr_block::pc_nproduced() } } +float +gr_block::pc_nproduced_var() +{ + if(d_detail) { + return d_detail->pc_nproduced_var(); + } + else { + return 0; + } +} + float gr_block::pc_input_buffers_full(int which) { @@ -303,6 +325,17 @@ gr_block::pc_input_buffers_full(int which) } } +float +gr_block::pc_input_buffers_full_var(int which) +{ + if(d_detail) { + return d_detail->pc_input_buffers_full_var(static_cast(which)); + } + else { + return 0; + } +} + std::vector gr_block::pc_input_buffers_full() { @@ -314,6 +347,17 @@ gr_block::pc_input_buffers_full() } } +std::vector +gr_block::pc_input_buffers_full_var() +{ + if(d_detail) { + return d_detail->pc_input_buffers_full_var(); + } + else { + return std::vector(1,0); + } +} + float gr_block::pc_output_buffers_full(int which) { @@ -325,6 +369,17 @@ gr_block::pc_output_buffers_full(int which) } } +float +gr_block::pc_output_buffers_full_var(int which) +{ + if(d_detail) { + return d_detail->pc_output_buffers_full_var(static_cast(which)); + } + else { + return 0; + } +} + std::vector gr_block::pc_output_buffers_full() { @@ -336,6 +391,17 @@ gr_block::pc_output_buffers_full() } } +std::vector +gr_block::pc_output_buffers_full_var() +{ + if(d_detail) { + return d_detail->pc_output_buffers_full_var(); + } + else { + return std::vector(1,0); + } +} + float gr_block::pc_work_time() { @@ -347,6 +413,25 @@ gr_block::pc_work_time() } } +float +gr_block::pc_work_time_var() +{ + if(d_detail) { + return d_detail->pc_work_time_var(); + } + else { + return 0; + } +} + +void +gr_block::reset_perf_counters() +{ + if(d_detail) { + d_detail->reset_perf_counters(); + } +} + std::ostream& operator << (std::ostream& os, const gr_block *m) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index bd9ff42df..6e21d5b97 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -382,36 +382,75 @@ class GR_CORE_API gr_block : public gr_basic_block { */ float pc_noutput_items(); + /*! + * \brief Gets variance of noutput_items performance counter. + */ + float pc_noutput_items_var(); + /*! * \brief Gets average num items produced performance counter. */ float pc_nproduced(); /*! - * \brief Gets average average fullness of \p which input buffer. + * \brief Gets variance of num items produced performance counter. + */ + float pc_nproduced_var(); + + /*! + * \brief Gets average fullness of \p which input buffer. */ float pc_input_buffers_full(int which); + /*! + * \brief Gets variance of fullness of \p which input buffer. + */ + float pc_input_buffers_full_var(int which); + /*! * \brief Gets average fullness of all input buffers. */ std::vector pc_input_buffers_full(); + /*! + * \brief Gets variance of fullness of all input buffers. + */ + std::vector pc_input_buffers_full_var(); + /*! * \brief Gets average fullness of \p which input buffer. */ float pc_output_buffers_full(int which); + /*! + * \brief Gets variance of fullness of \p which input buffer. + */ + float pc_output_buffers_full_var(int which); + /*! * \brief Gets average fullness of all output buffers. */ std::vector pc_output_buffers_full(); + /*! + * \brief Gets variance of fullness of all output buffers. + */ + std::vector pc_output_buffers_full_var(); /*! * \brief Gets average clock cycles spent in work. */ float pc_work_time(); + /*! + * \brief Gets average clock cycles spent in work. + */ + float pc_work_time_var(); + + /*! + * \brief Resets the performance counters + */ + void reset_perf_counters(); + // ---------------------------------------------------------------------------- // Functions to handle thread affinity diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index ff20e0e85..82081039a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -43,10 +43,17 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs) d_ninputs (ninputs), d_noutputs (noutputs), d_input (ninputs), d_output (noutputs), d_done (false), - d_avg_noutput_items(0), d_avg_nproduced(0), + d_avg_noutput_items(0), + d_var_noutput_items(0), + d_avg_nproduced(0), + d_var_nproduced(0), d_avg_input_buffers_full(ninputs, 0), + d_var_input_buffers_full(ninputs, 0), d_avg_output_buffers_full(noutputs, 0), - d_avg_work_time(0) + d_var_output_buffers_full(noutputs, 0), + d_avg_work_time(0), + d_var_work_time(0), + d_pc_counter(0) { s_ncurrently_allocated++; } @@ -237,27 +244,68 @@ gr_block_detail::start_perf_counters() void gr_block_detail::stop_perf_counters(int noutput_items, int nproduced) { - float alpha = 0.05; - float beta = 1.0-alpha; - d_end_of_work = gruel::high_res_timer_now(); gruel::high_res_timer_type diff = d_end_of_work - d_start_of_work; - d_avg_work_time = beta*d_avg_work_time + alpha*diff; - - d_avg_nproduced = beta*d_avg_nproduced + alpha*nproduced; - d_avg_noutput_items = beta*d_avg_noutput_items + alpha*noutput_items; - for(size_t i=0; i < d_input.size(); i++) { - float pfull = static_cast(d_input[i]->items_available()) / - static_cast(d_input[i]->max_possible_items_available()); - d_avg_input_buffers_full[i] = beta*d_avg_input_buffers_full[i] + alpha*pfull; + if(d_pc_counter == 0) { + d_avg_work_time = diff; + d_var_work_time = 0; + d_avg_nproduced = nproduced; + d_var_nproduced = 0; + d_avg_noutput_items = noutput_items; + d_var_noutput_items = 0; + for(size_t i=0; i < d_input.size(); i++) { + float pfull = static_cast(d_input[i]->items_available()) / + static_cast(d_input[i]->max_possible_items_available()); + d_avg_input_buffers_full[i] = pfull; + d_var_input_buffers_full[i] = 0; + } + for(size_t i=0; i < d_output.size(); i++) { + float pfull = 1.0f - static_cast(d_output[i]->space_available()) / + static_cast(d_output[i]->bufsize()); + d_avg_output_buffers_full[i] = pfull; + d_var_output_buffers_full[i] = 0; + } } + else { + float d = diff - d_avg_work_time; + d_avg_work_time = d_avg_work_time + d/d_pc_counter; + d_var_work_time = d_var_work_time + d*d; + + d = nproduced - d_avg_nproduced; + d_avg_nproduced = d_avg_nproduced + d/d_pc_counter; + d_var_nproduced = d_var_nproduced + d*d; + + d = noutput_items - d_avg_noutput_items; + d_avg_noutput_items = d_avg_noutput_items + d/d_pc_counter; + d_var_noutput_items = d_var_noutput_items + d*d; + + for(size_t i=0; i < d_input.size(); i++) { + float pfull = static_cast(d_input[i]->items_available()) / + static_cast(d_input[i]->max_possible_items_available()); + + d = pfull - d_avg_input_buffers_full[i]; + d_avg_input_buffers_full[i] = d_avg_input_buffers_full[i] + d/d_pc_counter; + d_var_input_buffers_full[i] = d_var_input_buffers_full[i] + d*d; + } - for(size_t i=0; i < d_output.size(); i++) { - float pfull = 1.0f - static_cast(d_output[i]->space_available()) / - static_cast(d_output[i]->bufsize()); - d_avg_output_buffers_full[i] = beta*d_avg_output_buffers_full[i] + alpha*pfull; + for(size_t i=0; i < d_output.size(); i++) { + float pfull = 1.0f - static_cast(d_output[i]->space_available()) / + static_cast(d_output[i]->bufsize()); + + d = pfull - d_avg_output_buffers_full[i]; + d_avg_output_buffers_full[i] = d_avg_output_buffers_full[i] + d/d_pc_counter; + d_var_output_buffers_full[i] = d_var_output_buffers_full[i] + d*d; + } } + + d_pc_counter++; +} + +void +gr_block_detail::reset_perf_counters() +{ + d_pc_counter = 0; } float @@ -307,3 +355,58 @@ gr_block_detail::pc_work_time() { return d_avg_work_time; } + + +float +gr_block_detail::pc_noutput_items_var() +{ + return d_var_noutput_items/(d_pc_counter-1); +} + +float +gr_block_detail::pc_nproduced_var() +{ + return d_var_nproduced/(d_pc_counter-1); +} + +float +gr_block_detail::pc_input_buffers_full_var(size_t which) +{ + if(which < d_avg_input_buffers_full.size()) + return d_var_input_buffers_full[which]/(d_pc_counter-1); + else + return 0; +} + +std::vector +gr_block_detail::pc_input_buffers_full_var() +{ + std::vector var(d_avg_input_buffers_full.size(), 0); + for(size_t i = 0; i < d_avg_input_buffers_full.size(); i++) + var[i] = d_avg_input_buffers_full[i]/(d_pc_counter-1); + return var; +} + +float +gr_block_detail::pc_output_buffers_full_var(size_t which) +{ + if(which < d_avg_output_buffers_full.size()) + return d_var_output_buffers_full[which]/(d_pc_counter-1); + else + return 0; +} + +std::vector +gr_block_detail::pc_output_buffers_full_var() +{ + std::vector var(d_avg_output_buffers_full.size(), 0); + for(size_t i = 0; i < d_avg_output_buffers_full.size(); i++) + var[i] = d_avg_output_buffers_full[i]/(d_pc_counter-1); + return var; +} + +float +gr_block_detail::pc_work_time_var() +{ + return d_var_work_time/(d_pc_counter-1); +} diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index a8ed8da90..32a01e763 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -173,6 +173,7 @@ class GR_CORE_API gr_block_detail { void start_perf_counters(); void stop_perf_counters(int noutput_items, int nproduced); + void reset_perf_counters(); // Calls to get performance counter items float pc_noutput_items(); @@ -182,6 +183,14 @@ class GR_CORE_API gr_block_detail { float pc_output_buffers_full(size_t which); std::vector pc_output_buffers_full(); float pc_work_time(); + + float pc_noutput_items_var(); + float pc_nproduced_var(); + float pc_input_buffers_full_var(size_t which); + std::vector pc_input_buffers_full_var(); + float pc_output_buffers_full_var(size_t which); + std::vector pc_output_buffers_full_var(); + float pc_work_time_var(); gr_tpb_detail d_tpb; // used by thread-per-block scheduler int d_produce_or; @@ -197,11 +206,17 @@ class GR_CORE_API gr_block_detail { // Performance counters float d_avg_noutput_items; + float d_var_noutput_items; float d_avg_nproduced; + float d_var_nproduced; std::vector d_avg_input_buffers_full; + std::vector d_var_input_buffers_full; std::vector d_avg_output_buffers_full; + std::vector d_var_output_buffers_full; gruel::high_res_timer_type d_start_of_work, d_end_of_work; float d_avg_work_time; + float d_var_work_time; + float d_pc_counter; gr_block_detail (unsigned int ninputs, unsigned int noutputs); -- cgit From 6e2f2e4716bedb1317b44d5b03bde4468b2502fd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 16 Feb 2013 10:57:04 -0500 Subject: core: adding new var perf. counters to swig interface. --- gnuradio-core/src/lib/runtime/gr_block.i | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index c016f2c28..a80f64d02 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -68,13 +68,20 @@ class gr_block : public gr_basic_block { // Methods to access performance counters float pc_noutput_items(); + float pc_noutput_items_var(); float pc_nproduced(); + float pc_nproduced_var(); float pc_input_buffers_full(int which); + float pc_input_buffers_full_var(int which); std::vector pc_input_buffers_full(); + std::vector pc_input_buffers_full_var(); float pc_output_buffers_full(int which); + float pc_output_buffers_full_var(int which); std::vector pc_output_buffers_full(); + std::vector pc_output_buffers_full_var(); float pc_work_time(); - + float pc_work_time_var(); + // Methods to manage processor affinity. void set_processor_affinity(const gr_vector_uint &mask); void unset_processor_affinity(); -- cgit From 55028034dbad37c07c4675c88fccb460218ee924 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 16 Feb 2013 14:45:43 -0500 Subject: core: adding and using a PerfCounters section to the config files. gr_block_executor will read the config files to determine if the perf counters are on or off. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 27f591452..6258d99a8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -179,6 +180,8 @@ gr_block_executor::~gr_block_executor () gr_block_executor::state gr_block_executor::run_one_iteration() { + gr_prefs *prefs = gr_prefs::singleton(); + int noutput_items; int max_items_avail; int max_noutput_items = d_max_noutput_items; @@ -420,7 +423,8 @@ gr_block_executor::run_one_iteration() d_start_nitems_read[i] = d->nitems_read(i); #ifdef GR_PERFORMANCE_COUNTERS - d->start_perf_counters(); + if(prefs->get_bool("PerfCounters", "on", false)) + d->start_perf_counters(); #endif /* GR_PERFORMANCE_COUNTERS */ // Do the actual work of the block @@ -428,7 +432,8 @@ gr_block_executor::run_one_iteration() d_input_items, d_output_items); #ifdef GR_PERFORMANCE_COUNTERS - d->stop_perf_counters(noutput_items, n); + if(prefs->get_bool("PerfCounters", "on", false)) + d->stop_perf_counters(noutput_items, n); #endif /* GR_PERFORMANCE_COUNTERS */ LOG(*d_log << " general_work: noutput_items = " << noutput_items -- cgit From 1ddc990d1aded4cda9c1dfde596a1be2599aaf0d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 16 Feb 2013 15:41:56 -0500 Subject: core: only query preferences database once at start of block_executor. --- gnuradio-core/src/lib/runtime/gr_block_executor.cc | 11 +++++++---- gnuradio-core/src/lib/runtime/gr_block_executor.h | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index 6258d99a8..e070f3c50 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -166,6 +166,11 @@ gr_block_executor::gr_block_executor (gr_block_sptr block, int max_noutput_items << d_block << std::endl; } +#ifdef GR_PERFORMANCE_COUNTERS + gr_prefs *prefs = gr_prefs::singleton(); + d_use_pc = prefs->get_bool("PerfCounters", "on", false); +#endif /* GR_PERFORMANCE_COUNTERS */ + d_block->start(); // enable any drivers, etc. } @@ -180,8 +185,6 @@ gr_block_executor::~gr_block_executor () gr_block_executor::state gr_block_executor::run_one_iteration() { - gr_prefs *prefs = gr_prefs::singleton(); - int noutput_items; int max_items_avail; int max_noutput_items = d_max_noutput_items; @@ -423,7 +426,7 @@ gr_block_executor::run_one_iteration() d_start_nitems_read[i] = d->nitems_read(i); #ifdef GR_PERFORMANCE_COUNTERS - if(prefs->get_bool("PerfCounters", "on", false)) + if(d_use_pc) d->start_perf_counters(); #endif /* GR_PERFORMANCE_COUNTERS */ @@ -432,7 +435,7 @@ gr_block_executor::run_one_iteration() d_input_items, d_output_items); #ifdef GR_PERFORMANCE_COUNTERS - if(prefs->get_bool("PerfCounters", "on", false)) + if(d_use_pc) d->stop_perf_counters(noutput_items, n); #endif /* GR_PERFORMANCE_COUNTERS */ diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.h b/gnuradio-core/src/lib/runtime/gr_block_executor.h index 0ae5affba..fb7f9c269 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.h +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.h @@ -53,6 +53,10 @@ protected: std::vector d_returned_tags; int d_max_noutput_items; +#ifdef GR_PERFORMANCE_COUNTERS + bool d_use_pc; +#endif /* GR_PERFORMANCE_COUNTERS */ + public: gr_block_executor(gr_block_sptr block, int max_noutput_items=100000); ~gr_block_executor (); -- cgit From ea42d0aa849bf5adfa0d1768e7b189a60b35e784 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 22 Feb 2013 00:30:57 -0800 Subject: gras: linker stuff + moving around symbols and shit Basically there were some issues on OSX linking, because gras wasnt explicitly specified, and was technically exposed by the gr wrappers. As part of this commit, some symbols were moved into the wrappers, and some of the interfaces which were in gras for backwards compat purposes, The compile is still going, but this already addresses a few issues. Now, I don't want to go copying every symbol over, the real solution is to link in gras into whatever library. Probably another commit to come... --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 4 +- gnuradio-core/src/lib/runtime/gr_block.cc | 35 +++++++ gnuradio-core/src/lib/runtime/gr_block.h | 14 +++ gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 133 +++--------------------- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 25 ----- gnuradio-core/src/lib/runtime/gr_top_block.cc | 83 ++++++--------- gnuradio-core/src/lib/runtime/gr_top_block.h | 34 +++--- 7 files changed, 112 insertions(+), 216 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index cec02b360..6092c4f4e 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -55,7 +55,7 @@ list(APPEND gnuradio_core_sources #${CMAKE_CURRENT_SOURCE_DIR}/gr_block_detail.cc #${CMAKE_CURRENT_SOURCE_DIR}/gr_block_executor.cc #${CMAKE_CURRENT_SOURCE_DIR}/gr_block_registry.cc - #${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2.cc #${CMAKE_CURRENT_SOURCE_DIR}/gr_hier_block2_detail.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_buffer.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_dispatcher.cc @@ -78,7 +78,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_decimator.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_interpolator.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_sys_paths.cc - #${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.cc #${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block_impl.cc #${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_detail.cc #${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_thread_body.cc diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 63df6aa18..dae266c87 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -43,6 +43,26 @@ gr_block::gr_block( this->set_output_signature(output_signature); } +void gr_block::notify_active(void) +{ + this->start(); +} + +bool gr_block::start(void) +{ + return true; +} + +void gr_block::notify_inactive(void) +{ + this->stop(); +} + +bool gr_block::stop(void) +{ + return true; +} + void gr_block::notify_topology(const size_t num_inputs, const size_t num_outputs) { _fcast_ninput_items.resize(num_inputs); @@ -57,6 +77,16 @@ bool gr_block::check_topology(int, int) return true; } +const gr_io_signature_sptr &gr_block::input_signature(void) const +{ + return gras::Block::input_signature(); +} + +const gr_io_signature_sptr &gr_block::output_signature(void) const +{ + return gras::Block::output_signature(); +} + void gr_block::work( const InputItems &input_items, const OutputItems &output_items @@ -454,3 +484,8 @@ gras::BufferQueueSptr gr_block::input_buffer_allocator(const size_t, const gras: } return gras::BufferQueueSptr(); } + +gras::BufferQueueSptr gr_block::output_buffer_allocator(const size_t which, const gras::SBufferConfig &config) +{ + return gras::Block::output_buffer_allocator(which, config); +} diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 48bb2fc97..2a57792a0 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -85,6 +85,9 @@ struct GR_CORE_API gr_block : gras::Block gr_vector_void_star &output_items ); + virtual bool start(void); + virtual bool stop(void); + //! Call during work to consume items void consume_each(const int how_many_items); @@ -140,6 +143,10 @@ struct GR_CORE_API gr_block : gras::Block bool is_set_max_noutput_items(void) const; + const gr_io_signature_sptr &input_signature(void) const; + + const gr_io_signature_sptr &output_signature(void) const; + /******************************************************************* * Deal with input and output port configuration ******************************************************************/ @@ -308,12 +315,19 @@ struct GR_CORE_API gr_block : gras::Block //! notifications of new topological commits void notify_topology(const size_t, const size_t); + //! start notification + void notify_active(void); + + //! stop notification + void notify_inactive(void); + //! implements tag_propagation_policy() virtual void propagate_tags(const size_t, const gras::TagIter &); void _update_input_reserve(void); gras::BufferQueueSptr input_buffer_allocator(const size_t, const gras::SBufferConfig &); + gras::BufferQueueSptr output_buffer_allocator(const size_t, const gras::SBufferConfig &); }; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index 8c2794c63..c43f903a3 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -25,129 +25,28 @@ #endif #include -#include -#include -#include -#define GR_HIER_BLOCK2_DEBUG 0 - -gr_hier_block2_sptr -gr_make_hier_block2(const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature) -{ - return gnuradio::get_initial_sptr(new gr_hier_block2(name, input_signature, output_signature)); -} - -gr_hier_block2::gr_hier_block2(const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature) - : gr_basic_block(name, input_signature, output_signature), - d_detail(new gr_hier_block2_detail(this)), - hier_message_ports_in(pmt::PMT_NIL), - hier_message_ports_out(pmt::PMT_NIL) -{ - // This bit of magic ensures that self() works in the constructors of derived classes. - gnuradio::detail::sptr_magic::create_and_stash_initial_sptr(this); -} - -gr_hier_block2::~gr_hier_block2() -{ - delete d_detail; -} - -gr_hier_block2::opaque_self -gr_hier_block2::self() +gr_hier_block2::gr_hier_block2(void) { - return shared_from_this(); + //NOP } -gr_hier_block2_sptr -gr_hier_block2::to_hier_block2() +gr_hier_block2::gr_hier_block2( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +): + gras::HierBlock(name) { - return cast_to_hier_block2_sptr(shared_from_this()); + this->set_input_signature(input_signature); + this->set_output_signature(output_signature); } -void -gr_hier_block2::connect(gr_basic_block_sptr block) -{ - d_detail->connect(block); -} - -void -gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port) -{ - d_detail->connect(src, src_port, dst, dst_port); -} - -void -gr_hier_block2::msg_connect(gr_basic_block_sptr src, pmt::pmt_t srcport, - gr_basic_block_sptr dst, pmt::pmt_t dstport) -{ - if(!pmt::pmt_is_symbol(srcport)){throw std::runtime_error("bad port id"); } - d_detail->msg_connect(src, srcport, dst, dstport); -} - -void -gr_hier_block2::msg_connect(gr_basic_block_sptr src, std::string srcport, - gr_basic_block_sptr dst, std::string dstport) -{ - d_detail->msg_connect(src, pmt::mp(srcport), dst, pmt::mp(dstport)); -} - -void -gr_hier_block2::msg_disconnect(gr_basic_block_sptr src, pmt::pmt_t srcport, - gr_basic_block_sptr dst, pmt::pmt_t dstport) -{ - if(!pmt::pmt_is_symbol(srcport)){throw std::runtime_error("bad port id"); } - d_detail->msg_disconnect(src, srcport, dst, dstport); -} - -void -gr_hier_block2::msg_disconnect(gr_basic_block_sptr src, std::string srcport, - gr_basic_block_sptr dst, std::string dstport) -{ - d_detail->msg_disconnect(src, pmt::mp(srcport), dst, pmt::mp(dstport)); -} - -void -gr_hier_block2::disconnect(gr_basic_block_sptr block) -{ - d_detail->disconnect(block); -} - -void -gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, - gr_basic_block_sptr dst, int dst_port) -{ - d_detail->disconnect(src, src_port, dst, dst_port); -} - -void -gr_hier_block2::disconnect_all() -{ - d_detail->disconnect_all(); -} - -void -gr_hier_block2::lock() -{ - d_detail->lock(); -} - -void -gr_hier_block2::unlock() -{ - d_detail->unlock(); -} - - -gr_flat_flowgraph_sptr -gr_hier_block2::flatten() const -{ - gr_flat_flowgraph_sptr new_ffg = gr_make_flat_flowgraph(); - d_detail->flatten_aux(new_ffg); - return new_ffg; +gr_hier_block2_sptr gr_make_hier_block2( + const std::string &name, + gr_io_signature_sptr input_signature, + gr_io_signature_sptr output_signature +){ + return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); } diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 4163557ca..2ab04ac6f 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -36,7 +36,6 @@ struct GR_CORE_API gr_hier_block2 : gras::HierBlock { return *this; } - }; typedef boost::shared_ptr gr_hier_block2_sptr; @@ -47,28 +46,4 @@ GR_CORE_API gr_hier_block2_sptr gr_make_hier_block2( gr_io_signature_sptr output_signature ); -inline gr_hier_block2::gr_hier_block2(void) -{ - //NOP -} - -inline gr_hier_block2::gr_hier_block2( - const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature -): - gras::HierBlock(name) -{ - this->set_input_signature(input_signature); - this->set_output_signature(output_signature); -} - -inline gr_hier_block2_sptr gr_make_hier_block2( - const std::string &name, - gr_io_signature_sptr input_signature, - gr_io_signature_sptr output_signature -){ - return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); -} - #endif /*INCLUDED_GNURADIO_GR_HIER_BLOCK2_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index e47473edd..da221c7d5 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -26,90 +26,65 @@ #include #include -#include -#include -#include -gr_top_block_sptr -gr_make_top_block(const std::string &name) +gr_top_block::gr_top_block(void): + //cannot make a null top block, use name constructor + gras::TopBlock("top") { - return gnuradio::get_initial_sptr(new gr_top_block(name)); + //NOP } -gr_top_block::gr_top_block(const std::string &name) - : gr_hier_block2(name, - gr_make_io_signature(0,0,0), - gr_make_io_signature(0,0,0)) - -{ - d_impl = new gr_top_block_impl(this); -} - -gr_top_block::~gr_top_block() -{ - stop(); - wait(); - - delete d_impl; -} - -void -gr_top_block::start(int max_noutput_items) +gr_top_block::gr_top_block(const std::string &name): + gras::TopBlock(name) { - d_impl->start(max_noutput_items); + //NOP } -void -gr_top_block::stop() +gr_top_block_sptr gr_make_top_block(const std::string &name) { - d_impl->stop(); + return gr_top_block_sptr(new gr_top_block(name)); } -void -gr_top_block::wait() +void gr_top_block::start(const size_t max_items) { - d_impl->wait(); + this->set_max_noutput_items(max_items); + this->start(); } -void -gr_top_block::run(int max_noutput_items) +void gr_top_block::run(const size_t max_items) { - start(max_noutput_items); - wait(); + this->set_max_noutput_items(max_items); + this->run(); } -void -gr_top_block::lock() +int gr_top_block::max_noutput_items(void) const { - d_impl->lock(); + return this->get_global_config().maximum_output_items; } -void -gr_top_block::unlock() +void gr_top_block::set_max_noutput_items(int max_items) { - d_impl->unlock(); + gras::GlobalBlockConfig config = this->get_global_config(); + config.maximum_output_items = max_items; + this->set_global_config(config); } -void -gr_top_block::dump() +void gr_top_block::run(void) { - d_impl->dump(); + gras::TopBlock::run(); } -int -gr_top_block::max_noutput_items() +void gr_top_block::start(void) { - return d_impl->max_noutput_items(); + gras::TopBlock::start(); } -void -gr_top_block::set_max_noutput_items(int nmax) +void gr_top_block::stop(void) { - d_impl->set_max_noutput_items(nmax); + gras::TopBlock::stop(); } -gr_top_block_sptr -gr_top_block::to_top_block() +void gr_top_block::wait(void) { - return cast_to_top_block_sptr(shared_from_this()); + gras::TopBlock::wait(); } diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 0e033f7c1..0126e9215 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -28,28 +28,26 @@ struct GR_CORE_API gr_top_block : gras::TopBlock gr_top_block(const std::string &name); -}; + void start(const size_t max_items); -typedef boost::shared_ptr gr_top_block_sptr; + void run(const size_t max_items); -GR_CORE_API gr_top_block_sptr gr_make_top_block(const std::string &name); + int max_noutput_items(void) const; -inline gr_top_block::gr_top_block(void): - //cannot make a null top block, use name constructor - gras::TopBlock("top") -{ - //NOP -} + void set_max_noutput_items(int max_items); -inline gr_top_block::gr_top_block(const std::string &name): - gras::TopBlock(name) -{ - //NOP -} + void run(void); -inline gr_top_block_sptr gr_make_top_block(const std::string &name) -{ - return gr_top_block_sptr(new gr_top_block(name)); -} + virtual void start(void); + + virtual void stop(void); + + virtual void wait(void); + +}; + +typedef boost::shared_ptr gr_top_block_sptr; + +GR_CORE_API gr_top_block_sptr gr_make_top_block(const std::string &name); #endif /*INCLUDED_GNURADIO_GR_TOP_BLOCK_H*/ -- cgit From 9ecb12014a646f67b428f9415a5f186c59537dba Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 22 Feb 2013 19:23:09 -0800 Subject: gras: continuation from the last commit Removed a bunch of GRAS_LIBRARIES, we do this in a common place to avoid extra changes. Added virtual destructors for many classes. --- gnuradio-core/src/lib/runtime/gr_block.cc | 15 +++++---------- gnuradio-core/src/lib/runtime/gr_block.h | 6 ++---- gnuradio-core/src/lib/runtime/gr_sync_block.cc | 5 +++++ gnuradio-core/src/lib/runtime/gr_sync_block.h | 2 ++ gnuradio-core/src/lib/runtime/gr_sync_decimator.cc | 5 +++++ gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 2 ++ gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc | 5 +++++ gnuradio-core/src/lib/runtime/gr_sync_interpolator.h | 2 ++ 8 files changed, 28 insertions(+), 14 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index dae266c87..ed390e71f 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -43,6 +43,11 @@ gr_block::gr_block( this->set_output_signature(output_signature); } +gr_block::~gr_block(void) +{ + //NOP +} + void gr_block::notify_active(void) { this->start(); @@ -77,16 +82,6 @@ bool gr_block::check_topology(int, int) return true; } -const gr_io_signature_sptr &gr_block::input_signature(void) const -{ - return gras::Block::input_signature(); -} - -const gr_io_signature_sptr &gr_block::output_signature(void) const -{ - return gras::Block::output_signature(); -} - void gr_block::work( const InputItems &input_items, const OutputItems &output_items diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 2a57792a0..0004f887b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -52,6 +52,8 @@ struct GR_CORE_API gr_block : gras::Block gr_io_signature_sptr output_signature ); + virtual ~gr_block(void); + virtual bool check_topology(int ninputs, int noutputs); //! Overload me! I am the forecast @@ -143,10 +145,6 @@ struct GR_CORE_API gr_block : gras::Block bool is_set_max_noutput_items(void) const; - const gr_io_signature_sptr &input_signature(void) const; - - const gr_io_signature_sptr &output_signature(void) const; - /******************************************************************* * Deal with input and output port configuration ******************************************************************/ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.cc b/gnuradio-core/src/lib/runtime/gr_sync_block.cc index 492fe2c2a..96b5e6253 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.cc @@ -41,6 +41,11 @@ gr_sync_block::gr_sync_block( this->set_fixed_rate(true); } +gr_sync_block::~gr_sync_block(void) +{ + //NOP +} + int gr_sync_block::work( int noutput_items, gr_vector_const_void_star &input_items, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index d0ce95bca..90370dd2b 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -29,6 +29,8 @@ struct GR_CORE_API gr_sync_block : public gr_block gr_io_signature_sptr output_signature ); + virtual ~gr_sync_block(void); + //! implements work -> calls work int general_work( int noutput_items, diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc index 4574116bc..a39c53b09 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.cc @@ -41,3 +41,8 @@ gr_sync_decimator::gr_sync_decimator( { this->set_decimation(decim_rate); } + +gr_sync_decimator::~gr_sync_decimator(void) +{ + //NOP +} diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h index 6f366037f..dd7de7d1f 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -31,6 +31,8 @@ struct GR_CORE_API gr_sync_decimator : gr_sync_block const size_t decim_rate ); + virtual ~gr_sync_decimator(void); + }; #endif /*INCLUDED_GNURADIO_GR_SYNC_DECIMATOR_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc index 28a878eb2..17f60e613 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.cc @@ -41,3 +41,8 @@ gr_sync_interpolator::gr_sync_interpolator( { this->set_interpolation(interp_rate); } + +gr_sync_interpolator::~gr_sync_interpolator(void) +{ + //NOP +} diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index 485e5c101..0ed8c6f56 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -31,6 +31,8 @@ struct GR_CORE_API gr_sync_interpolator : gr_sync_block const size_t interp_rate ); + virtual ~gr_sync_interpolator(void); + }; #endif /*INCLUDED_GNURADIO_GR_SYNC_INTERPOLATOR_H*/ -- cgit From eb05abff6d3ba1f593e3f33fe2eb455d0824a7a4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 23 Feb 2013 01:50:10 -0800 Subject: gras: implement io sig ontop of set/get size api --- gnuradio-core/src/lib/runtime/CMakeLists.txt | 2 +- gnuradio-core/src/lib/runtime/gr_block.cc | 28 ++++ gnuradio-core/src/lib/runtime/gr_block.h | 7 + gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 20 +++ gnuradio-core/src/lib/runtime/gr_hier_block2.h | 8 + gnuradio-core/src/lib/runtime/gr_io_signature.h | 201 ++++++++++++++---------- gnuradio-core/src/lib/runtime/gr_types.h | 1 - gnuradio-core/src/lib/runtime/runtime.i | 31 ++-- 8 files changed, 195 insertions(+), 103 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt index 6092c4f4e..5f2c317c4 100644 --- a/gnuradio-core/src/lib/runtime/CMakeLists.txt +++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt @@ -60,7 +60,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gr_buffer.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_dispatcher.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.cc - #${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_local_sighandler.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_message.cc #${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.cc diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index ed390e71f..bac395a20 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -43,6 +43,34 @@ gr_block::gr_block( this->set_output_signature(output_signature); } +gr_io_signature_sptr gr_block::input_signature(void) const +{ + return _in_sig; +} + +gr_io_signature_sptr gr_block::output_signature(void) const +{ + return _out_sig; +} + +void gr_block::set_input_signature(gr_io_signature_sptr sig) +{ + for (size_t i = 0; i < sig->sizeof_stream_items().size(); i++) + { + this->set_input_size(i, sig->sizeof_stream_items().at(i)); + } + _in_sig = sig; +} + +void gr_block::set_output_signature(gr_io_signature_sptr sig) +{ + for (size_t i = 0; i < sig->sizeof_stream_items().size(); i++) + { + this->set_output_size(i, sig->sizeof_stream_items().at(i)); + } + _out_sig = sig; +} + gr_block::~gr_block(void) { //NOP diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 0004f887b..6c6480eb4 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -54,6 +54,12 @@ struct GR_CORE_API gr_block : gras::Block virtual ~gr_block(void); + gr_io_signature_sptr input_signature(void) const; + gr_io_signature_sptr output_signature(void) const; + + void set_input_signature(gr_io_signature_sptr sig); + void set_output_signature(gr_io_signature_sptr sig); + virtual bool check_topology(int ninputs, int noutputs); //! Overload me! I am the forecast @@ -304,6 +310,7 @@ struct GR_CORE_API gr_block : gras::Block size_t _input_history_items; tag_propagation_policy_t _tag_prop_policy; size_t _interp, _decim; + gr_io_signature_sptr _in_sig, _out_sig; ///////////////// the Block overloads ////////////////////// diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index c43f903a3..2f92d8c6b 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -50,3 +50,23 @@ gr_hier_block2_sptr gr_make_hier_block2( ){ return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, output_signature)); } + +gr_io_signature_sptr gr_hier_block2::input_signature(void) const +{ + return _in_sig; +} + +gr_io_signature_sptr gr_hier_block2::output_signature(void) const +{ + return _out_sig; +} + +void gr_hier_block2::set_input_signature(gr_io_signature_sptr sig) +{ + _in_sig = sig; +} + +void gr_hier_block2::set_output_signature(gr_io_signature_sptr sig) +{ + _out_sig = sig; +} diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 2ab04ac6f..01cecfaf6 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -36,6 +36,14 @@ struct GR_CORE_API gr_hier_block2 : gras::HierBlock { return *this; } + + gr_io_signature_sptr input_signature(void) const; + gr_io_signature_sptr output_signature(void) const; + + void set_input_signature(gr_io_signature_sptr sig); + void set_output_signature(gr_io_signature_sptr sig); + + gr_io_signature_sptr _in_sig, _out_sig; }; typedef boost::shared_ptr gr_hier_block2_sptr; diff --git a/gnuradio-core/src/lib/runtime/gr_io_signature.h b/gnuradio-core/src/lib/runtime/gr_io_signature.h index 4c1eec4e8..fd1825797 100644 --- a/gnuradio-core/src/lib/runtime/gr_io_signature.h +++ b/gnuradio-core/src/lib/runtime/gr_io_signature.h @@ -1,84 +1,117 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . - -#ifndef INCLUDED_GNURADIO_GR_IO_SIGNATURE_H -#define INCLUDED_GNURADIO_GR_IO_SIGNATURE_H - -#include -#include - -typedef gras::IOSignature gr_io_signature; -typedef gr_io_signature gr_io_signature_sptr; - -inline gr_io_signature_sptr gr_make_io_signature( - int min_streams, - int max_streams, - int sizeof_stream_item -){ - gr_io_signature io_sig(min_streams, max_streams); - - if (io_sig.max_streams() != gr_io_signature::IO_INFINITE) - { - io_sig.resize(io_sig.max_streams(), sizeof_stream_item); - } - else - { - io_sig.resize(1, sizeof_stream_item); - } - - return io_sig; -} - -inline gr_io_signature_sptr gr_make_io_signature2( - int min_streams, - int max_streams, - int sizeof_stream_item1, - int sizeof_stream_item2 -){ - gr_io_signature io_sig(min_streams, max_streams); - io_sig.push_back(sizeof_stream_item1); - io_sig.push_back(sizeof_stream_item2); - return io_sig; -} - -inline gr_io_signature_sptr gr_make_io_signature3( - int min_streams, - int max_streams, - int sizeof_stream_item1, - int sizeof_stream_item2, - int sizeof_stream_item3 -){ - gr_io_signature io_sig(min_streams, max_streams); - io_sig.push_back(sizeof_stream_item1); - io_sig.push_back(sizeof_stream_item2); - io_sig.push_back(sizeof_stream_item3); - return io_sig; -} - -inline gr_io_signature_sptr gr_make_io_signaturev( - int min_streams, - int max_streams, - const std::vector &sizeof_stream_items -){ - gr_io_signature io_sig(min_streams, max_streams); - for (unsigned i = 0; i < sizeof_stream_items.size(); i++) - { - io_sig.push_back(sizeof_stream_items[i]); - } - return io_sig; -} - -#endif /*INCLUDED_GNURADIO_GR_IO_SIGNATURE_H*/ +/* -*- c++ -*- */ +/* + * Copyright 2004,2007 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_IO_SIGNATURE_H +#define INCLUDED_IO_SIGNATURE_H + +#include +#include + +/*! + * \brief Create an i/o signature + * + * \ingroup internal + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item specify the size of the items in each stream + */ +GR_CORE_API gr_io_signature_sptr +gr_make_io_signature(int min_streams, int max_streams, + int sizeof_stream_item); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item1 specify the size of the items in the first stream + * \param sizeof_stream_item2 specify the size of the items in the second and subsequent streams + */ +GR_CORE_API gr_io_signature_sptr +gr_make_io_signature2(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2 + ); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_item1 specify the size of the items in the first stream + * \param sizeof_stream_item2 specify the size of the items in the second stream + * \param sizeof_stream_item3 specify the size of the items in the third and subsequent streams + */ +GR_CORE_API gr_io_signature_sptr +gr_make_io_signature3(int min_streams, int max_streams, + int sizeof_stream_item1, + int sizeof_stream_item2, + int sizeof_stream_item3 + ); + +/*! + * \brief Create an i/o signature + * + * \param min_streams specify minimum number of streams (>= 0) + * \param max_streams specify maximum number of streams (>= min_streams or -1 -> infinite) + * \param sizeof_stream_items specify the size of the items in the streams + * + * If there are more streams than there are entries in sizeof_stream_items, the + * value of the last entry in sizeof_stream_items is used for the missing values. + * sizeof_stream_items must contain at least 1 entry. + */ +GR_CORE_API gr_io_signature_sptr +gr_make_io_signaturev(int min_streams, int max_streams, + const std::vector &sizeof_stream_items); + + +/*! + * \brief i/o signature for input and output ports. + * \brief misc + */ +class GR_CORE_API gr_io_signature { + int d_min_streams; + int d_max_streams; + std::vector d_sizeof_stream_item; + + gr_io_signature(int min_streams, int max_streams, + const std::vector &sizeof_stream_items); + + friend GR_CORE_API gr_io_signature_sptr + gr_make_io_signaturev(int min_streams, + int max_streams, + const std::vector &sizeof_stream_items); + + public: + + static const int IO_INFINITE = -1; + + ~gr_io_signature (); + + int min_streams () const { return d_min_streams; } + int max_streams () const { return d_max_streams; } + int sizeof_stream_item (int index) const; + std::vector sizeof_stream_items() const; +}; + + +#endif /* INCLUDED_IO_SIGNATURE_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h index 7b25a6811..a698226bf 100644 --- a/gnuradio-core/src/lib/runtime/gr_types.h +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -19,7 +19,6 @@ // this section is to satisfy swig includes for gras.i // since gras.i includes gr_types.h, we only have to edit this file -#include #include #include #include diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 4dff7fabe..29900bdf7 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -26,8 +26,6 @@ #include #include #include -#include -#include #include #include #include @@ -40,19 +38,6 @@ %} -%rename(io_signature) gr_make_io_signature; -%rename(io_signature2) gr_make_io_signature2; -%rename(io_signature3) gr_make_io_signature3; -%rename(io_signaturev) gr_make_io_signaturev; - -%include -%include -%include -%include -%include - -#ifdef SW_RUNTIME - //const size types used by blocks in python %constant int sizeof_char = sizeof(char); %constant int sizeof_short = sizeof(short); @@ -61,8 +46,16 @@ %constant int sizeof_double = sizeof(double); %constant int sizeof_gr_complex = sizeof(gr_complex); +%include +%include +%include +%include +%include + +#ifdef SW_RUNTIME + %import -%include +%include %include %include %include @@ -81,7 +74,11 @@ namespace gras struct HierBlock : gras::Element{}; } struct gr_hier_block2 : gras::HierBlock{}; -struct gr_block : gras::Block{}; +struct gr_block : gras::Block +{ + gr_io_signature_sptr input_signature(void) const; + gr_io_signature_sptr output_signature(void) const; +}; struct gr_sync_block : gr_block{}; struct gr_sync_interpolator : gr_sync_block{}; struct gr_sync_decimator : gr_sync_block{}; -- cgit From 3dd2796a1e9d189d5775db4aa2d1c2ec48a91d70 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 23 Feb 2013 04:26:55 -0800 Subject: gras: well thats a duplicate now --- gnuradio-core/src/lib/runtime/runtime.i | 1 - 1 file changed, 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 29900bdf7..d69122341 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -55,7 +55,6 @@ #ifdef SW_RUNTIME %import -%include %include %include %include -- cgit From df9bcf4297f0da202d28f9cdf1efd5bf8167d719 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 23 Feb 2013 04:27:19 -0800 Subject: gras: fix stupid multiple type traits error x86 machine --- gnuradio-core/src/lib/runtime/gr_tags.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_tags.i b/gnuradio-core/src/lib/runtime/gr_tags.i index 828d0147c..f2ee69ce8 100644 --- a/gnuradio-core/src/lib/runtime/gr_tags.i +++ b/gnuradio-core/src/lib/runtime/gr_tags.i @@ -23,7 +23,7 @@ #include %} -%include //for pmt support +%import //for pmt support %include -- cgit From c60a6dc8b61c26c37874b27e4440c02e573dca27 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 25 Feb 2013 03:16:03 -0800 Subject: gras: changes for port config API --- gnuradio-core/src/lib/runtime/gr_block.cc | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index bac395a20..53d9d20c4 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -57,7 +57,7 @@ void gr_block::set_input_signature(gr_io_signature_sptr sig) { for (size_t i = 0; i < sig->sizeof_stream_items().size(); i++) { - this->set_input_size(i, sig->sizeof_stream_items().at(i)); + this->input_config(i).item_size = sig->sizeof_stream_items().at(i); } _in_sig = sig; } @@ -66,7 +66,7 @@ void gr_block::set_output_signature(gr_io_signature_sptr sig) { for (size_t i = 0; i < sig->sizeof_stream_items().size(); i++) { - this->set_output_size(i, sig->sizeof_stream_items().at(i)); + this->output_config(i).item_size = sig->sizeof_stream_items().at(i); } _out_sig = sig; } @@ -344,12 +344,11 @@ unsigned gr_block::history(void) const void gr_block::set_history(unsigned history) { - gras::InputPortConfig config = this->get_input_config(0); //implement off-by-one history compat if (history == 0) history++; _input_history_items = history-1; - config.preload_items = _input_history_items; - this->set_input_config(0, config); + this->input_config(0).preload_items = _input_history_items; + this->commit_config(); } void gr_block::set_fixed_rate(const bool fixed_rate) @@ -373,18 +372,15 @@ void gr_block::_update_input_reserve(void) */ if (_enable_fixed_rate or _output_multiple_items > 1024) { - gras::InputPortConfig config = this->get_input_config(0); - config.reserve_items = size_t(0.5 + _output_multiple_items/_relative_rate); - if (config.reserve_items) this->set_input_config(0, config); + const size_t reserve = size_t(0.5 + _output_multiple_items/_relative_rate); + if (reserve) this->input_config(0).reserve_items = reserve; } } void gr_block::set_output_multiple(const size_t multiple) { _output_multiple_items = multiple; - gras::OutputPortConfig config = this->get_output_config(0); - config.reserve_items = multiple; - this->set_output_config(0, config); + this->output_config(0).reserve_items = multiple; this->_update_input_reserve(); } @@ -406,14 +402,12 @@ double gr_block::relative_rate(void) const int gr_block::max_noutput_items(void) const { - return this->get_output_config(0).maximum_items; + return this->output_config(0).maximum_items; } void gr_block::set_max_noutput_items(int max_items) { - gras::OutputPortConfig config = this->get_output_config(0); - config.maximum_items = max_items; - this->set_output_config(0, config); + this->output_config(0).maximum_items = max_items; } void gr_block::unset_max_noutput_items(void) -- cgit From d8e73d63c0af6ba6810319d866cab07b332d0e42 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 26 Feb 2013 12:00:47 -0500 Subject: core: adding a mutex as a protected member of gr_block for use in protecting set and work function access to variables. This is used in gr-analog's noise_source and gr-filter's fir_filter_XXX since these two cause particular problems (in next's channel model). This shows the use of the mutex for general protection when needed. --- gnuradio-core/src/lib/runtime/gr_block.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 6e21d5b97..0783e8684 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -484,9 +484,9 @@ class GR_CORE_API gr_block : public gr_basic_block { gr_block_detail_sptr d_detail; // implementation details unsigned d_history; bool d_fixed_rate; - int d_min_noutput_items; bool d_max_noutput_items_set; // if d_max_noutput_items is valid int d_max_noutput_items; // value of max_noutput_items for this block + int d_min_noutput_items; tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream std::vector d_affinity; // thread affinity proc. mask @@ -609,6 +609,12 @@ class GR_CORE_API gr_block : public gr_basic_block { std::vector d_max_output_buffer; std::vector d_min_output_buffer; + /*! Used by block's setters and work functions to make + * setting/resetting of parameters thread-safe. + * + * Used by calling gruel::scoped_lock l(d_setlock); + */ + gruel::mutex d_setlock; // These are really only for internal use, but leaving them public avoids // having to work up an ever-varying list of friend GR_CORE_APIs -- cgit From cb5ff01c491d4558a096fc1649b85283c36ccf91 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 6 Mar 2013 02:39:15 -0600 Subject: gras: same changes to config struct --- gnuradio-core/src/lib/runtime/gr_top_block.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index da221c7d5..1c885be6e 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -59,14 +59,12 @@ void gr_top_block::run(const size_t max_items) int gr_top_block::max_noutput_items(void) const { - return this->get_global_config().maximum_output_items; + return this->global_config().maximum_output_items; } void gr_top_block::set_max_noutput_items(int max_items) { - gras::GlobalBlockConfig config = this->get_global_config(); - config.maximum_output_items = max_items; - this->set_global_config(config); + this->global_config().maximum_output_items = max_items; } void gr_top_block::run(void) -- cgit From 7ebec8cc4b5e3a9eb480e3f954f9425d92e73a18 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 7 Mar 2013 14:24:52 -0500 Subject: core: protect against popping a message off the queue if no handler is attached. This mostly solves a problem with threads being launched in random order, so a handler might not be established yet, even if there is a message waiting. Fixes Issue #514. --- gnuradio-core/src/lib/runtime/gr_basic_block.h | 23 +++++++++++++++++++--- .../src/lib/runtime/gr_tpb_thread_body.cc | 17 +++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index b4935d8ac..024159c4c 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -106,6 +106,13 @@ class GR_CORE_API gr_basic_block : public gr_msg_accepter, public boost::enable_ void set_color(vcolor color) { d_color = color; } vcolor color() const { return d_color; } + /*! + * \brief Tests if there is a handler attached to port \p which_port + */ + bool has_msg_handler(pmt::pmt_t which_port) { + return (d_msg_handlers.find(which_port) != d_msg_handlers.end()); + } + /* * This function is called by the runtime system to dispatch messages. * @@ -115,9 +122,10 @@ class GR_CORE_API gr_basic_block : public gr_msg_accepter, public boost::enable_ virtual void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg) { // AA Update this - if (d_msg_handlers.find(which_port) != d_msg_handlers.end()) // Is there a handler? + if(has_msg_handler(which_port)) { // Is there a handler? d_msg_handlers[which_port](msg); // Yes, invoke it. - }; + } + } // Message passing interface pmt::pmt_t message_subscribers; @@ -177,9 +185,18 @@ class GR_CORE_API gr_basic_block : public gr_msg_accepter, public boost::enable_ } bool empty_p() { bool rv = true; - BOOST_FOREACH(msg_queue_map_t::value_type &i, msg_queue){ rv &= msg_queue[i.first].empty(); } + BOOST_FOREACH(msg_queue_map_t::value_type &i, msg_queue) { + rv &= msg_queue[i.first].empty(); + } return rv; } + + //! How many messages in the queue? + size_t nmsgs(pmt::pmt_t which_port) { + if(msg_queue.find(which_port) == msg_queue.end()) + throw std::runtime_error("port does not exist!"); + return msg_queue[which_port].size(); + } //| Acquires and release the mutex void insert_tail( pmt::pmt_t which_port, pmt::pmt_t msg); diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index cea374fac..679fd1512 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -22,6 +22,7 @@ #include #endif #include +#include #include #include #include @@ -41,6 +42,9 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item d->threaded = true; d->thread = gruel::get_current_thread_id(); + gr_prefs *p = gr_prefs::singleton(); + size_t max_nmsgs = static_cast(p->get_long("DEFAULT", "max_messages", 100)); + // Set thread affinity if it was set before fg was started. if(block->processor_affinity().size() > 0) { gruel::thread_bind_to_processor(d->thread, block->processor_affinity()); @@ -54,9 +58,20 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block, int max_noutput_item BOOST_FOREACH( gr_basic_block::msg_queue_map_t::value_type &i, block->msg_queue ) { + // Check if we have a message handler attached before getting + // any messages. This is mostly a protection for the unknown + // startup sequence of the threads. + if(block->has_msg_handler(i.first)) { while ((msg = block->delete_head_nowait(i.first))){ - block->dispatch_msg(i.first,msg); + block->dispatch_msg(i.first,msg); } + } + else { + // If we don't have a handler but are building up messages, + // prune the queue from the front to keep memory in check. + if(block->nmsgs(i.first) > max_nmsgs) + msg = block->delete_head_nowait(i.first); + } } d->d_tpb.clear_changed(); -- cgit From e3379b56d48f149df81760b897bbf0d562cef848 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 17 Mar 2013 23:46:55 -0700 Subject: gras: more changes to get compiling w/ maint --- gnuradio-core/src/lib/runtime/gr_block.h | 29 +++++++++++++++++++++++++++++ gnuradio-core/src/lib/runtime/runtime.i | 1 + 2 files changed, 30 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 9c8485663..6919b204e 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace gnuradio { @@ -318,6 +319,34 @@ struct GR_CORE_API gr_block : gras::Block } } + /*! Used by block's setters and work functions to make + * setting/resetting of parameters thread-safe. + * + * Used by calling gruel::scoped_lock l(d_setlock); + */ + gruel::mutex d_setlock; + + // ---------------------------------------------------------------------------- + // Functions to handle thread affinity + std::vector d_affinity; // thread affinity proc. mask + + /*! + * \brief Set the thread's affinity to processor core \p n. + * + * \param mask a vector of unsigned ints of the core numbers available to this block. + */ + void set_processor_affinity(const std::vector &mask){d_affinity=mask;} + + /*! + * \brief Remove processor affinity to a specific core. + */ + void unset_processor_affinity(){} + + /*! + * \brief Get the current processor affinity. + */ + std::vector processor_affinity() { return d_affinity; } + ///////////////// private vars ////////////////////// gr_vector_int _work_ninput_items; diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index d69122341..935b43742 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -20,6 +20,7 @@ %ignore gri_agc_cc::reference(); %ignore gri_agc2_ff::reference(); %ignore gri_agc2_cc::reference(); +%ignore gr_block::d_setlock; %{ -- cgit From 78ccc760124713a56c9c85729ac40844a97f0550 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 21 Mar 2013 20:45:29 -0700 Subject: gras: moved the lock/unlock here --- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 4 ++++ gnuradio-core/src/lib/runtime/gr_top_block.h | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 01cecfaf6..ec72bf337 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -43,6 +43,10 @@ struct GR_CORE_API gr_hier_block2 : gras::HierBlock void set_input_signature(gr_io_signature_sptr sig); void set_output_signature(gr_io_signature_sptr sig); + inline void lock(void){} + + inline void unlock(void){this->commit();} + gr_io_signature_sptr _in_sig, _out_sig; }; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 0126e9215..59dfe3b30 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -44,6 +44,10 @@ struct GR_CORE_API gr_top_block : gras::TopBlock virtual void wait(void); + inline void lock(void){} + + inline void unlock(void){this->commit();} + }; typedef boost::shared_ptr gr_top_block_sptr; -- cgit From 78cd4026c0a9b902162e94905b60a9dd44a07bb7 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 29 Mar 2013 13:12:36 -0400 Subject: core: addressing issue #529. Using vector instead of vector for affinity mask vector. This is wrong as the mask should be unsigned, but necessary for SWIG to work cleanly on both 32-bit and 64-bit platforms. --- gnuradio-core/src/lib/runtime/gr_block.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block.h | 8 ++++---- gnuradio-core/src/lib/runtime/gr_block.i | 4 ++-- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 2 +- gnuradio-core/src/lib/runtime/gr_block_detail.h | 4 ++-- gnuradio-core/src/lib/runtime/qa_gr_top_block.cc | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 54d267620..587e9d195 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -253,7 +253,7 @@ gr_block::is_set_max_noutput_items() } void -gr_block::set_processor_affinity(const std::vector &mask) +gr_block::set_processor_affinity(const std::vector &mask) { d_affinity = mask; if(d_detail) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 0783e8684..c5e510c3b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -458,9 +458,9 @@ class GR_CORE_API gr_block : public gr_basic_block { /*! * \brief Set the thread's affinity to processor core \p n. * - * \param mask a vector of unsigned ints of the core numbers available to this block. + * \param mask a vector of ints of the core numbers available to this block. */ - void set_processor_affinity(const std::vector &mask); + void set_processor_affinity(const std::vector &mask); /*! * \brief Remove processor affinity to a specific core. @@ -470,7 +470,7 @@ class GR_CORE_API gr_block : public gr_basic_block { /*! * \brief Get the current processor affinity. */ - std::vector processor_affinity() { return d_affinity; } + std::vector processor_affinity() { return d_affinity; } // ---------------------------------------------------------------------------- @@ -488,7 +488,7 @@ class GR_CORE_API gr_block : public gr_basic_block { int d_max_noutput_items; // value of max_noutput_items for this block int d_min_noutput_items; tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream - std::vector d_affinity; // thread affinity proc. mask + std::vector d_affinity; // thread affinity proc. mask protected: gr_block (void){} //allows pure virtual interface sub-classes diff --git a/gnuradio-core/src/lib/runtime/gr_block.i b/gnuradio-core/src/lib/runtime/gr_block.i index a80f64d02..a53489f9a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.i +++ b/gnuradio-core/src/lib/runtime/gr_block.i @@ -83,9 +83,9 @@ class gr_block : public gr_basic_block { float pc_work_time_var(); // Methods to manage processor affinity. - void set_processor_affinity(const gr_vector_uint &mask); + void set_processor_affinity(const std::vector &mask); void unset_processor_affinity(); - gr_vector_uint processor_affinity(); + std::vector processor_affinity(); // internal use gr_block_detail_sptr detail () const { return d_detail; } diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index 82081039a..af80e61cf 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -215,7 +215,7 @@ gr_block_detail::get_tags_in_range(std::vector &v, } void -gr_block_detail::set_processor_affinity(const std::vector &mask) +gr_block_detail::set_processor_affinity(const std::vector &mask) { if(threaded) { try { diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h index 32a01e763..15d85135a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h @@ -159,9 +159,9 @@ class GR_CORE_API gr_block_detail { /*! * \brief Set core affinity of block to the cores in the vector mask. * - * \param mask a vector of unsigned ints of the core numbers available to this block. + * \param mask a vector of ints of the core numbers available to this block. */ - void set_processor_affinity(const std::vector &mask); + void set_processor_affinity(const std::vector &mask); /*! * \brief Unset core affinity. diff --git a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc index 1d3dafadf..6bbc9ceb8 100644 --- a/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/qa_gr_top_block.cc @@ -269,7 +269,7 @@ void qa_gr_top_block::t11_set_block_affinity() gr_block_sptr src (gr_make_null_source(sizeof(float))); gr_block_sptr snk (gr_make_null_sink(sizeof(float))); - std::vector set(1, 0), ret; + std::vector set(1, 0), ret; src->set_processor_affinity(set); tb->connect(src, 0, snk, 0); -- cgit From 563240c2b4efc26e6c4032b0d3d75fc5489b7f1f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 14 Apr 2013 22:11:30 -0700 Subject: gras: runtime.i export a few more calls from block --- gnuradio-core/src/lib/runtime/runtime.i | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index 2da3f40a4..a172c151d 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -20,8 +20,15 @@ %ignore gri_agc_cc::reference(); %ignore gri_agc2_ff::reference(); %ignore gri_agc2_cc::reference(); + +//someone forgot about d_detail %ignore gr_block::d_setlock; +//dont export work overloads +%ignore general_work; +%ignore work; +%ignore forecast; + %{ #include @@ -78,6 +85,31 @@ struct gr_block : gras::Block { gr_io_signature_sptr input_signature(void) const; gr_io_signature_sptr output_signature(void) const; + + unsigned history () const; + + int output_multiple () const; + double relative_rate () const; + + bool start(); + bool stop(); + + uint64_t nitems_read(unsigned int which_input); + uint64_t nitems_written(unsigned int which_output); + + // Methods to manage the block's max_noutput_items size. + int max_noutput_items(); + void set_max_noutput_items(int m); + void unset_max_noutput_items(); + bool is_set_max_noutput_items(); + + // Methods to manage block's min/max buffer sizes. + long max_output_buffer(int i); + void set_max_output_buffer(long max_output_buffer); + void set_max_output_buffer(int port, long max_output_buffer); + long min_output_buffer(int i); + void set_min_output_buffer(long min_output_buffer); + void set_min_output_buffer(int port, long min_output_buffer); }; struct gr_sync_block : gr_block{}; struct gr_sync_interpolator : gr_sync_block{}; -- cgit From ae55a6d41af61415a56f43b087ccba2f43409fad Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 15 Apr 2013 01:49:12 -0700 Subject: gras: inline a bunch of wrapper calls Also simplify the work by reusing work buffers mins already calculated --- gnuradio-core/src/lib/runtime/gr_block.cc | 76 ++++---------------------- gnuradio-core/src/lib/runtime/gr_block.h | 46 ++++++++++++++++ gnuradio-core/src/lib/runtime/gr_sync_block.cc | 14 ----- gnuradio-core/src/lib/runtime/gr_sync_block.h | 14 +++++ 4 files changed, 71 insertions(+), 79 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 53d9d20c4..c243ff8d6 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -122,37 +122,29 @@ void gr_block::work( //------------------------------------------------------------------ //-- initialize input buffers before work //------------------------------------------------------------------ - size_t num_input_items = REALLY_BIG; //so big that it must std::min + size_t num_input_items = input_items.min(); + if (_enable_fixed_rate) num_input_items -= _input_history_items; for (size_t i = 0; i < num_inputs; i++) { _work_ninput_items[i] = input_items[i].size(); _work_input_items[i] = input_items[i].get(); _work_io_ptr_mask |= ptrdiff_t(_work_input_items[i]); - size_t items = input_items[i].size(); - if (_enable_fixed_rate) + if GRAS_UNLIKELY(_enable_fixed_rate and input_items[i].size() <= _input_history_items) { - if (items <= _input_history_items) - { - return this->mark_input_fail(i); - } - items -= _input_history_items; + return this->mark_input_fail(i); } - - num_input_items = std::min(num_input_items, items); } //------------------------------------------------------------------ //-- initialize output buffers before work //------------------------------------------------------------------ - size_t num_output_items = REALLY_BIG; //so big that it must std::min + size_t num_output_items = output_items.min(); + num_output_items /= _output_multiple_items; + num_output_items *= _output_multiple_items; for (size_t i = 0; i < num_outputs; i++) { _work_output_items[i] = output_items[i].get(); _work_io_ptr_mask |= ptrdiff_t(_work_output_items[i]); - size_t items = output_items[i].size(); - items /= _output_multiple_items; - items *= _output_multiple_items; - num_output_items = std::min(num_output_items, items); } //------------------------------------------------------------------ @@ -182,10 +174,10 @@ void gr_block::work( this->forecast(work_noutput_items, _fcast_ninput_items); for (size_t i = 0; i < input_items.size(); i++) { - if (_fcast_ninput_items[i] <= _work_ninput_items[i]) continue; + if GRAS_LIKELY(_fcast_ninput_items[i] <= _work_ninput_items[i]) continue; //handle the case of forecast failing - if (work_noutput_items <= _output_multiple_items) + if GRAS_UNLIKELY(work_noutput_items <= _output_multiple_items) { return this->mark_input_fail(i); } @@ -205,12 +197,12 @@ void gr_block::work( _work_output_items ); - if (work_ret > 0) for (size_t i = 0; i < num_outputs; i++) + if GRAS_LIKELY(work_ret > 0) for (size_t i = 0; i < num_outputs; i++) { this->produce(i, work_ret); } - if (work_ret == -1) this->mark_done(); + if GRAS_UNLIKELY(work_ret == -1) this->mark_done(); } static inline unsigned long long myullround(const double x) @@ -265,34 +257,6 @@ int gr_block::general_work( throw std::runtime_error("gr_block subclasses must overload general_work!"); } -void gr_block::consume_each(const int how_many_items) -{ - if (how_many_items < 0) return; - gras::Block::consume(size_t(how_many_items)); -} - -void gr_block::consume(const size_t i, const int how_many_items) -{ - if (how_many_items < 0) return; - gras::Block::consume(i, size_t(how_many_items)); -} - -void gr_block::produce(const size_t o, const int how_many_items) -{ - if (how_many_items < 0) return; - gras::Block::produce(o, size_t(how_many_items)); -} - -uint64_t gr_block::nitems_read(const size_t which_input) -{ - return Block::get_consumed(which_input); -} - -uint64_t gr_block::nitems_written(const size_t which_output) -{ - return Block::get_produced(which_output); -} - void gr_block::set_alignment(const size_t) { //TODO @@ -300,24 +264,11 @@ void gr_block::set_alignment(const size_t) //and therefore alignment is always re-acheived } -bool gr_block::is_unaligned(void) -{ - //TODO - //probably dont need this since volk dispatcher checks alignment - //32 byte aligned is good enough for you - return (_work_io_ptr_mask & ptrdiff_t(GRAS_MAX_ALIGNMENT-1)) != 0; -} - size_t gr_block::fixed_rate_noutput_to_ninput(const size_t noutput_items) { return ((decimation()*noutput_items)/interpolation()) + _input_history_items; } -size_t gr_block::interpolation(void) const -{ - return _interp; -} - void gr_block::set_interpolation(const size_t interp) { _interp = interp; @@ -325,11 +276,6 @@ void gr_block::set_interpolation(const size_t interp) this->set_output_multiple(interp); } -size_t gr_block::decimation(void) const -{ - return _decim; -} - void gr_block::set_decimation(const size_t decim) { _decim = decim; diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index c3898a5c0..44faa313a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -388,4 +388,50 @@ struct GR_CORE_API gr_block : gras::Block typedef boost::shared_ptr gr_block_sptr; +GRAS_FORCE_INLINE void gr_block::consume_each(const int how_many_items) +{ + if GRAS_UNLIKELY(how_many_items < 0) return; + gras::Block::consume(size_t(how_many_items)); +} + +GRAS_FORCE_INLINE void gr_block::consume(const size_t i, const int how_many_items) +{ + if GRAS_UNLIKELY(how_many_items < 0) return; + gras::Block::consume(i, size_t(how_many_items)); +} + +GRAS_FORCE_INLINE void gr_block::produce(const size_t o, const int how_many_items) +{ + if GRAS_UNLIKELY(how_many_items < 0) return; + gras::Block::produce(o, size_t(how_many_items)); +} + +GRAS_FORCE_INLINE uint64_t gr_block::nitems_read(const size_t which_input) +{ + return Block::get_consumed(which_input); +} + +GRAS_FORCE_INLINE uint64_t gr_block::nitems_written(const size_t which_output) +{ + return Block::get_produced(which_output); +} + +GRAS_FORCE_INLINE size_t gr_block::interpolation(void) const +{ + return _interp; +} + +GRAS_FORCE_INLINE size_t gr_block::decimation(void) const +{ + return _decim; +} + +GRAS_FORCE_INLINE bool gr_block::is_unaligned(void) +{ + //TODO + //probably dont need this since volk dispatcher checks alignment + //32 byte aligned is good enough for you + return (_work_io_ptr_mask & ptrdiff_t(GRAS_MAX_ALIGNMENT-1)) != 0; +} + #endif /*INCLUDED_GNURADIO_GR_BLOCK_H*/ diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.cc b/gnuradio-core/src/lib/runtime/gr_sync_block.cc index 96b5e6253..3c79e630d 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.cc @@ -53,17 +53,3 @@ int gr_sync_block::work( ){ throw std::runtime_error("gr_block subclasses must overload general_work!"); } - -int gr_sync_block::general_work( - int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items -){ - const int work_ret = this->work(noutput_items, input_items, output_items); - if (work_ret > 0) - { - this->consume_each((decimation()*size_t(work_ret))/interpolation()); - } - return work_ret; -} diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index 90370dd2b..1d2aef802 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -52,4 +52,18 @@ struct GR_CORE_API gr_sync_block : public gr_block }; +GRAS_FORCE_INLINE int gr_sync_block::general_work( + int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items +){ + const int work_ret = this->work(noutput_items, input_items, output_items); + if (work_ret > 0) + { + this->consume_each((decimation()*size_t(work_ret))/interpolation()); + } + return work_ret; +} + #endif /*INCLUDED_GNURADIO_GR_SYNC_BLOCK_H*/ -- cgit From 4d576d8d00ca66214f6447d644ffc400530cb5c5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 15 Apr 2013 23:10:44 -0700 Subject: gras: make use of work buffer's vec call --- gnuradio-core/src/lib/runtime/gr_block.cc | 19 +++++++------------ gnuradio-core/src/lib/runtime/gr_block.h | 3 +-- 2 files changed, 8 insertions(+), 14 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index c243ff8d6..2848f34e8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -98,10 +98,9 @@ bool gr_block::stop(void) void gr_block::notify_topology(const size_t num_inputs, const size_t num_outputs) { + _num_outputs = num_outputs; _fcast_ninput_items.resize(num_inputs); _work_ninput_items.resize(num_inputs); - _work_input_items.resize(num_inputs); - _work_output_items.resize(num_outputs); this->check_topology(num_inputs, num_outputs); } @@ -127,8 +126,7 @@ void gr_block::work( for (size_t i = 0; i < num_inputs; i++) { _work_ninput_items[i] = input_items[i].size(); - _work_input_items[i] = input_items[i].get(); - _work_io_ptr_mask |= ptrdiff_t(_work_input_items[i]); + _work_io_ptr_mask |= ptrdiff_t(input_items.vec()[i]); if GRAS_UNLIKELY(_enable_fixed_rate and input_items[i].size() <= _input_history_items) { return this->mark_input_fail(i); @@ -143,8 +141,7 @@ void gr_block::work( num_output_items *= _output_multiple_items; for (size_t i = 0; i < num_outputs; i++) { - _work_output_items[i] = output_items[i].get(); - _work_io_ptr_mask |= ptrdiff_t(_work_output_items[i]); + _work_io_ptr_mask |= ptrdiff_t(output_items.vec()[i]); } //------------------------------------------------------------------ @@ -193,8 +190,8 @@ void gr_block::work( const int work_ret = this->general_work( work_noutput_items, _work_ninput_items, - _work_input_items, - _work_output_items + const_cast(input_items).vec(), + const_cast(output_items).vec() ); if GRAS_LIKELY(work_ret > 0) for (size_t i = 0; i < num_outputs; i++) @@ -212,13 +209,11 @@ static inline unsigned long long myullround(const double x) void gr_block::propagate_tags(const size_t which_input, const gras::TagIter &iter) { - const size_t num_outputs = _work_output_items.size(); - switch (_tag_prop_policy) { case TPP_DONT: break; //well that was ez case TPP_ALL_TO_ALL: - for (size_t out_i = 0; out_i < num_outputs; out_i++) + for (size_t out_i = 0; out_i < _num_outputs; out_i++) { BOOST_FOREACH(gras::Tag t, iter) { @@ -228,7 +223,7 @@ void gr_block::propagate_tags(const size_t which_input, const gras::TagIter &ite } break; case TPP_ONE_TO_ONE: - if (which_input < num_outputs) + if (which_input < _num_outputs) { BOOST_FOREACH(gras::Tag t, iter) { diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 44faa313a..9225e6910 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -351,8 +351,7 @@ struct GR_CORE_API gr_block : gras::Block gr_vector_int _work_ninput_items; gr_vector_int _fcast_ninput_items; - gr_vector_const_void_star _work_input_items; - gr_vector_void_star _work_output_items; + size_t _num_outputs; ptrdiff_t _work_io_ptr_mask; size_t _output_multiple_items; double _relative_rate; -- cgit From 589915f97bba8499715bc61d2dec64b6fd7bca25 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 15 Apr 2013 23:42:58 -0700 Subject: gras: copied in standard header w/ correct dates --- gnuradio-core/src/lib/runtime/gr_block.cc | 35 ++++++++++++---------- gnuradio-core/src/lib/runtime/gr_block.h | 35 ++++++++++++---------- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 35 ++++++++++++---------- gnuradio-core/src/lib/runtime/gr_sync_block.h | 35 ++++++++++++---------- gnuradio-core/src/lib/runtime/gr_sync_decimator.h | 35 ++++++++++++---------- .../src/lib/runtime/gr_sync_interpolator.h | 35 ++++++++++++---------- gnuradio-core/src/lib/runtime/gr_top_block.h | 35 ++++++++++++---------- gnuradio-core/src/lib/runtime/gr_types.h | 35 ++++++++++++---------- gnuradio-core/src/lib/runtime/pmx_helper.hpp | 35 ++++++++++++---------- gnuradio-core/src/lib/runtime/runtime.i | 35 ++++++++++++---------- 10 files changed, 200 insertions(+), 150 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 2848f34e8..144b51f45 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #include "pmx_helper.hpp" #include diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 9225e6910..7a728bc4e 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #ifndef INCLUDED_GNURADIO_GR_BLOCK_H #define INCLUDED_GNURADIO_GR_BLOCK_H diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index ec72bf337..61f2e500f 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #ifndef INCLUDED_GNURADIO_GR_HIER_BLOCK2_H #define INCLUDED_GNURADIO_GR_HIER_BLOCK2_H diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index 1d2aef802..0f3daccf2 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #ifndef INCLUDED_GNURADIO_GR_SYNC_BLOCK_H #define INCLUDED_GNURADIO_GR_SYNC_BLOCK_H diff --git a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h index dd7de7d1f..32edfd78e 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_decimator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_decimator.h @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #ifndef INCLUDED_GNURADIO_GR_SYNC_DECIMATOR_H #define INCLUDED_GNURADIO_GR_SYNC_DECIMATOR_H diff --git a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h index 0ed8c6f56..81c17c18e 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_interpolator.h @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #ifndef INCLUDED_GNURADIO_GR_SYNC_INTERPOLATOR_H #define INCLUDED_GNURADIO_GR_SYNC_INTERPOLATOR_H diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 59dfe3b30..451f28a7b 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #ifndef INCLUDED_GNURADIO_GR_TOP_BLOCK_H #define INCLUDED_GNURADIO_GR_TOP_BLOCK_H diff --git a/gnuradio-core/src/lib/runtime/gr_types.h b/gnuradio-core/src/lib/runtime/gr_types.h index 9b70eb20c..b7c297d61 100644 --- a/gnuradio-core/src/lib/runtime/gr_types.h +++ b/gnuradio-core/src/lib/runtime/gr_types.h @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #ifndef INCLUDED_GRNURADIO_TYPES_H #define INCLUDED_GRNURADIO_TYPES_H diff --git a/gnuradio-core/src/lib/runtime/pmx_helper.hpp b/gnuradio-core/src/lib/runtime/pmx_helper.hpp index 4178daa06..44cc2997c 100644 --- a/gnuradio-core/src/lib/runtime/pmx_helper.hpp +++ b/gnuradio-core/src/lib/runtime/pmx_helper.hpp @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #ifndef INCLUDED_LIBGRAS_PMX_HELPER_HPP #define INCLUDED_LIBGRAS_PMX_HELPER_HPP diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i index a172c151d..64c28c8e1 100644 --- a/gnuradio-core/src/lib/runtime/runtime.i +++ b/gnuradio-core/src/lib/runtime/runtime.i @@ -1,18 +1,23 @@ -// -// Copyright 2012 Josh Blum -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see . +/* + * Copyright 2012-2013 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ #define GR_CORE_API -- cgit From 14502c92752098e773187890b89db8c763a1ecda Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 1 May 2013 18:16:26 -0700 Subject: gras: use include for pmt_swig.i for swig vector error Effected ubuntu 11.04 - the std::vector already defined swig error Import pmt_swig not include in all cases. However, gr_feval.i was probably the one causing general to fail --- gnuradio-core/src/lib/runtime/gr_basic_block.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index 62f16462d..91f3d2cfc 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -23,7 +23,7 @@ class gr_basic_block; typedef boost::shared_ptr gr_basic_block_sptr; %template(gr_basic_block_sptr) boost::shared_ptr; -%include "pmt_swig.i" +%import "pmt_swig.i" using namespace pmt; // support vectors of these... -- cgit From 3868a90728478e541d7b1b4864da1fbef59bcf34 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Wed, 8 May 2013 23:25:28 +0100 Subject: runtime: fix for thread safety issue during simultaneous use of stream tags and performance counters --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index af80e61cf..ecc0c1f98 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -261,6 +261,7 @@ gr_block_detail::stop_perf_counters(int noutput_items, int nproduced) d_var_input_buffers_full[i] = 0; } for(size_t i=0; i < d_output.size(); i++) { + gr::thread::scoped_lock guard(*d_output[i]->mutex()); float pfull = 1.0f - static_cast(d_output[i]->space_available()) / static_cast(d_output[i]->bufsize()); d_avg_output_buffers_full[i] = pfull; @@ -290,6 +291,7 @@ gr_block_detail::stop_perf_counters(int noutput_items, int nproduced) } for(size_t i=0; i < d_output.size(); i++) { + gr::thread::scoped_lock guard(*d_output[i]->mutex()); float pfull = 1.0f - static_cast(d_output[i]->space_available()) / static_cast(d_output[i]->bufsize()); -- cgit From 00796f668331ee9d4d00817dbe224b57be164d1a Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 8 May 2013 23:07:32 -0400 Subject: runtime: forgot to go back to the 'old' style using gruel. --- gnuradio-core/src/lib/runtime/gr_block_detail.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc index ecc0c1f98..4922ea083 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc @@ -261,7 +261,7 @@ gr_block_detail::stop_perf_counters(int noutput_items, int nproduced) d_var_input_buffers_full[i] = 0; } for(size_t i=0; i < d_output.size(); i++) { - gr::thread::scoped_lock guard(*d_output[i]->mutex()); + gruel::scoped_lock guard(*d_output[i]->mutex()); float pfull = 1.0f - static_cast(d_output[i]->space_available()) / static_cast(d_output[i]->bufsize()); d_avg_output_buffers_full[i] = pfull; @@ -291,7 +291,7 @@ gr_block_detail::stop_perf_counters(int noutput_items, int nproduced) } for(size_t i=0; i < d_output.size(); i++) { - gr::thread::scoped_lock guard(*d_output[i]->mutex()); + gruel::scoped_lock guard(*d_output[i]->mutex()); float pfull = 1.0f - static_cast(d_output[i]->space_available()) / static_cast(d_output[i]->bufsize()); -- cgit From f4fc952e58ce318298258926f7382ed28b92bfae Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 1 Jun 2013 22:43:27 -0700 Subject: gras: moved name and id into compat layer --- gnuradio-core/src/lib/runtime/gr_block.cc | 7 ++++++- gnuradio-core/src/lib/runtime/gr_block.h | 5 +++++ gnuradio-core/src/lib/runtime/gr_hier_block2.cc | 7 ++++++- gnuradio-core/src/lib/runtime/gr_hier_block2.h | 5 +++++ gnuradio-core/src/lib/runtime/gr_top_block.cc | 11 +++++++++-- gnuradio-core/src/lib/runtime/gr_top_block.h | 5 +++++ 6 files changed, 36 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc index 144b51f45..443ac8f64 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_block.cc @@ -23,6 +23,9 @@ #include #include #include +#include + +static boost::detail::atomic_count unique_id_pool(0); gr_block::gr_block(void) { @@ -34,7 +37,9 @@ gr_block::gr_block( gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature ): - gras::Block(name) + gras::Block(name), + _unique_id(++unique_id_pool), + _name(name) { //this initializes private vars, order matters this->set_fixed_rate(false); diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 7a728bc4e..08914f24a 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -54,6 +54,11 @@ struct GR_CORE_API gr_block : gras::Block gr_io_signature_sptr output_signature ); + long unique_id(void) const{return _unique_id;} + std::string name(void) const{return _name;} + long _unique_id; + std::string _name; + virtual ~gr_block(void); gr_io_signature_sptr input_signature(void) const; diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc index 2f92d8c6b..04eb60fc6 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.cc +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.cc @@ -25,6 +25,9 @@ #endif #include +#include + +static boost::detail::atomic_count unique_id_pool(0); gr_hier_block2::gr_hier_block2(void) @@ -37,7 +40,9 @@ gr_hier_block2::gr_hier_block2( gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature ): - gras::HierBlock(name) + gras::HierBlock(name), + _unique_id(++unique_id_pool), + _name(name) { this->set_input_signature(input_signature); this->set_output_signature(output_signature); diff --git a/gnuradio-core/src/lib/runtime/gr_hier_block2.h b/gnuradio-core/src/lib/runtime/gr_hier_block2.h index 61f2e500f..d393c42cb 100644 --- a/gnuradio-core/src/lib/runtime/gr_hier_block2.h +++ b/gnuradio-core/src/lib/runtime/gr_hier_block2.h @@ -37,6 +37,11 @@ struct GR_CORE_API gr_hier_block2 : gras::HierBlock gr_io_signature_sptr output_signature ); + long unique_id(void) const{return _unique_id;} + std::string name(void) const{return _name;} + long _unique_id; + std::string _name; + const gr_hier_block2 &self(void) const { return *this; diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.cc b/gnuradio-core/src/lib/runtime/gr_top_block.cc index 1c885be6e..fa090b4ef 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_top_block.cc @@ -26,16 +26,23 @@ #include #include +#include + +static boost::detail::atomic_count unique_id_pool(0); gr_top_block::gr_top_block(void): //cannot make a null top block, use name constructor - gras::TopBlock("top") + gras::TopBlock("top"), + _unique_id(++unique_id_pool), + _name("top") { //NOP } gr_top_block::gr_top_block(const std::string &name): - gras::TopBlock(name) + gras::TopBlock(name), + _unique_id(++unique_id_pool), + _name(name) { //NOP } diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.h b/gnuradio-core/src/lib/runtime/gr_top_block.h index 451f28a7b..4e4becd1f 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.h +++ b/gnuradio-core/src/lib/runtime/gr_top_block.h @@ -33,6 +33,11 @@ struct GR_CORE_API gr_top_block : gras::TopBlock gr_top_block(const std::string &name); + long unique_id(void) const{return _unique_id;} + std::string name(void) const{return _name;} + long _unique_id; + std::string _name; + void start(const size_t max_items); void run(const size_t max_items); -- cgit From 6961a794356d413f81bfbf347ed84619b1125d22 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 31 Jul 2013 00:20:23 -0700 Subject: gras: transplant get_initial_sptr for teh compilz --- gnuradio-core/src/lib/runtime/gr_block.h | 11 +---------- gnuradio-core/src/lib/runtime/gr_sptr_magic.h | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) (limited to 'gnuradio-core/src/lib/runtime') diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index 08914f24a..bd085100b 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -32,16 +32,7 @@ #include #include #include - -namespace gnuradio -{ -//! dummy entry, just here for legacy purposes -template -boost::shared_ptr get_initial_sptr(T *p) -{ - return boost::shared_ptr(p); -} -} +#include struct GR_CORE_API gr_block : gras::Block { diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.h b/gnuradio-core/src/lib/runtime/gr_sptr_magic.h index 3d997539c..d9c7f26c4 100644 --- a/gnuradio-core/src/lib/runtime/gr_sptr_magic.h +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.h @@ -45,7 +45,7 @@ namespace gnuradio { boost::shared_ptr get_initial_sptr(T *p) { - return boost::dynamic_pointer_cast(detail::sptr_magic::fetch_initial_sptr(p)); + return boost::shared_ptr(p);//return boost::dynamic_pointer_cast(detail::sptr_magic::fetch_initial_sptr(p)); } }; -- cgit