Skip to content

Commit

Permalink
Fix callbacks
Browse files Browse the repository at this point in the history
This change does two things
* correctly passes the template parameters into the callbacks fixing
  correct zeroing of memory.
* By making the callbacks more specific it removes the warnings that GCC
was generating.
  • Loading branch information
mjp41 committed Apr 14, 2020
1 parent 070aa94 commit d4fccfa
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/mem/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,18 +1131,21 @@ namespace snmalloc
stats().sizeclass_alloc(sizeclass);
return small_alloc_new_free_list<zero_mem, allow_reserve>(sizeclass);
}
return small_alloc_first_alloc<zero_mem, allow_reserve>(size);
return small_alloc_first_alloc<zero_mem, allow_reserve>(sizeclass, size);
}

/**
* Called on first allocation to set up the thread local allocator,
* then directs the allocation request to the newly created allocator.
*/
template<ZeroMem zero_mem, AllowReserve allow_reserve>
SNMALLOC_SLOW_PATH void* small_alloc_first_alloc(size_t size)
SNMALLOC_SLOW_PATH void*
small_alloc_first_alloc(sizeclass_t sizeclass, size_t size)
{
return InitThreadAllocator([size](void* alloc) {
return reinterpret_cast<Allocator*>(alloc)->alloc(size);
return InitThreadAllocator([sizeclass, size](void* alloc) {
return reinterpret_cast<Allocator*>(alloc)
->template small_alloc_inner<zero_mem, allow_reserve>(
sizeclass, size);
});
}

Expand Down Expand Up @@ -1320,8 +1323,9 @@ namespace snmalloc
{
if (NeedsInitialisation(this))
{
return InitThreadAllocator([size](void* alloc) {
return reinterpret_cast<Allocator*>(alloc)->alloc(size);
return InitThreadAllocator([size, rsize, sizeclass](void* alloc) {
return reinterpret_cast<Allocator*>(alloc)
->medium_alloc<zero_mem, allow_reserve>(sizeclass, rsize, size);
});
}
slab = reinterpret_cast<Mediumslab*>(
Expand Down Expand Up @@ -1394,7 +1398,8 @@ namespace snmalloc
if (NeedsInitialisation(this))
{
return InitThreadAllocator([size](void* alloc) {
return reinterpret_cast<Allocator*>(alloc)->alloc(size);
return reinterpret_cast<Allocator*>(alloc)
->large_alloc<zero_mem, allow_reserve>(size);
});
}

Expand All @@ -1420,8 +1425,8 @@ namespace snmalloc

if (NeedsInitialisation(this))
{
InitThreadAllocator([p](void* alloc) {
reinterpret_cast<Allocator*>(alloc)->dealloc(p);
InitThreadAllocator([p, size](void* alloc) {
reinterpret_cast<Allocator*>(alloc)->large_dealloc(p, size);
return nullptr;
});
return;
Expand Down

0 comments on commit d4fccfa

Please sign in to comment.