From a6b5781e36ff75adb1e4d39d755d4ab8f5efd9dd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 14 Nov 2010 13:43:05 -0500 Subject: First hack at pruning tags to keep from growing. --- gnuradio-core/src/lib/runtime/gr_buffer.cc | 28 +++++++++++++++++++++++++++- gnuradio-core/src/lib/runtime/gr_buffer.h | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 1d67470ec..f6a0a98fb 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -156,8 +156,15 @@ gr_buffer::space_available () // Find out the maximum amount of data available to our readers int most_data = d_readers[0]->items_available (); - for (unsigned int i = 1; i < d_readers.size (); i++) + uint64_t min_items_read = d_readers[0]->nitems_read(); + for (size_t i = 1; i < d_readers.size (); i++) { most_data = std::max (most_data, d_readers[i]->items_available ()); + min_items_read = std::min(min_items_read, d_readers[i]->nitems_read()); + } + + for (size_t i = 0; i < d_readers.size (); i++) { + d_readers[i]->prune_tags(min_items_read); + } // The -1 ensures that the case d_write_index == d_read_index is // unambiguous. It indicates that there is no data for the reader @@ -287,6 +294,25 @@ gr_buffer_reader::get_tags_in_range(uint64_t abs_start, return found_items; } +void +gr_buffer_reader::prune_tags(uint64_t max_time) +{ + int n = 0; + uint64_t item_time; + std::deque::iterator itr = d_buffer->get_tags_begin(); + + while(itr != d_buffer->get_tags_end()) { + item_time = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*itr, 0)); + if(item_time < max_time) { + d_buffer->tags_pop_front(); + n++; + } + else + break; + itr++; + } +} + long gr_buffer_reader_ncurrently_allocated () { diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index d6d5564e8..47ba4cd96 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -101,6 +101,7 @@ class gr_buffer { std::deque::iterator get_tags_begin() { return d_item_tags.begin(); } std::deque::iterator get_tags_end() { return d_item_tags.end(); } + void tags_pop_front() { d_item_tags.pop_front(); } // ------------------------------------------------------------------------- @@ -260,6 +261,8 @@ class gr_buffer_reader { std::vector get_tags_in_range(uint64_t abs_start, uint64_t abs_end); + void prune_tags(uint64_t max_time); + // ------------------------------------------------------------------------- private: -- cgit