]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
PrioritizedQueue: allow remove_by_class to return removed items
authorSamuel Just <sam.just@inktank.com>
Thu, 15 Nov 2012 00:30:05 +0000 (16:30 -0800)
committerSage Weil <sage@inktank.com>
Thu, 15 Nov 2012 01:05:55 +0000 (17:05 -0800)
Signed-off-by: Samuel Just <sam.just@inktank.com>
src/common/PrioritizedQueue.h

index 53933421db2aa9a0f960c7d935257c525c72be7e..267db38b3c1daf3adaf795ae51fe27354597d504 100644 (file)
@@ -136,7 +136,7 @@ class PrioritizedQueue {
       if (cur == q.end())
        cur = q.begin();
     }
-    void remove_by_class(K k) {
+    void remove_by_class(K k, list<T> *out) {
       typename map<K, list<pair<unsigned, T> > >::iterator i = q.find(k);
       if (i == q.end())
        return;
@@ -146,6 +146,14 @@ class PrioritizedQueue {
        if (cur == q.end())
          cur = q.begin();
       }
+      if (out) {
+       for (typename list<pair<unsigned, T> >::reverse_iterator j =
+              i->second.rbegin();
+            j != i->second.rend();
+            ++j) {
+         out->push_front(j->second);
+       }
+      }
       q.erase(i);
     }
   };
@@ -225,11 +233,11 @@ public:
     }
   }
 
-  void remove_by_class(K k) {
+  void remove_by_class(K k, list<T> *out = 0) {
     for (typename map<unsigned, SubQueue>::iterator i = queue.begin();
         i != queue.end();
         ) {
-      i->second.remove_by_class(k);
+      i->second.remove_by_class(k, out);
       if (i->second.empty()) {
        unsigned priority = i->first;
        ++i;
@@ -241,7 +249,7 @@ public:
     for (typename map<unsigned, SubQueue>::iterator i = high_queue.begin();
         i != high_queue.end();
         ) {
-      i->second.remove_by_class(k);
+      i->second.remove_by_class(k, out);
       if (i->second.empty()) {
        high_queue.erase(i++);
       } else {