summaryrefslogtreecommitdiff
path: root/gnuradio-core
diff options
context:
space:
mode:
authorTom Rondeau2010-11-02 19:57:24 -0400
committerTom Rondeau2010-11-02 19:57:24 -0400
commite70f8a0d50474784c1f1b64b94907feb9b913a2b (patch)
tree62141b4ab6ca9b540fe88ad86d73d3f4d10bc222 /gnuradio-core
parent1c7119f52792da359fc5638a589b8cc8fa959864 (diff)
downloadgnuradio-e70f8a0d50474784c1f1b64b94907feb9b913a2b.tar.gz
gnuradio-e70f8a0d50474784c1f1b64b94907feb9b913a2b.tar.bz2
gnuradio-e70f8a0d50474784c1f1b64b94907feb9b913a2b.zip
Moved number items read/written from gr_block_detail into gr_buffer (abs_written_offset) and gr_buffer_reader (abs_read_offset). Keeps the API exposed in gr_blocks for now.
Diffstat (limited to 'gnuradio-core')
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block.cc4
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block_detail.cc24
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block_detail.h14
-rw-r--r--gnuradio-core/src/lib/runtime/gr_buffer.cc5
-rw-r--r--gnuradio-core/src/lib/runtime/gr_buffer.h10
5 files changed, 32 insertions, 25 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc
index e0a223135..c00a034de 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.cc
+++ b/gnuradio-core/src/lib/runtime/gr_block.cc
@@ -121,7 +121,7 @@ gr_uint64
gr_block::n_items_read(unsigned int which_input)
{
if(d_detail) {
- return d_detail->n_items_read(which_input);
+ return d_detail->nitems_read(which_input);
}
else {
//throw std::runtime_error("No block_detail associated with block yet");
@@ -133,7 +133,7 @@ gr_uint64
gr_block::n_items_written(unsigned int which_output)
{
if(d_detail) {
- return d_detail->n_items_written(which_output);
+ return d_detail->nitems_written(which_output);
}
else {
//throw std::runtime_error("No block_detail associated with block yet");
diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc
index effaf5269..d12d808e9 100644
--- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc
+++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc
@@ -39,7 +39,6 @@ gr_block_detail::gr_block_detail (unsigned int ninputs, unsigned int noutputs)
: d_produce_or(0),
d_ninputs (ninputs), d_noutputs (noutputs),
d_input (ninputs), d_output (noutputs),
- d_n_items_read(ninputs, 0), d_n_items_written(noutputs, 0),
d_done (false)
{
s_ncurrently_allocated++;
@@ -91,10 +90,6 @@ gr_block_detail::consume (int which_input, int how_many_items)
{
if (how_many_items > 0) {
input (which_input)->update_read_pointer (how_many_items);
-
- // Carefull here; we check that which_input exists above
- // is this good enough protection that we don't get here?
- d_n_items_read[which_input] += how_many_items;
}
}
@@ -105,7 +100,6 @@ gr_block_detail::consume_each (int how_many_items)
if (how_many_items > 0) {
for (int i = 0; i < ninputs (); i++) {
d_input[i]->update_read_pointer (how_many_items);
- d_n_items_read[i] += how_many_items;
}
}
}
@@ -115,7 +109,6 @@ gr_block_detail::produce (int which_output, int how_many_items)
{
if (how_many_items > 0){
d_output[which_output]->update_write_pointer (how_many_items);
- d_n_items_written[which_output] += how_many_items;
d_produce_or |= how_many_items;
}
}
@@ -126,7 +119,6 @@ gr_block_detail::produce_each (int how_many_items)
if (how_many_items > 0) {
for (int i = 0; i < noutputs (); i++) {
d_output[i]->update_write_pointer (how_many_items);
- d_n_items_written[i] += how_many_items;
}
d_produce_or |= how_many_items;
}
@@ -139,6 +131,22 @@ gr_block_detail::_post(pmt::pmt_t msg)
d_tpb.insert_tail(msg);
}
+gr_uint64
+gr_block_detail::nitems_read(unsigned int which_input)
+{
+ if(which_input >= d_ninputs)
+ throw std::invalid_argument ("gr_block_detail::n_input_items");
+ return d_input[which_input]->nitems_read();
+}
+
+gr_uint64
+gr_block_detail::nitems_written(unsigned int which_output)
+{
+ if(which_output >= d_noutputs)
+ throw std::invalid_argument ("gr_block_detail::n_output_items");
+ return d_output[which_output]->nitems_written();
+}
+
void
gr_block_detail::add_item_tag(unsigned int which_output,
gr_uint64 offset,
diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h
index cb590cec9..ee226a349 100644
--- a/gnuradio-core/src/lib/runtime/gr_block_detail.h
+++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h
@@ -89,18 +89,10 @@ class gr_block_detail {
void _post(pmt::pmt_t msg);
// Return the number of items read on input stream which_input
- gr_uint64 n_items_read(unsigned int which_input) {
- if(which_input >= d_ninputs)
- throw std::invalid_argument ("gr_block_detail::n_input_items");
- return d_n_items_read[which_input];
- }
+ gr_uint64 nitems_read(unsigned int which_input);
// Return the number of items written on output stream which_output
- gr_uint64 n_items_written(unsigned int which_output) {
- if(which_output >= d_noutputs)
- throw std::invalid_argument ("gr_block_detail::n_output_items");
- return d_n_items_written[which_output];
- }
+ gr_uint64 nitems_written(unsigned int which_output);
// Add an item tag tuple to list of tags
// -> is this just based on output stream? how to handle this...
@@ -125,8 +117,6 @@ class gr_block_detail {
unsigned int d_noutputs;
std::vector<gr_buffer_reader_sptr> d_input;
std::vector<gr_buffer_sptr> d_output;
- std::vector<uint64_t> d_n_items_read;
- std::vector<uint64_t> d_n_items_written;
std::list<pmt::pmt_t> d_item_tags;
bool d_done;
diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc
index db2db5d6d..42d00e06f 100644
--- a/gnuradio-core/src/lib/runtime/gr_buffer.cc
+++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc
@@ -80,7 +80,7 @@ minimum_buffer_items (long type_size, long page_size)
gr_buffer::gr_buffer (int nitems, size_t sizeof_item, gr_block_sptr link)
: d_base (0), d_bufsize (0), d_vmcircbuf (0),
d_sizeof_item (sizeof_item), d_link(link),
- d_write_index (0), d_done (false)
+ d_write_index (0), d_abs_write_offset(0), d_done (false)
{
if (!allocate_buffer (nitems, sizeof_item))
throw std::bad_alloc ();
@@ -225,7 +225,7 @@ gr_buffer_ncurrently_allocated ()
gr_buffer_reader::gr_buffer_reader(gr_buffer_sptr buffer, unsigned int read_index,
gr_block_sptr link)
- : d_buffer(buffer), d_read_index(read_index), d_link(link)
+ : d_buffer(buffer), d_read_index(read_index), d_abs_read_offset(0), d_link(link)
{
s_buffer_reader_count++;
}
@@ -253,6 +253,7 @@ gr_buffer_reader::update_read_pointer (int nitems)
{
gruel::scoped_lock guard(*mutex());
d_read_index = d_buffer->index_add (d_read_index, nitems);
+ d_abs_read_offset += nitems;
}
long
diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h
index 207bfe7c5..8af72741a 100644
--- a/gnuradio-core/src/lib/runtime/gr_buffer.h
+++ b/gnuradio-core/src/lib/runtime/gr_buffer.h
@@ -88,6 +88,8 @@ class gr_buffer {
gruel::mutex *mutex() { return &d_mutex; }
+ gr_uint64 nitems_written() { return d_abs_write_offset; }
+
// -------------------------------------------------------------------------
private:
@@ -106,10 +108,13 @@ class gr_buffer {
boost::weak_ptr<gr_block> d_link; // block that writes to this buffer
//
- // The mutex protects d_write_index, d_done and the d_read_index's in the buffer readers.
+ // The mutex protects d_write_index, d_abs_write_offset, d_done and the d_read_index's
+ // and d_abs_read_offset's in the buffer readers.
//
gruel::mutex d_mutex;
unsigned int d_write_index; // in items [0,d_bufsize)
+ gr_uint64 d_abs_write_offset; // num items written since the start
+ //deq tag_tuples
bool d_done;
unsigned
@@ -220,6 +225,8 @@ class gr_buffer_reader {
gruel::mutex *mutex() { return d_buffer->mutex(); }
+ gr_uint64 nitems_read() { return d_abs_read_offset; }
+
/*!
* \brief Return the block that reads via this reader.
*/
@@ -236,6 +243,7 @@ class gr_buffer_reader {
gr_buffer_sptr d_buffer;
unsigned int d_read_index; // in items [0,d->buffer.d_bufsize)
+ gr_uint64 d_abs_read_offset; // num items seen since the start
boost::weak_ptr<gr_block> d_link; // block that reads via this buffer reader
//! constructor is private. Use gr_buffer::add_reader to create instances