Cleanup and made new variant work with Verona
This commit is contained in:
@@ -785,4 +785,10 @@ namespace snmalloc
|
||||
return debug_is_empty_impl(result);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename SharedStateHandle>
|
||||
using AllocPool = Pool<
|
||||
CoreAllocator<SharedStateHandle>,
|
||||
SharedStateHandle,
|
||||
SharedStateHandle::pool>;
|
||||
} // namespace snmalloc
|
||||
|
||||
@@ -11,8 +11,7 @@ namespace snmalloc
|
||||
static_assert(
|
||||
SharedStateHandle::Options.CoreAllocIsPoolAllocated,
|
||||
"Global statistics are available only for pool-allocated configurations");
|
||||
auto* alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
|
||||
auto* alloc = AllocPool<SharedStateHandle>::iterate();
|
||||
|
||||
while (alloc != nullptr)
|
||||
{
|
||||
@@ -20,9 +19,7 @@ namespace snmalloc
|
||||
if (a != nullptr)
|
||||
stats.add(*a);
|
||||
stats.add(alloc->stats());
|
||||
alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
|
||||
alloc);
|
||||
alloc = AllocPool<SharedStateHandle>::iterate(alloc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,17 +30,14 @@ namespace snmalloc
|
||||
static_assert(
|
||||
SharedStateHandle::Options.CoreAllocIsPoolAllocated,
|
||||
"Global statistics are available only for pool-allocated configurations");
|
||||
auto alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
|
||||
auto alloc = AllocPool<SharedStateHandle>::iterate();
|
||||
|
||||
while (alloc != nullptr)
|
||||
{
|
||||
auto stats = alloc->stats();
|
||||
if (stats != nullptr)
|
||||
stats->template print<decltype(alloc)>(o, dumpid, alloc->id());
|
||||
alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
|
||||
alloc);
|
||||
alloc = AllocPool<SharedStateHandle>::iterate(alloc);
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -66,8 +60,7 @@ namespace snmalloc
|
||||
// allocators that are not currently in use by any thread.
|
||||
// One atomic operation to extract the stack, another to restore it.
|
||||
// Handling the message queue for each stack is non-atomic.
|
||||
auto* first =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::extract();
|
||||
auto* first = AllocPool<SharedStateHandle>::extract();
|
||||
auto* alloc = first;
|
||||
decltype(alloc) last;
|
||||
|
||||
@@ -77,13 +70,10 @@ namespace snmalloc
|
||||
{
|
||||
alloc->flush();
|
||||
last = alloc;
|
||||
alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::extract(
|
||||
alloc);
|
||||
alloc = AllocPool<SharedStateHandle>::extract(alloc);
|
||||
}
|
||||
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::restore(
|
||||
first, last);
|
||||
AllocPool<SharedStateHandle>::restore(first, last);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -102,8 +92,7 @@ namespace snmalloc
|
||||
"Global status is available only for pool-allocated configurations");
|
||||
// This is a debugging function. It checks that all memory from all
|
||||
// allocators has been freed.
|
||||
auto* alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
|
||||
auto* alloc = AllocPool<SharedStateHandle>::iterate();
|
||||
|
||||
# ifdef SNMALLOC_TRACING
|
||||
std::cout << "debug check empty: first " << alloc << std::endl;
|
||||
@@ -117,8 +106,7 @@ namespace snmalloc
|
||||
std::cout << "debug_check_empty: Check all allocators!" << std::endl;
|
||||
# endif
|
||||
done = true;
|
||||
alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
|
||||
alloc = AllocPool<SharedStateHandle>::iterate();
|
||||
okay = true;
|
||||
|
||||
while (alloc != nullptr)
|
||||
@@ -140,9 +128,7 @@ namespace snmalloc
|
||||
# ifdef SNMALLOC_TRACING
|
||||
std::cout << "debug check empty: okay = " << okay << std::endl;
|
||||
# endif
|
||||
alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
|
||||
alloc);
|
||||
alloc = AllocPool<SharedStateHandle>::iterate(alloc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,14 +141,11 @@ namespace snmalloc
|
||||
// Redo check so abort is on allocator with allocation left.
|
||||
if (!okay)
|
||||
{
|
||||
alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
|
||||
alloc = AllocPool<SharedStateHandle>::iterate();
|
||||
while (alloc != nullptr)
|
||||
{
|
||||
alloc->debug_is_empty(nullptr);
|
||||
alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
|
||||
alloc);
|
||||
alloc = AllocPool<SharedStateHandle>::iterate(alloc);
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -176,8 +159,7 @@ namespace snmalloc
|
||||
static_assert(
|
||||
SharedStateHandle::Options.CoreAllocIsPoolAllocated,
|
||||
"Global status is available only for pool-allocated configurations");
|
||||
auto alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
|
||||
auto alloc = AllocPool<SharedStateHandle>::iterate();
|
||||
while (alloc != nullptr)
|
||||
{
|
||||
if (alloc->debug_is_in_use())
|
||||
@@ -188,9 +170,7 @@ namespace snmalloc
|
||||
}
|
||||
count--;
|
||||
}
|
||||
alloc =
|
||||
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
|
||||
alloc);
|
||||
alloc = AllocPool<SharedStateHandle>::iterate(alloc);
|
||||
|
||||
if (count != 0)
|
||||
{
|
||||
|
||||
@@ -380,7 +380,7 @@ namespace snmalloc
|
||||
// Initialise the global allocator structures
|
||||
ensure_init();
|
||||
// Grab an allocator for this thread.
|
||||
init(Pool<CoreAlloc, SharedStateHandle>::acquire(&(this->local_cache)));
|
||||
init(AllocPool<SharedStateHandle>::acquire(&(this->local_cache)));
|
||||
}
|
||||
|
||||
// Return all state in the fast allocator and release the underlying
|
||||
@@ -402,7 +402,7 @@ namespace snmalloc
|
||||
// Return underlying allocator to the system.
|
||||
if constexpr (SharedStateHandle::Options.CoreAllocOwnsLocalState)
|
||||
{
|
||||
Pool<CoreAlloc, SharedStateHandle>::release(core_alloc);
|
||||
AllocPool<SharedStateHandle>::release(core_alloc);
|
||||
}
|
||||
|
||||
// Set up thread local allocator to look like
|
||||
|
||||
@@ -21,7 +21,10 @@ namespace snmalloc
|
||||
template<class T>
|
||||
class PoolState
|
||||
{
|
||||
template<typename TT, typename SharedStateHandle>
|
||||
template<
|
||||
typename TT,
|
||||
typename SharedStateHandle,
|
||||
PoolState<TT>& get_state()>
|
||||
friend class Pool;
|
||||
|
||||
private:
|
||||
@@ -34,35 +37,28 @@ namespace snmalloc
|
||||
};
|
||||
|
||||
/**
|
||||
* Class used to instantiate non-allocator pools using a Singleton PoolState.
|
||||
* Class used to instantiate a global non-allocator PoolState.
|
||||
*/
|
||||
template<typename T, typename SharedStateHandle>
|
||||
class PoolStateHandle
|
||||
template<typename T>
|
||||
class SingletonPoolState
|
||||
{
|
||||
static PoolState<T>& pool_state =
|
||||
Singleton<PoolState<T>, PoolStateHandle::make_state>::get();
|
||||
|
||||
static PoolState<T>* make_state()
|
||||
{
|
||||
return ChunkAllocator::alloc_meta_data<PoolState<T>, SharedStateHandle>(
|
||||
nullptr);
|
||||
}
|
||||
static inline PoolState<T> state;
|
||||
|
||||
public:
|
||||
static PoolState<T>& pool()
|
||||
{
|
||||
return pool_state;
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename SharedStateHandle>
|
||||
template<typename T, typename SharedStateHandle, PoolState<T>& get_state()>
|
||||
class Pool
|
||||
{
|
||||
public:
|
||||
template<typename... Args>
|
||||
static T* acquire(Args&&... args)
|
||||
{
|
||||
PoolState<T>& pool = SharedStateHandle::pool();
|
||||
PoolState<T>& pool = get_state();
|
||||
T* p = pool.stack.pop();
|
||||
|
||||
if (p != nullptr)
|
||||
@@ -99,14 +95,14 @@ namespace snmalloc
|
||||
// is returned without the constructor being run, so the object is reused
|
||||
// without re-initialisation.
|
||||
p->reset_in_use();
|
||||
SharedStateHandle::pool().stack.push(p);
|
||||
get_state().stack.push(p);
|
||||
}
|
||||
|
||||
static T* extract(T* p = nullptr)
|
||||
{
|
||||
// Returns a linked list of all objects in the stack, emptying the stack.
|
||||
if (p == nullptr)
|
||||
return SharedStateHandle::pool().stack.pop_all();
|
||||
return get_state().stack.pop_all();
|
||||
|
||||
return p->next;
|
||||
}
|
||||
@@ -120,13 +116,13 @@ namespace snmalloc
|
||||
{
|
||||
// Pushes a linked list of objects onto the stack. Use to put a linked
|
||||
// list returned by extract back onto the stack.
|
||||
SharedStateHandle::pool().stack.push(first, last);
|
||||
get_state().stack.push(first, last);
|
||||
}
|
||||
|
||||
static T* iterate(T* p = nullptr)
|
||||
{
|
||||
if (p == nullptr)
|
||||
return SharedStateHandle::pool().list;
|
||||
return get_state().list;
|
||||
|
||||
return p->list_next;
|
||||
}
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
template<class T>
|
||||
class PoolState;
|
||||
|
||||
template<class T>
|
||||
class Pooled
|
||||
{
|
||||
private:
|
||||
template<class TT, typename SharedStateHandle>
|
||||
public:
|
||||
template<
|
||||
typename TT,
|
||||
typename SharedStateHandle,
|
||||
PoolState<TT>& get_state()>
|
||||
friend class Pool;
|
||||
template<class a, Construction c>
|
||||
friend class MPMCStack;
|
||||
|
||||
Reference in New Issue
Block a user