Made alloc_chunk typed
Alloc_chunk now allocates and calls the constructor.
This commit is contained in:
committed by
Matthew Parkinson
parent
2d831920ea
commit
f88bcdbf58
@@ -132,11 +132,11 @@ namespace snmalloc
|
||||
* Primitive allocator for structure that are required before
|
||||
* the allocator can be running.
|
||||
*/
|
||||
template<size_t alignment = 64>
|
||||
void* alloc_chunk(size_t size)
|
||||
template<typename T, size_t alignment, typename... Args>
|
||||
T* alloc_chunk(Args&&... args)
|
||||
{
|
||||
// Cache line align
|
||||
size = bits::align_up(size, 64);
|
||||
size_t size = bits::align_up(sizeof(T), 64);
|
||||
|
||||
void* p;
|
||||
{
|
||||
@@ -169,7 +169,7 @@ namespace snmalloc
|
||||
PAL::template notify_using<NoZero>(
|
||||
(void*)page_start, page_end - page_start);
|
||||
|
||||
return p;
|
||||
return new (p) T(std::forward<Args...>(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,6 +95,9 @@ namespace snmalloc
|
||||
static_assert(
|
||||
sizeof(PagemapEntry) == sizeof(Leaf), "Should be the same size");
|
||||
|
||||
static_assert(
|
||||
sizeof(PagemapEntry) == PAGEMAP_NODE_SIZE, "Should be the same size");
|
||||
|
||||
// Init removed as not required as this is only ever a global
|
||||
// cl is generating a memset of zero, which will be a problem
|
||||
// in libc/ucrt bring up. On ucrt this will run after the first
|
||||
@@ -121,8 +124,7 @@ namespace snmalloc
|
||||
value, (PagemapEntry*)LOCKED_ENTRY, std::memory_order_relaxed))
|
||||
{
|
||||
auto& v = default_memory_provider;
|
||||
value =
|
||||
(PagemapEntry*)v.alloc_chunk<OS_PAGE_SIZE>(PAGEMAP_NODE_SIZE);
|
||||
value = v.alloc_chunk<PagemapEntry,OS_PAGE_SIZE>();
|
||||
e->store(value, std::memory_order_release);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace snmalloc
|
||||
{
|
||||
private:
|
||||
friend Pooled<T>;
|
||||
template <typename TT>
|
||||
friend class MemoryProviderStateMixin;
|
||||
|
||||
std::atomic_flag lock = ATOMIC_FLAG_INIT;
|
||||
MPMCStack<T, PreZeroed> stack;
|
||||
@@ -33,8 +35,7 @@ namespace snmalloc
|
||||
|
||||
static Pool* make(MemoryProvider& memory_provider) noexcept
|
||||
{
|
||||
auto r = memory_provider.alloc_chunk(sizeof(Pool));
|
||||
return new (r) Pool(memory_provider);
|
||||
return memory_provider.template alloc_chunk<Pool,0, MemoryProvider&>(memory_provider);
|
||||
}
|
||||
|
||||
static Pool* make() noexcept
|
||||
@@ -50,10 +51,8 @@ namespace snmalloc
|
||||
if (p != nullptr)
|
||||
return p;
|
||||
|
||||
p = (T*)memory_provider
|
||||
.template alloc_chunk<bits::next_pow2_const(sizeof(T))>(sizeof(T));
|
||||
|
||||
new (p) T(std::forward<Args...>(args)...);
|
||||
p = memory_provider
|
||||
.template alloc_chunk<T, bits::next_pow2_const(sizeof(T))>(std::forward<Args...>(args)...);
|
||||
|
||||
FlagLock f(lock);
|
||||
p->list_next = list;
|
||||
|
||||
Reference in New Issue
Block a user