From 01bd77b356e8b3f1d468d087a98f0b48caa4f69c Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 21 Feb 2019 17:53:15 +0000 Subject: [PATCH] Remove some ugly templated things. Replace them with some very simple constexpr things. This is what the code used to look like, but it appears that I fundamentally misunderstood why it didn't work. This version should be a lot more maintainable. --- src/mem/largealloc.h | 45 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index d2a8c5e..5ca8cd7 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -116,40 +116,6 @@ namespace snmalloc lazy_decommit_guard.clear(); } - private: - /** - * Query whether the PAL given by `P` supports a specific feature. This is - * used internally in templated functions where PAL can't be referenced in - * an `enable_if` context. - */ - template - constexpr static bool pal_supports() - { - return (P::pal_features & F) == F; - } - /** - * Wrapper that is instantiated only if the memory provider supports low - * memory notifications and forwards the call to the memory provider. - */ - template - ALWAYSINLINE uint64_t low_mem_epoch( - std::enable_if_t(), int> = 0) - { - return PAL::low_memory_epoch(); - } - - /** - * Default implementations that is instantiated when the memory provider - * does not support low memory notifications and always returns 0 for the - * epoch. - */ - template - ALWAYSINLINE uint64_t low_memory_epoch( - std::enable_if_t(), int> = 0) - { - return 0; - } - public: /** * Stack of large allocations that have been returned for reuse. @@ -207,7 +173,7 @@ namespace snmalloc template constexpr static bool pal_supports() { - return pal_supports(); + return (PAL::pal_features & F) == F; } /** @@ -218,7 +184,14 @@ namespace snmalloc ALWAYSINLINE uint64_t low_memory_epoch() { - return low_mem_epoch(); + if constexpr (pal_supports()) + { + return PAL::low_memory_epoch(); + } + else + { + return 0; + } } ALWAYSINLINE void lazy_decommit_if_needed()