]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
sharedptr_registry: add a variant of get_next() and the empty() method
authorLoic Dachary <loic@dachary.org>
Mon, 12 Aug 2013 12:05:38 +0000 (14:05 +0200)
committerSamuel Just <sam.just@inktank.com>
Fri, 19 Sep 2014 22:58:08 +0000 (15:58 -0700)
The SharedPtrRegistry::get_next() method with a value of type VPtr
instead of V is added because it is sometime more convenient to not
copy the value when walking the registry. The
SharedPtrRegistry::empty() predicate method is added.

Signed-off-by: Loic Dachary <loic@dachary.org>
(cherry picked from commit be04918d4446a7e4ab997e255db6448db749c2a5)

src/common/sharedptr_registry.hpp

index a62aa0d9ce31384de251525b763c00f985038a99..6579bd4ba712f9055aed31ca9e8cc927768881e9 100644 (file)
@@ -58,6 +58,26 @@ public:
     lock("SharedPtrRegistry::lock")
   {}
 
+  bool empty() {
+    Mutex::Locker l(lock);
+    return contents.empty();
+  }
+
+  bool get_next(const K &key, pair<K, VPtr> *next) {
+    VPtr next_val;
+    Mutex::Locker l(lock);
+    typename map<K, WeakVPtr>::iterator i = contents.upper_bound(key);
+    while (i != contents.end() &&
+          !(next_val = i->second.lock()))
+      ++i;
+    if (i == contents.end())
+      return false;
+    if (next)
+      *next = make_pair(i->first, next_val);
+    return true;
+  }
+
+  
   bool get_next(const K &key, pair<K, V> *next) {
     VPtr next_val;
     Mutex::Locker l(lock);