Moved SharedStateHandle to Pool class instead of methods since all of them use it

This commit is contained in:
Istvan Haller
2021-08-23 20:08:27 +01:00
parent c89a085c90
commit 769c61e716
4 changed files with 40 additions and 36 deletions

View File

@@ -11,8 +11,8 @@ namespace snmalloc
static_assert(
SharedStateHandle::Options.CoreAllocIsPoolAllocated,
"Global statistics are available only for pool-allocated configurations");
auto* alloc = Pool<CoreAllocator<SharedStateHandle>>::template iterate<
SharedStateHandle>();
auto* alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
while (alloc != nullptr)
{
@@ -20,8 +20,9 @@ namespace snmalloc
if (a != nullptr)
stats.add(*a);
stats.add(alloc->stats());
alloc = Pool<CoreAllocator<SharedStateHandle>>::template iterate<
SharedStateHandle>(alloc);
alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
alloc);
}
}
@@ -32,16 +33,17 @@ namespace snmalloc
static_assert(
SharedStateHandle::Options.CoreAllocIsPoolAllocated,
"Global statistics are available only for pool-allocated configurations");
auto alloc = Pool<CoreAllocator<SharedStateHandle>>::template iterate<
SharedStateHandle>();
auto alloc =
Pool<CoreAllocator<SharedStateHandle>, 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>>::template iterate<
SharedStateHandle>(alloc);
alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
alloc);
}
}
#else
@@ -64,7 +66,8 @@ 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>>::extract();
auto* first =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::extract();
auto* alloc = first;
decltype(alloc) last;
@@ -74,10 +77,13 @@ namespace snmalloc
{
alloc->flush();
last = alloc;
alloc = Pool<CoreAllocator<SharedStateHandle>>::extract(alloc);
alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::extract(
alloc);
}
Pool<CoreAllocator<SharedStateHandle>>::restore(first, last);
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::restore(
first, last);
}
#endif
}
@@ -96,8 +102,8 @@ 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>>::template iterate<
SharedStateHandle>();
auto* alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
# ifdef SNMALLOC_TRACING
std::cout << "debug check empty: first " << alloc << std::endl;
@@ -111,8 +117,8 @@ namespace snmalloc
std::cout << "debug_check_empty: Check all allocators!" << std::endl;
# endif
done = true;
alloc = Pool<CoreAllocator<SharedStateHandle>>::template iterate<
SharedStateHandle>();
alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
okay = true;
while (alloc != nullptr)
@@ -134,8 +140,9 @@ namespace snmalloc
# ifdef SNMALLOC_TRACING
std::cout << "debug check empty: okay = " << okay << std::endl;
# endif
alloc = Pool<CoreAllocator<SharedStateHandle>>::template iterate<
SharedStateHandle>(alloc);
alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
alloc);
}
}
@@ -148,13 +155,14 @@ namespace snmalloc
// Redo check so abort is on allocator with allocation left.
if (!okay)
{
alloc = Pool<CoreAllocator<SharedStateHandle>>::template iterate<
SharedStateHandle>();
alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
while (alloc != nullptr)
{
alloc->debug_is_empty(nullptr);
alloc = Pool<CoreAllocator<SharedStateHandle>>::template iterate<
SharedStateHandle>(alloc);
alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
alloc);
}
}
#else
@@ -168,8 +176,8 @@ namespace snmalloc
static_assert(
SharedStateHandle::Options.CoreAllocIsPoolAllocated,
"Global status is available only for pool-allocated configurations");
auto alloc = Pool<CoreAllocator<SharedStateHandle>>::template iterate<
SharedStateHandle>();
auto alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate();
while (alloc != nullptr)
{
if (alloc->debug_is_in_use())
@@ -180,8 +188,9 @@ namespace snmalloc
}
count--;
}
alloc = Pool<CoreAllocator<SharedStateHandle>>::template iterate<
SharedStateHandle>(alloc);
alloc =
Pool<CoreAllocator<SharedStateHandle>, SharedStateHandle>::iterate(
alloc);
if (count != 0)
{