Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_tpb_detail.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 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 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #include <gr_tpb_detail.h>
26 #include <gr_block.h>
27 #include <gr_block_detail.h>
28 #include <gr_buffer.h>
29
30 /*
31  * We assume that no worker threads are ever running when the
32  * graph structure is being manipulated, thus it's safe for us to poke
33  * around in our neighbors w/o holding any locks.
34  */
35
36 void
37 gr_tpb_detail::notify_upstream(gr_block_detail *d)
38 {
39   // For each of our inputs, tell the guy upstream that we've consumed
40   // some input, and that he most likely has more output buffer space
41   // available.
42
43   for (size_t i = 0; i < d->d_input.size(); i++){
44     // Can you say, "pointer chasing?"
45     d->d_input[i]->buffer()->link()->detail()->d_tpb.set_output_changed();
46   }
47 }
48
49 void
50 gr_tpb_detail::notify_downstream(gr_block_detail *d)
51 {
52   // For each of our outputs, tell the guys downstream that they have
53   // new input available.
54
55   for (size_t i = 0; i < d->d_output.size(); i++){
56     gr_buffer_sptr buf = d->d_output[i];
57     for (size_t j = 0, k = buf->nreaders(); j < k; j++)
58       buf->reader(j)->link()->detail()->d_tpb.set_input_changed();
59   }
60 }
61
62 void
63 gr_tpb_detail::notify_neighbors(gr_block_detail *d)
64 {
65   notify_downstream(d);
66   notify_upstream(d);
67 }