From f7c131e4acc24b167a2922757712088d66efc840 Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Mon, 29 Apr 2019 18:48:28 +0100 Subject: [PATCH] largealloc: use pointer, not address_t, for cursor --- src/mem/largealloc.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index a0301ca..8f91440 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -58,7 +58,7 @@ namespace snmalloc class MemoryProviderStateMixin : public PAL { std::atomic_flag lock = ATOMIC_FLAG_INIT; - address_t bump; + void* bump; size_t remaining; void new_block() @@ -71,7 +71,7 @@ namespace snmalloc PAL::template notify_using(r, OS_PAGE_SIZE); - bump = address_cast(r); + bump = r; remaining = size; } @@ -145,15 +145,21 @@ namespace snmalloc { FlagLock f(lock); - auto aligned_bump = bits::align_up(bump, alignment); - if ((aligned_bump - bump) > remaining) + if constexpr (alignment != 0) { - new_block(); - } - else - { - remaining -= aligned_bump - bump; - bump = aligned_bump; + char* aligned_bump = pointer_align_up(bump); + + size_t bump_delta = pointer_diff(bump, aligned_bump); + + if (bump_delta > remaining) + { + new_block(); + } + else + { + remaining -= bump_delta; + bump = aligned_bump; + } } if (remaining < size) @@ -161,8 +167,8 @@ namespace snmalloc new_block(); } - p = pointer_cast(bump); - bump += size; + p = bump; + bump = pointer_offset(bump, size); remaining -= size; }