]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
shared_cache: reduce duplication between get_next's
authorSamuel Just <sjust@redhat.com>
Thu, 15 Jan 2015 05:09:45 +0000 (21:09 -0800)
committerSamuel Just <sjust@redhat.com>
Thu, 15 Jan 2015 18:10:22 +0000 (10:10 -0800)
Signed-off-by: Samuel Just <sjust@redhat.com>
src/common/shared_cache.hpp

index 7bdf03ee24e35edc617b4c799d5beb0cfda7096d..aaa47f04f3717faedd830ec3cd32bcfa91425805 100644 (file)
@@ -227,25 +227,14 @@ public:
     return true;
   }
   bool get_next(const K &key, pair<K, V> *next) {
-    pair<K, V> r;
-    {
-      Mutex::Locker l(lock);
-      VPtr next_val;
-      typename map<K, pair<WeakVPtr, V*> >::iterator i = weak_refs.upper_bound(key);
-
-      while (i != weak_refs.end() &&
-            !(next_val = i->second.first.lock()))
-       ++i;
-
-      if (i == weak_refs.end())
-       return false;
-
-      if (next)
-       r = make_pair(i->first, *next_val);
-    }
-    if (next)
-      *next = r;
-    return true;
+    pair<K, VPtr> r;
+    bool found = get_next(key, &r);
+    if (!found || !next)
+      return found;
+    next->first = r.first;
+    assert(r.second);
+    next->second = *(r.second);
+    return found;
   }
 
   VPtr lookup(const K& key) {