commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/01: runtime: fixes a problem with tag pr


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/01: runtime: fixes a problem with tag pruning.
Date: Wed, 5 Aug 2015 20:50:45 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch maint
in repository gnuradio.

commit 25ece6784ec06d9c2fed13d59eb9dec9c541983d
Author: Tom Rondeau <address@hidden>
Date:   Wed Aug 5 15:28:43 2015 -0400

    runtime: fixes a problem with tag pruning.
    
    Looked like a race condition if two blocks are reading from the same
    buffer; one block calls prune before the other one can, and then it no
    longer gets its tags. This puts back in the original protections we
    used when pruning with vectors, only we don't have to restart the
    iterator at the beginning and can exit sooner because of the sort
    order. Likely slower than the multimap erase, so we will have to
    reinvestigate what kind of performance hit we take and if we can do
    better.
---
 gnuradio-runtime/lib/buffer.cc | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/gnuradio-runtime/lib/buffer.cc b/gnuradio-runtime/lib/buffer.cc
index f00e9a0..4840614 100644
--- a/gnuradio-runtime/lib/buffer.cc
+++ b/gnuradio-runtime/lib/buffer.cc
@@ -248,12 +248,37 @@ namespace gr {
        locks the mutex itself.
 
        If this function is used elsewhere, remember to lock the
-       buffer's mutex al la the scoped_lock line below.
-    */
-    std::multimap<uint64_t, tag_t>::iterator end_itr = 
d_item_tags.lower_bound(max_time);
-    std::multimap<uint64_t, tag_t>::iterator begin_itr = d_item_tags.begin();
-    d_item_tags.erase(begin_itr, end_itr);
-  }
+       buffer's mutex al la the scoped_lock:
+           gr::thread::scoped_lock guard(*mutex());
+     */
+
+    /*
+      http://www.cplusplus.com/reference/map/multimap/erase/
+      "Iterators, pointers and references referring to elements removed
+      by the function are invalidated. All other iterators, pointers
+      and references keep their validity."
+
+      Store the iterator to be deleted in tmp; increment itr to the
+      next valid iterator, then erase tmp, which now becomes invalid.
+     */
+
+    uint64_t item_time;
+   std::multimap<uint64_t,tag_t>::iterator itr(d_item_tags.begin()), tmp;
+    while(itr != d_item_tags.end()) {
+      item_time = (*itr).second.offset;
+      if(item_time+d_max_reader_delay + bufsize() < max_time) {
+        tmp = itr;
+       itr++;
+        d_item_tags.erase(tmp);
+      }
+      else {
+        // d_item_tags is a map sorted by offset, so when the if
+        // condition above fails, all future tags in the map must also
+        // fail. So just break here.
+        break;
+      }
+    }
+   }
 
   long
   buffer_ncurrently_allocated()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]