NFC: Introduce pointer domestication backend support

`capptr_domesticate<Backend>(Backend::LocalState*, CapPtr<T, B>)` is the
intended affordance for conversion to covert from a `CapPtr<T, B>` with
`B::wildness` `Wild` to a `CapPtr<>` with `B::with_wildness<Tame>` and thence
plumbed into the rest of the machinery.

David added the SFINAE wrapper so that `Backend`-s now don't need to implement a
domestication callback; instead, if the `Backend` does not provide a
`capptr_domesticate` function, a default, which just does an explicit type cast,
will be used instead.

This is not yet hooked into the rest of the tree.

Co-authored-by: David Chisnall <David.Chisnall@microsoft.com>
This commit is contained in:
Nathaniel Wesley Filardo
2021-08-16 21:03:29 +01:00
committed by Nathaniel Wesley Filardo
parent 7e53a2e82a
commit 1a608e6066
6 changed files with 133 additions and 1 deletions

View File

@@ -1,7 +1,6 @@
#pragma once
#include "../ds/defines.h"
#include "../mem/remotecache.h"
namespace snmalloc
{
@@ -137,4 +136,54 @@ namespace snmalloc
return true;
}
namespace detail
{
/**
* SFINAE helper, calls capptr_domesticate in the backend if it exists.
*/
template<
SNMALLOC_CONCEPT(ConceptBackendDomestication) Backend,
typename T,
SNMALLOC_CONCEPT(capptr::ConceptBound) B>
SNMALLOC_FAST_PATH_INLINE auto
capptr_domesticate(typename Backend::LocalState* ls, CapPtr<T, B> p, int)
-> decltype(Backend::capptr_domesticate(ls, p))
{
return Backend::capptr_domesticate(ls, p);
}
/**
* SFINAE helper. If the back end does not provide special handling for
* domestication then assume all wild pointers can be domesticated.
*/
template<
SNMALLOC_CONCEPT(ConceptBackendGlobals) Backend,
typename T,
SNMALLOC_CONCEPT(capptr::ConceptBound) B>
SNMALLOC_FAST_PATH_INLINE auto
capptr_domesticate(typename Backend::LocalState*, CapPtr<T, B> p, long)
{
return CapPtr<
T,
typename B::template with_wildness<capptr::dimension::Wildness::Tame>>(
p.unsafe_ptr());
}
} // namespace detail
/**
* Wrapper that calls `Backend::capptr_domesticate` if and only if it is
* implemented. If it is not implemented then this assumes that any wild
* pointer can be domesticated.
*/
template<
SNMALLOC_CONCEPT(ConceptBackendGlobals) Backend,
typename T,
SNMALLOC_CONCEPT(capptr::ConceptBound) B>
SNMALLOC_FAST_PATH_INLINE auto
capptr_domesticate(typename Backend::LocalState* ls, CapPtr<T, B> p)
{
return detail::capptr_domesticate<Backend>(ls, p, 0);
}
} // namespace snmalloc
#include "../mem/remotecache.h"