]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/shared_cache: allow comparator to be adjusted
authorSage Weil <sage@redhat.com>
Tue, 4 Aug 2015 15:31:37 +0000 (11:31 -0400)
committerSage Weil <sage@redhat.com>
Fri, 7 Aug 2015 14:17:34 +0000 (10:17 -0400)
Allow the use of a comparator that has a value, and for that
comparator to be adjusted at runtime for the purposes for get_next
sort order.  Since get_next uses the weak_refs map, that is the
only map that needs to be rebuilt.

We assume, for simplicity, that the comparator can be constructed
with no arguments with some default... otherwise this is messier.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/shared_cache.hpp

index d149d1ba39a9077b756606c29a464d29e6351e7b..c55119c02b796c79ff86104cde54311db53e3dd9 100644 (file)
@@ -105,6 +105,24 @@ public:
     }
   }
 
+  /// adjust container comparator (for purposes of get_next sort order)
+  void reset_comparator(C comp) {
+    // get_next uses weak_refs; that's the only container we need to
+    // reorder.
+    map<K, pair<WeakVPtr, V*>, C> temp;
+
+    Mutex::Locker l(lock);
+    temp.swap(weak_refs);
+
+    // reconstruct with new comparator
+    weak_refs = map<K, pair<WeakVPtr, V*>, C>(comp);
+    weak_refs.insert(temp.begin(), temp.end());
+  }
+
+  C get_comparator() {
+    return weak_refs.key_comp();
+  }
+
   void set_cct(CephContext *c) {
     cct = c;
   }