summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Dachary <loic@dachary.org>2013-08-12 14:05:38 +0200
committerLoic Dachary <loic@dachary.org>2013-08-22 02:10:58 +0200
commitbe04918d4446a7e4ab997e255db6448db749c2a5 (patch)
tree5ba87a7c76317e442f6698152a0b685380304eaf
parent17859e147743fde5e160ad951d33afa57556f9b8 (diff)
downloadceph-be04918d4446a7e4ab997e255db6448db749c2a5.tar.gz
sharedptr_registry: add a variant of get_next() and the empty() method
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>
-rw-r--r--src/common/sharedptr_registry.hpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/common/sharedptr_registry.hpp b/src/common/sharedptr_registry.hpp
index a62aa0d9ce3..6579bd4ba71 100644
--- a/src/common/sharedptr_registry.hpp
+++ b/src/common/sharedptr_registry.hpp
@@ -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);