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
|
* Primitive allocator for structure that are required before
|
||||||
* the allocator can be running.
|
* the allocator can be running.
|
||||||
*/
|
*/
|
||||||
template<size_t alignment = 64>
|
template<typename T, size_t alignment, typename... Args>
|
||||||
void* alloc_chunk(size_t size)
|
T* alloc_chunk(Args&&... args)
|
||||||
{
|
{
|
||||||
// Cache line align
|
// Cache line align
|
||||||
size = bits::align_up(size, 64);
|
size_t size = bits::align_up(sizeof(T), 64);
|
||||||
|
|
||||||
void* p;
|
void* p;
|
||||||
{
|
{
|
||||||
@@ -169,7 +169,7 @@ namespace snmalloc
|
|||||||
PAL::template notify_using<NoZero>(
|
PAL::template notify_using<NoZero>(
|
||||||
(void*)page_start, page_end - page_start);
|
(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(
|
static_assert(
|
||||||
sizeof(PagemapEntry) == sizeof(Leaf), "Should be the same size");
|
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
|
// Init removed as not required as this is only ever a global
|
||||||
// cl is generating a memset of zero, which will be a problem
|
// 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
|
// 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))
|
value, (PagemapEntry*)LOCKED_ENTRY, std::memory_order_relaxed))
|
||||||
{
|
{
|
||||||
auto& v = default_memory_provider;
|
auto& v = default_memory_provider;
|
||||||
value =
|
value = v.alloc_chunk<PagemapEntry,OS_PAGE_SIZE>();
|
||||||
(PagemapEntry*)v.alloc_chunk<OS_PAGE_SIZE>(PAGEMAP_NODE_SIZE);
|
|
||||||
e->store(value, std::memory_order_release);
|
e->store(value, std::memory_order_release);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ namespace snmalloc
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
friend Pooled<T>;
|
friend Pooled<T>;
|
||||||
|
template <typename TT>
|
||||||
|
friend class MemoryProviderStateMixin;
|
||||||
|
|
||||||
std::atomic_flag lock = ATOMIC_FLAG_INIT;
|
std::atomic_flag lock = ATOMIC_FLAG_INIT;
|
||||||
MPMCStack<T, PreZeroed> stack;
|
MPMCStack<T, PreZeroed> stack;
|
||||||
@@ -33,8 +35,7 @@ namespace snmalloc
|
|||||||
|
|
||||||
static Pool* make(MemoryProvider& memory_provider) noexcept
|
static Pool* make(MemoryProvider& memory_provider) noexcept
|
||||||
{
|
{
|
||||||
auto r = memory_provider.alloc_chunk(sizeof(Pool));
|
return memory_provider.template alloc_chunk<Pool,0, MemoryProvider&>(memory_provider);
|
||||||
return new (r) Pool(memory_provider);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Pool* make() noexcept
|
static Pool* make() noexcept
|
||||||
@@ -50,10 +51,8 @@ namespace snmalloc
|
|||||||
if (p != nullptr)
|
if (p != nullptr)
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
p = (T*)memory_provider
|
p = memory_provider
|
||||||
.template alloc_chunk<bits::next_pow2_const(sizeof(T))>(sizeof(T));
|
.template alloc_chunk<T, bits::next_pow2_const(sizeof(T))>(std::forward<Args...>(args)...);
|
||||||
|
|
||||||
new (p) T(std::forward<Args...>(args)...);
|
|
||||||
|
|
||||||
FlagLock f(lock);
|
FlagLock f(lock);
|
||||||
p->list_next = list;
|
p->list_next = list;
|
||||||
|
|||||||
Reference in New Issue
Block a user