1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008,2009,2013 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 
22 #ifndef INCLUDED_GR_TPB_DETAIL_H
23 #define INCLUDED_GR_TPB_DETAIL_H
24 
25 #include <gnuradio/api.h>
26 #include <gnuradio/thread/thread.h>
27 #include <pmt/pmt.h>
28 #include <deque>
29 
30 namespace gr {
31 
32 class block_detail;
33 
34 /*!
35  * \brief used by thread-per-block scheduler
36  */
37 struct GR_RUNTIME_API tpb_detail {
38     gr::thread::mutex mutex; //< protects all vars
39     bool input_changed;
40     gr::thread::condition_variable input_cond;
41     bool output_changed;
42     gr::thread::condition_variable output_cond;
43 
44 public:
tpb_detailtpb_detail45     tpb_detail() : input_changed(false), output_changed(false) {}
46 
47     //! Called by us to tell all our upstream blocks that their output
48     //! may have changed.
49     void notify_upstream(block_detail* d);
50 
51     //! Called by us to tell all our downstream blocks that their
52     //! input may have changed.
53     void notify_downstream(block_detail* d);
54 
55     //! Called by us to notify both upstream and downstream
56     void notify_neighbors(block_detail* d);
57 
58     //! Called by pmt msg posters
notify_msgtpb_detail59     void notify_msg()
60     {
61         gr::thread::scoped_lock guard(mutex);
62         input_changed = true;
63         input_cond.notify_one();
64         output_changed = true;
65         output_cond.notify_one();
66     }
67 
68     //! Called by us
clear_changedtpb_detail69     void clear_changed()
70     {
71         gr::thread::scoped_lock guard(mutex);
72         input_changed = false;
73         output_changed = false;
74     }
75 
76 private:
77     //! Used by notify_downstream
set_input_changedtpb_detail78     void set_input_changed()
79     {
80         gr::thread::scoped_lock guard(mutex);
81         input_changed = true;
82         input_cond.notify_one();
83     }
84 
85     //! Used by notify_upstream
set_output_changedtpb_detail86     void set_output_changed()
87     {
88         gr::thread::scoped_lock guard(mutex);
89         output_changed = true;
90         output_cond.notify_one();
91     }
92 };
93 
94 } /* namespace gr */
95 
96 #endif /* INCLUDED_GR_TPB_DETAIL_H */
97