switch source package format to 3.0 quilt
[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 #include <deque>
26 #include <gruel/pmt.h>
27
28 class gr_block_detail;
29
30 /*!
31  * \brief used by thread-per-block scheduler
32  */
33 struct gr_tpb_detail {
34
35   gruel::mutex                  mutex;                  //< protects all vars
36   bool                          input_changed;
37   gruel::condition_variable     input_cond;
38   bool                          output_changed;
39   gruel::condition_variable     output_cond;
40
41 private:
42   std::deque<pmt::pmt_t>        msg_queue;
43
44 public:
45   gr_tpb_detail()
46     : input_changed(false), output_changed(false) { }
47
48   //! Called by us to tell all our upstream blocks that their output may have changed.
49   void notify_upstream(gr_block_detail *d);
50
51   //! Called by us to tell all our downstream blocks that their input may have changed.
52   void notify_downstream(gr_block_detail *d);
53
54   //! Called by us to notify both upstream and downstream
55   void notify_neighbors(gr_block_detail *d);
56
57   //! Called by us
58   void clear_changed()
59   {
60     gruel::scoped_lock guard(mutex);
61     input_changed = false;
62     output_changed = false;
63   }
64   
65   //! is the queue empty?
66   bool empty_p() const { return msg_queue.empty(); }
67
68   //| Acquires and release the mutex    
69   void insert_tail(pmt::pmt_t msg);
70
71   /*!
72    * \returns returns pmt at head of queue or pmt_t() if empty.
73    */
74   pmt::pmt_t delete_head_nowait();
75
76   /*!
77    * \returns returns pmt at head of queue or pmt_t() if empty.
78    * Caller must already be holding the mutex
79    */
80   pmt::pmt_t delete_head_nowait_already_holding_mutex();
81
82 private:
83
84   //! Used by notify_downstream
85   void set_input_changed()
86   {
87     gruel::scoped_lock guard(mutex);
88     input_changed = true;
89     input_cond.notify_one();
90   }
91
92   //! Used by notify_upstream
93   void set_output_changed()
94   {
95     gruel::scoped_lock guard(mutex);
96     output_changed = true;
97     output_cond.notify_one();
98   }
99
100 };
101
102 #endif /* INCLUDED_GR_TPB_DETAIL_H */