]> git.gag.com Git - debian/gnuradio/blob - gnuradio-core/src/lib/runtime/gr_tpb_detail.h
29101d7307b36a6c14877c40f82b3e15616f4864
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_tpb_detail.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008,2009 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 #ifndef INCLUDED_GR_TPB_DETAIL_H
22 #define INCLUDED_GR_TPB_DETAIL_H
23
24 #include <gruel/thread.h>
25
26 class gr_block_detail;
27
28 /*!
29  * \brief used by thread-per-block scheduler
30  */
31 struct gr_tpb_detail {
32
33   gruel::mutex                  mutex;                  //< protects all vars
34   bool                          input_changed;
35   gruel::condition_variable     input_cond;
36   bool                          output_changed;
37   gruel::condition_variable     output_cond;
38   bool                          msg_pending;
39
40   gr_tpb_detail()
41     : input_changed(false), output_changed(false), msg_pending(false) { }
42
43   //! Called by us to tell all our upstream blocks that their output may have changed.
44   void notify_upstream(gr_block_detail *d);
45
46   //! Called by us to tell all our downstream blocks that their input may have changed.
47   void notify_downstream(gr_block_detail *d);
48
49   //! Called by us to notify both upstream and downstream
50   void notify_neighbors(gr_block_detail *d);
51
52   //! Called by us
53   void clear_changed()
54   {
55     gruel::scoped_lock guard(mutex);
56     input_changed = false;
57     output_changed = false;
58   }
59
60   //! Called to notify us that a message is pending in the queue
61   void notify_msg()
62   {
63     gruel::scoped_lock guard(mutex);
64     msg_pending = true;
65     input_cond.notify_one();
66     output_cond.notify_one();
67   }
68
69 private:
70
71   //! Used by notify_downstream
72   void set_input_changed()
73   {
74     gruel::scoped_lock guard(mutex);
75     input_changed = true;
76     input_cond.notify_one();
77   }
78
79   //! Used by notify_upstream
80   void set_output_changed()
81   {
82     gruel::scoped_lock guard(mutex);
83     output_changed = true;
84     output_cond.notify_one();
85   }
86 };
87
88 #endif /* INCLUDED_GR_TPB_DETAIL_H */