gem5: fix some iterator use and erase bugs
authorAli Saidi <Ali.Saidi@ARM.com>
Thu, 10 May 2012 23:04:27 +0000 (18:04 -0500)
committerAli Saidi <Ali.Saidi@ARM.com>
Thu, 10 May 2012 23:04:27 +0000 (18:04 -0500)
src/cpu/pc_event.cc
src/mem/cache/prefetch/base.cc

index 9cf63f7d3b6396b3a701bffdfad74726c78db5bb..2b54ee5fb7acaf1f2acaba20b0ff2fece5102b6d 100644 (file)
@@ -56,13 +56,18 @@ PCEventQueue::remove(PCEvent *event)
 {
     int removed = 0;
     range_t range = equal_range(event);
-    for (iterator i = range.first; i != range.second; ++i) {
+    iterator i = range.first;
+    while (i != range.second &&
+           i != pc_map.end()) {
         if (*i == event) {
             DPRINTF(PCEvent, "PC based event removed at %#x: %s\n",
                     event->pc(), event->descr());
-            pc_map.erase(i);
+            i = pc_map.erase(i);
             ++removed;
+        } else {
+            i++;
         }
+
     }
 
     return removed > 0;
index 4d1f7c81cba5c41bbfddfc079d079fe8a0a33ee5..f3ac5f04646d18a229303a3bfa13ec63fe156ef4 100644 (file)
@@ -182,7 +182,7 @@ BasePrefetcher::notify(PacketPtr &pkt, Tick time)
             pfRemovedMSHR++;
             delete (*iter)->req;
             delete (*iter);
-            pf.erase(iter);
+            iter = pf.erase(iter);
             if (pf.empty())
                 cache->deassertMemSideBusRequest(BaseCache::Request_PF);
         }
@@ -194,15 +194,17 @@ BasePrefetcher::notify(PacketPtr &pkt, Tick time)
         // Needed for serial calculators like GHB
         if (serialSquash) {
             iter = pf.end();
-            iter--;
+            if (iter != pf.begin())
+                iter--;
             while (!pf.empty() && ((*iter)->time >= time)) {
                 pfSquashed++;
                 DPRINTF(HWPrefetch, "Squashing old prefetch addr: 0x%x\n",
                         (*iter)->getAddr());
                 delete (*iter)->req;
                 delete (*iter);
-                pf.erase(iter);
-                iter--;
+                iter = pf.erase(iter);
+                if (iter != pf.begin())
+                    iter--;
             }
             if (pf.empty())
                 cache->deassertMemSideBusRequest(BaseCache::Request_PF);