diff --git a/src/pal/pal_concept.h b/src/pal/pal_concept.h index 42e034b..d8a328e 100644 --- a/src/pal/pal_concept.h +++ b/src/pal/pal_concept.h @@ -8,17 +8,29 @@ namespace snmalloc { + + /* + * These concepts enforce that these are indeed constants that fit in the + * desired types. (This is subtly different from saying that they are the + * required types; C++ may handle constants without much regard for their + * claimed type.) + */ + /** - * PALs must advertize the bit vector of their supported features and the - * platform's page size. This concept enforces that these are indeed - * constants that fit in the desired types. (This is subtly different from - * saying that they are the required types; C++ may handle constants without - * much regard for their claimed type.) + * PALs must advertize the bit vector of their supported features. */ template - concept ConceptPAL_static_members = requires() + concept ConceptPAL_static_features = requires() { typename std::integral_constant; + }; + + /** + * PALs must advertise their page size + */ + template + concept ConceptPAL_static_sizes = requires() + { typename std::integral_constant; }; @@ -93,7 +105,8 @@ namespace snmalloc */ template concept ConceptPAL = - ConceptPAL_static_members && + ConceptPAL_static_features && + ConceptPAL_static_sizes && ConceptPAL_error && ConceptPAL_memops && (!pal_supports || diff --git a/src/pal/pal_noalloc.h b/src/pal/pal_noalloc.h index b5c286e..2c5c61a 100644 --- a/src/pal/pal_noalloc.h +++ b/src/pal/pal_noalloc.h @@ -4,23 +4,29 @@ #pragma once #include "../aal/aal.h" +#include "pal_concept.h" #include "pal_consts.h" #include namespace snmalloc { +#ifdef __cpp_concepts + /** + * The minimal subset of a PAL that we need for delegation + */ + template + concept PALNoAllocBase = ConceptPAL_static_sizes&& ConceptPAL_error; +#endif + /** * Platform abstraction layer that does not allow allocation. * * This is a minimal PAL for pre-reserved memory regions, where the * address-space manager is initialised with all of the memory that it will * ever use. - * - * It takes an error handler delegate as a template argument. This is - * expected to forward to the default PAL in most cases. */ - template + template struct PALNoAlloc { /** @@ -29,14 +35,14 @@ namespace snmalloc */ static constexpr uint64_t pal_features = NoAllocation; - static constexpr size_t page_size = Aal::smallest_page_size; + static constexpr size_t page_size = BasePAL::page_size; /** * Print a stack trace. */ static void print_stack_trace() { - ErrorHandler::print_stack_trace(); + BasePAL::print_stack_trace(); } /** @@ -44,7 +50,7 @@ namespace snmalloc */ [[noreturn]] static void error(const char* const str) noexcept { - ErrorHandler::error(str); + BasePAL::error(str); } /**