Provide a generic PAL feature detection mechanism.

We can support up to 64 optional features, currently only one is used.
This commit is contained in:
David Chisnall
2019-02-21 14:00:04 +00:00
committed by David Chisnall
parent 80630a359f
commit a24e6270cc
8 changed files with 43 additions and 18 deletions

View File

@@ -1004,7 +1004,7 @@ namespace snmalloc
static_assert(
std::remove_reference_t<decltype(
large_allocator
.memory_provider)>::supports_low_memory_notification,
.memory_provider)>::pal_supports<LowMemoryNotification>(),
"A lazy decommit strategy cannot be implemented on platforms "
"without low memory notifications");
}

View File

@@ -47,7 +47,6 @@ namespace snmalloc
template<class PAL>
class MemoryProviderStateMixin : public PAL
{
using PAL::supports_low_memory_notification;
std::atomic_flag lock = ATOMIC_FLAG_INIT;
size_t bump;
size_t remaining;
@@ -117,13 +116,21 @@ namespace snmalloc
lazy_decommit_guard.clear();
}
public:
template<PalFeatures F, typename P = PAL>
constexpr static bool pal_supports()
{
return (P::pal_features & F) == F;
}
private:
/**
* Wrapper that is instantiated only if the memory provider supports low
* memory notifications and forwards the call to the memory provider.
*/
template<typename M>
ALWAYSINLINE uint64_t low_mem_epoch(
std::enable_if_t<M::supports_low_memory_notification, int> = 0)
std::enable_if_t<pal_supports<LowMemoryNotification, M>(), int> = 0)
{
return PAL::low_memory_epoch();
}
@@ -135,7 +142,7 @@ namespace snmalloc
*/
template<typename M>
ALWAYSINLINE uint64_t low_memory_epoch(
std::enable_if_t<!M::supports_low_memory_notification, int> = 0)
std::enable_if_t<!pal_supports<LowMemoryNotification, M>(), int> = 0)
{
return 0;
}