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.
This commit is contained in:
Norman Feske 2019-01-25 15:28:12 +01:00
parent 437e6c5653
commit f9373b4430
1 changed files with 15 additions and 1 deletions

View File

@ -19,6 +19,7 @@
#include <base/output.h>
#include <util/avl_tree.h>
#include <util/misc_math.h>
#include <util/construct_at.h>
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<Block *>(_find_by_address((addr_t)addr));
Block * const b = static_cast<Block *>(_find_by_address((addr_t)addr));
if (b) *static_cast<BMDT *>(b) = bmd;
else throw Assign_metadata_failed();
}
/**
* Construct meta-data object in place
*
* \param ARGS arguments passed to the meta-data constuctor
*/
template <typename... ARGS>
void construct_metadata(void *addr, ARGS &&... args)
{
Block * const b = static_cast<Block *>(_find_by_address((addr_t)addr));
if (b) construct_at<BMDT>(static_cast<BMDT *>(b), args...);
else throw Assign_metadata_failed();
}
/**
* Return meta data that was attached to block at specified address
*/