From 3958ea50a06cc7661c02a90fa58b71554189fde2 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Thu, 4 Oct 2018 16:39:57 +0200 Subject: [PATCH] Allocator_avl: apply_any method Provide an `apply_any` method for accessing any member of the allocator, this is provided for destructing members of the allocator. Ref #2996 --- repos/base/include/base/allocator_avl.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/repos/base/include/base/allocator_avl.h b/repos/base/include/base/allocator_avl.h index 6cffcd0a6..51896f963 100644 --- a/repos/base/include/base/allocator_avl.h +++ b/repos/base/include/base/allocator_avl.h @@ -381,6 +381,26 @@ class Genode::Allocator_avl_tpl : public Allocator_avl_base _metadata.backing_store(md_bs); return ret; } + + /** + * Apply functor 'fn' to the metadata of an arbitrary + * member of the allocator. This method is provided for + * destructing each member of the allocator. Calling + * the method repeatedly without removing or inserting + * members will produce the same member. + */ + template + bool apply_any(FUNC const &fn) + { + addr_t addr = 0; + if (any_block_addr(&addr)) { + if (BMDT *b = metadata((void*)addr)) { + fn((BMDT&)*b); + return true; + } + } + return false; + } }; #endif /* _INCLUDE__BASE__ALLOCATOR_AVL_H_ */