0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

ircd::allocator::node: Add scope usage convenience.

This commit is contained in:
Jason Volk 2023-02-05 18:44:08 -08:00
parent a0d565b2a4
commit b7bd92097a

View file

@ -38,13 +38,27 @@ template<class T>
struct ircd::allocator::node
{
struct allocator;
struct monotonic;
struct scope;
T *next {nullptr};
node() = default;
};
/// The container will use provided node when it calls for an allocation during
/// the lifetime of this object. Construct this object ahead of the insertion.
template<class T>
struct ircd::allocator::node<T>::scope
{
node<T> *state;
template<class C,
class N>
scope(C &container, N &node);
scope(const scope &) = delete;
~scope() noexcept;
};
/// The actual template passed to containers for using the allocator.
///
/// See the notes for ircd::allocator::fixed::allocator for details.
@ -129,3 +143,31 @@ struct ircd::allocator::node<T>::allocator
return &a == &b;
}
};
template<class T>
template<class C,
class N>
inline
ircd::allocator::node<T>::scope::scope(C &container,
N &node)
:state
{
container.get_allocator().s
}
{
using value_type = typename C::value_type;
assert(state);
assert(!state->next);
state->next = reinterpret_cast<value_type *>(&node);
}
template<class T>
inline
ircd::allocator::node<T>::scope::~scope()
noexcept
{
assert(state);
assert(state->next);
state->next = nullptr;
}