CR feedback

This commit is contained in:
Matthew Parkinson
2019-11-21 11:23:50 +00:00
parent 3f9e63209d
commit 1d0c42449e
2 changed files with 15 additions and 10 deletions

View File

@@ -33,7 +33,7 @@ namespace snmalloc
/**
* Pointer to first free entry in this slab
*
* The list will (allocated - needed - 1) long. The -1 is
* The list will be (allocated - needed - 1) long. The -1 is
* for the `link` element which is not in the free list.
*/
void* head;
@@ -145,6 +145,11 @@ namespace snmalloc
return pointer_cast<Slab>(address_cast(p) & SLAB_MASK);
}
static bool is_short(Slab* p)
{
return (address_cast(p) & SUPERSLAB_MASK) == address_cast(p);
}
/**
* Check bump-free-list-segment for cycles
*
@@ -187,9 +192,11 @@ namespace snmalloc
#endif
}
void debug_slab_invariant(bool is_short, Slab* slab)
void debug_slab_invariant(Slab* slab)
{
#if !defined(NDEBUG) && !defined(SNMALLOC_CHEAP_CHECKS)
bool is_short = Metaslab::is_short(slab);
if (is_full())
{
// There is no free list to validate
@@ -252,7 +259,6 @@ namespace snmalloc
assert(SLAB_SIZE == accounted_for);
#else
UNUSED(slab);
UNUSED(is_short);
#endif
}
};

View File

@@ -43,7 +43,7 @@ namespace snmalloc
void* head = meta.head;
assert(rsize == sizeclass_to_size(meta.sizeclass));
meta.debug_slab_invariant(is_short(), this);
meta.debug_slab_invariant(this);
assert(sl.get_head() == (SlabLink*)((size_t)this + meta.link));
assert(!meta.is_full());
@@ -127,7 +127,7 @@ namespace snmalloc
assert(is_start_of_object(Superslab::get(p), p));
meta.debug_slab_invariant(is_short(), this);
meta.debug_slab_invariant(this);
if constexpr (zero_mem == YesZero)
{
@@ -158,7 +158,7 @@ namespace snmalloc
if (meta.is_unused())
error("Detected potential double free.");
#endif
meta.debug_slab_invariant(is_short(), this);
meta.debug_slab_invariant(this);
if (unlikely(meta.return_object()))
return false;
@@ -172,7 +172,7 @@ namespace snmalloc
// Set the next pointer to the previous head.
Metaslab::store_next(p, head);
meta.debug_slab_invariant(is_short(), this);
meta.debug_slab_invariant(this);
return true;
}
@@ -206,7 +206,7 @@ namespace snmalloc
// Push on the list of slabs for this sizeclass.
sl->insert_back(meta.get_link(this));
meta.debug_slab_invariant(is_short(), this);
meta.debug_slab_invariant(this);
return Superslab::NoSlabReturn;
}
@@ -218,10 +218,9 @@ namespace snmalloc
return super->dealloc_slab(this, memory_provider);
}
bool is_short()
{
return (address_cast(this) & SUPERSLAB_MASK) == address_cast(this);
return Metaslab::is_short(this);
}
};
} // namespace snmalloc