GNU Radio 3.7.1 C++ API
tpb_detail.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2008,2009,2013 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00020  */
00021 
00022 #ifndef INCLUDED_GR_TPB_DETAIL_H
00023 #define INCLUDED_GR_TPB_DETAIL_H
00024 
00025 #include <gnuradio/api.h>
00026 #include <gnuradio/thread/thread.h>
00027 #include <deque>
00028 #include <pmt/pmt.h>
00029 
00030 namespace gr {
00031 
00032   class block_detail;
00033 
00034   /*!
00035    * \brief used by thread-per-block scheduler
00036    */
00037   struct GR_RUNTIME_API tpb_detail {
00038     gr::thread::mutex                   mutex;                  //< protects all vars
00039     bool                                input_changed;
00040     gr::thread::condition_variable      input_cond;
00041     bool                                output_changed;
00042     gr::thread::condition_variable      output_cond;
00043 
00044   public:
00045     tpb_detail()
00046       : input_changed(false), output_changed(false) { }
00047 
00048     //! Called by us to tell all our upstream blocks that their output
00049     //! may have changed.
00050     void notify_upstream(block_detail *d);
00051 
00052     //! Called by us to tell all our downstream blocks that their
00053     //! input may have changed.
00054     void notify_downstream(block_detail *d);
00055 
00056     //! Called by us to notify both upstream and downstream
00057     void notify_neighbors(block_detail *d);
00058 
00059     //! Called by pmt msg posters
00060     void notify_msg() {
00061       input_cond.notify_one();
00062       output_cond.notify_one();
00063     }
00064 
00065     //! Called by us
00066     void clear_changed()
00067     {
00068       gr::thread::scoped_lock guard(mutex);
00069       input_changed = false;
00070       output_changed = false;
00071     }
00072 
00073   private:
00074     //! Used by notify_downstream
00075     void set_input_changed()
00076     {
00077       gr::thread::scoped_lock guard(mutex);
00078       input_changed = true;
00079       input_cond.notify_one();
00080     }
00081 
00082     //! Used by notify_upstream
00083     void set_output_changed()
00084     {
00085       gr::thread::scoped_lock guard(mutex);
00086       output_changed = true;
00087       output_cond.notify_one();
00088     }
00089   };
00090 
00091 } /* namespace gr */
00092 
00093 #endif /* INCLUDED_GR_TPB_DETAIL_H */