From: Sage Weil Date: Tue, 4 Aug 2015 15:31:37 +0000 (-0400) Subject: common/shared_cache: allow comparator to be adjusted X-Git-Tag: v9.1.0~346^2~15 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a78cef4f3cb4b60184f3877b73e78d186f82c52a;p=ceph.git common/shared_cache: allow comparator to be adjusted 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 --- diff --git a/src/common/shared_cache.hpp b/src/common/shared_cache.hpp index d149d1ba39a9..c55119c02b79 100644 --- a/src/common/shared_cache.hpp +++ b/src/common/shared_cache.hpp @@ -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, C> temp; + + Mutex::Locker l(lock); + temp.swap(weak_refs); + + // reconstruct with new comparator + weak_refs = map, C>(comp); + weak_refs.insert(temp.begin(), temp.end()); + } + + C get_comparator() { + return weak_refs.key_comp(); + } + void set_cct(CephContext *c) { cct = c; }