GNU Radio 3.6.5 C++ API

gr_tpb_detail.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2008,2009 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 #ifndef INCLUDED_GR_TPB_DETAIL_H
00022 #define INCLUDED_GR_TPB_DETAIL_H
00023 
00024 #include <gr_core_api.h>
00025 #include <gruel/thread.h>
00026 #include <deque>
00027 #include <gruel/pmt.h>
00028 
00029 class gr_block_detail;
00030 
00031 /*!
00032  * \brief used by thread-per-block scheduler
00033  */
00034 struct GR_CORE_API gr_tpb_detail {
00035 
00036   gruel::mutex                  mutex;                  //< protects all vars
00037   bool                          input_changed;
00038   gruel::condition_variable     input_cond;
00039   bool                          output_changed;
00040   gruel::condition_variable     output_cond;
00041 
00042 public:
00043   gr_tpb_detail()
00044     : input_changed(false), output_changed(false) { }
00045 
00046   //! Called by us to tell all our upstream blocks that their output may have changed.
00047   void notify_upstream(gr_block_detail *d);
00048 
00049   //! Called by us to tell all our downstream blocks that their input may have changed.
00050   void notify_downstream(gr_block_detail *d);
00051 
00052   //! Called by us to notify both upstream and downstream
00053   void notify_neighbors(gr_block_detail *d);
00054 
00055   //! Called by pmt msg posters
00056   void notify_msg(){
00057     input_cond.notify_one();
00058     output_cond.notify_one();
00059     }
00060 
00061   //! Called by us
00062   void clear_changed()
00063   {
00064     gruel::scoped_lock guard(mutex);
00065     input_changed = false;
00066     output_changed = false;
00067   }
00068 
00069 private:
00070 
00071   //! Used by notify_downstream
00072   void set_input_changed()
00073   {
00074     gruel::scoped_lock guard(mutex);
00075     input_changed = true;
00076     input_cond.notify_one();
00077   }
00078 
00079   //! Used by notify_upstream
00080   void set_output_changed()
00081   {
00082     gruel::scoped_lock guard(mutex);
00083     output_changed = true;
00084     output_cond.notify_one();
00085   }
00086 
00087 };
00088 
00089 #endif /* INCLUDED_GR_TPB_DETAIL_H */