From be04918d4446a7e4ab997e255db6448db749c2a5 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Mon, 12 Aug 2013 14:05:38 +0200 Subject: [PATCH] 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 --- src/common/sharedptr_registry.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/common/sharedptr_registry.hpp b/src/common/sharedptr_registry.hpp index a62aa0d9ce313..6579bd4ba712f 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 *next) { + VPtr next_val; + Mutex::Locker l(lock); + typename map::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 *next) { VPtr next_val; Mutex::Locker l(lock); -- 2.39.5