Merge pull request #191 from nwf/aal-address_t

Allow the AAL to define address_t
This commit is contained in:
Matthew Parkinson
2020-05-23 08:26:29 +01:00
committed by GitHub
3 changed files with 29 additions and 5 deletions

View File

@@ -52,6 +52,31 @@ namespace snmalloc
template<class Arch>
struct AAL_Generic : Arch
{
/*
* Provide a default specification of address_t as uintptr_t for Arch-es
* that support IntegerPointers. Those Arch-es without IntegerPoihnters
* must explicitly give their address_t.
*
* This somewhat obtuse way of spelling the defaulting is necessary so
* that all arguments to std::conditional_t are valid, even if they
* wouldn't be valid in context. One might rather wish to say
*
* std::conditional_t<..., uintptr_t, Arch::address_t>
*
* but that requires that Arch::address_t always be given, precisely
* the thing we're trying to avoid with the conditional.
*/
struct default_address_t
{
using address_t = uintptr_t;
};
using address_t = typename std::conditional_t<
(Arch::aal_features & IntegerPointers) != 0,
default_address_t,
Arch>::address_t;
/**
* Prefetch a specific address.
*

View File

@@ -13,7 +13,7 @@ namespace snmalloc
* separated into two types, one for raw addresses and one for addresses that
* can be cast back to pointers.
*/
using address_t = uintptr_t;
using address_t = Aal::address_t;
/**
* Perform pointer arithmetic and return the adjusted pointer.
@@ -51,8 +51,7 @@ namespace snmalloc
{
static_assert(bits::next_pow2_const(alignment) == alignment);
return ((static_cast<size_t>(address_cast(p)) | size) & (alignment - 1)) ==
0;
return ((address_cast(p) | size) & (alignment - 1)) == 0;
}
/**

View File

@@ -17,7 +17,7 @@ namespace snmalloc
* are always the same, invalid pointer values with different sentinels are
* always different.
*/
template<uintptr_t OtherSentinel>
template<address_t OtherSentinel>
constexpr bool operator==(const InvalidPointer<OtherSentinel>&)
{
return Sentinel == OtherSentinel;
@@ -27,7 +27,7 @@ namespace snmalloc
* are always the same, invalid pointer values with different sentinels are
* always different.
*/
template<uintptr_t OtherSentinel>
template<address_t OtherSentinel>
constexpr bool operator!=(const InvalidPointer<OtherSentinel>&)
{
return Sentinel != OtherSentinel;