From f9373b4430e67cf95f66a736a745d5bad572dbd9 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 25 Jan 2019 15:28:12 +0100 Subject: [PATCH] base: new Allocator_avl::construct_metadata method The new method allows for the construction of a meta-data object inside the reserved space of the allocator's meta data. It thereby alleviates the need to copy the meta data object (via the assignment operator) as done by the traditional 'metadata' setter method. This, in turn, allows one to use non-copyable objects (like objects with constant member variables) as meta data. --- repos/base/include/base/allocator_avl.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/repos/base/include/base/allocator_avl.h b/repos/base/include/base/allocator_avl.h index 51896f9638..bce9fead39 100644 --- a/repos/base/include/base/allocator_avl.h +++ b/repos/base/include/base/allocator_avl.h @@ -19,6 +19,7 @@ #include #include #include +#include namespace Genode { @@ -353,11 +354,24 @@ class Genode::Allocator_avl_tpl : public Allocator_avl_base */ void metadata(void *addr, BMDT bmd) const { - Block *b = static_cast(_find_by_address((addr_t)addr)); + Block * const b = static_cast(_find_by_address((addr_t)addr)); if (b) *static_cast(b) = bmd; else throw Assign_metadata_failed(); } + /** + * Construct meta-data object in place + * + * \param ARGS arguments passed to the meta-data constuctor + */ + template + void construct_metadata(void *addr, ARGS &&... args) + { + Block * const b = static_cast(_find_by_address((addr_t)addr)); + if (b) construct_at(static_cast(b), args...); + else throw Assign_metadata_failed(); + } + /** * Return meta data that was attached to block at specified address */