Add C++ concept for PAL

This will not be used unless the C++ standard version is raised to 20.  As
concepts and C++20 more generally are quite new, this does not do so.
Nevertheless, the use of concepts can improve the local development experience
as type mismatches are discovered earlier (at template invocation rather than
only during expansion).
This commit is contained in:
Nathaniel Filardo
2020-09-02 12:41:09 +01:00
committed by Matthew Parkinson
parent a3d54779c8
commit 3e21ea1f65
7 changed files with 156 additions and 6 deletions

View File

@@ -13,7 +13,7 @@ namespace snmalloc
* It cannot unreserve memory, so this does not require the
* usual complexity of a buddy allocator.
*/
template<typename PAL>
template<SNMALLOC_CONCEPT(ConceptPAL) PAL>
class AddressSpaceManager : public PAL
{
/**

View File

@@ -14,7 +14,7 @@
namespace snmalloc
{
template<class PAL>
template<SNMALLOC_CONCEPT(ConceptPAL) PAL>
class MemoryProviderStateMixin;
class Largeslab : public Baseslab
@@ -24,7 +24,7 @@ namespace snmalloc
private:
template<class a, Construction c>
friend class MPMCStack;
template<class PAL>
template<SNMALLOC_CONCEPT(ConceptPAL) PAL>
friend class MemoryProviderStateMixin;
std::atomic<Largeslab*> next;
@@ -56,7 +56,7 @@ namespace snmalloc
// This represents the state that the large allcoator needs to add to the
// global state of the allocator. This is currently stored in the memory
// provider, so we add this in.
template<class PAL>
template<SNMALLOC_CONCEPT(ConceptPAL) PAL>
class MemoryProviderStateMixin : public PalNotificationObject, public PAL
{
/**

View File

@@ -2,6 +2,7 @@
#include "../ds/flaglock.h"
#include "../ds/mpmcstack.h"
#include "../pal/pal_concept.h"
#include "pooled.h"
namespace snmalloc
@@ -21,7 +22,7 @@ namespace snmalloc
{
private:
friend Pooled<T>;
template<typename TT>
template<SNMALLOC_CONCEPT(ConceptPAL) PAL>
friend class MemoryProviderStateMixin;
std::atomic_flag lock = ATOMIC_FLAG_INIT;