Use backend global concept on template args

Wire the concept into the rest of the tree, being careful to avoid demanding the
result of fixed-pointing computation while tying the knot.
This commit is contained in:
Nathaniel Wesley Filardo
2021-08-23 21:26:56 +01:00
committed by Nathaniel Wesley Filardo
parent e530f5629a
commit 2be44d2e6f
6 changed files with 22 additions and 17 deletions

View File

@@ -43,13 +43,13 @@ namespace snmalloc
* provided externally, then it must be set explicitly with
* `init_message_queue`.
*/
template<typename SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobalsLazy) SharedStateHandle>
class CoreAllocator : public std::conditional_t<
SharedStateHandle::Options.CoreAllocIsPoolAllocated,
Pooled<CoreAllocator<SharedStateHandle>>,
NotPoolAllocated>
{
template<typename SharedStateHandle2>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle2>
friend class LocalAllocator;
/**

View File

@@ -5,7 +5,7 @@
namespace snmalloc
{
template<class SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
inline static void aggregate_stats(Stats& stats)
{
static_assert(
@@ -24,7 +24,7 @@ namespace snmalloc
}
#ifdef USE_SNMALLOC_STATS
template<class SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
inline static void print_all_stats(std::ostream& o, uint64_t dumpid = 0)
{
static_assert(
@@ -41,7 +41,7 @@ namespace snmalloc
}
}
#else
template<class SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
inline static void print_all_stats(void*& o, uint64_t dumpid = 0)
{
UNUSED(o);
@@ -49,7 +49,7 @@ namespace snmalloc
}
#endif
template<class SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
inline static void cleanup_unused()
{
#ifndef SNMALLOC_PASS_THROUGH
@@ -83,7 +83,7 @@ namespace snmalloc
allocators are empty. If you don't pass a pointer to a bool, then will
raise an error all the allocators are not empty.
*/
template<class SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
inline static void debug_check_empty(bool* result = nullptr)
{
#ifndef SNMALLOC_PASS_THROUGH
@@ -153,7 +153,7 @@ namespace snmalloc
#endif
}
template<class SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
inline static void debug_in_use(size_t count)
{
static_assert(

View File

@@ -59,7 +59,7 @@ namespace snmalloc
* core allocator must be provided externally by invoking the `init` method
* on this class *before* any allocation-related methods are called.
*/
template<class SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
class LocalAllocator
{
public:

View File

@@ -23,7 +23,7 @@ namespace snmalloc
{
template<
typename TT,
typename SharedStateHandle,
SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle,
PoolState<TT>& get_state()>
friend class Pool;
@@ -42,7 +42,9 @@ namespace snmalloc
* SingletonPoolState::pool is the default provider for the PoolState within
* the Pool class.
*/
template<typename T, typename SharedStateHandle>
template<
typename T,
SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
class SingletonPoolState
{
/**
@@ -113,7 +115,7 @@ namespace snmalloc
*/
template<
typename T,
typename SharedStateHandle,
SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle,
PoolState<T>& get_state() = SingletonPoolState<T, SharedStateHandle>::pool>
class Pool
{

View File

@@ -13,7 +13,7 @@ namespace snmalloc
public:
template<
typename TT,
typename SharedStateHandle,
SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle,
PoolState<TT>& get_state()>
friend class Pool;
template<class a, Construction c>
@@ -45,4 +45,4 @@ namespace snmalloc
return result;
}
};
} // namespace snmalloc
} // namespace snmalloc

View File

@@ -75,7 +75,7 @@ namespace snmalloc
class ChunkAllocator
{
public:
template<typename SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
static std::pair<CapPtr<void, CBChunk>, Metaslab*> alloc_chunk(
typename SharedStateHandle::LocalState& local_state,
sizeclass_t sizeclass,
@@ -130,7 +130,7 @@ namespace snmalloc
return {slab, meta};
}
template<typename SharedStateHandle>
template<SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle>
SNMALLOC_SLOW_PATH static void dealloc(
typename SharedStateHandle::LocalState& local_state,
ChunkRecord* p,
@@ -153,7 +153,10 @@ namespace snmalloc
* Backend allocator may use guard pages and separate area of
* address space to protect this from corruption.
*/
template<typename U, typename SharedStateHandle, typename... Args>
template<
typename U,
SNMALLOC_CONCEPT(ConceptBackendGlobals) SharedStateHandle,
typename... Args>
static U* alloc_meta_data(
typename SharedStateHandle::LocalState* local_state, Args&&... args)
{