Add ConcurrencySafe property

Ranges can be safe to call from multiple threads.  This adds a constexpr
field to signify if that is the case.
This commit is contained in:
Matthew Parkinson
2022-03-23 16:15:57 +00:00
committed by Matthew Parkinson
parent bdb3183989
commit e77b9e2851
10 changed files with 24 additions and 0 deletions

View File

@@ -235,6 +235,9 @@ namespace snmalloc
}
else
{
static_assert(
GlobalMetaRange::ConcurrencySafe,
"Global meta data range needs to be concurrency safe.");
typename GlobalMetaRange::State global_state;
p = global_state->alloc_range(bits::next_pow2(size));
}

View File

@@ -25,6 +25,8 @@ namespace snmalloc
static constexpr bool Aligned = ParentRange::Aligned;
static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;
constexpr CommitRange() = default;
capptr::Chunk<void> alloc_range(size_t size)

View File

@@ -19,6 +19,8 @@ namespace snmalloc
static constexpr bool Aligned = true;
static constexpr bool ConcurrencySafe = true;
constexpr EmptyRange() = default;
capptr::Chunk<void> alloc_range(size_t)

View File

@@ -37,6 +37,8 @@ namespace snmalloc
static constexpr bool Aligned = ParentRange::Aligned;
static constexpr bool ConcurrencySafe = true;
constexpr GlobalRange() = default;
capptr::Chunk<void> alloc_range(size_t size)

View File

@@ -271,6 +271,8 @@ namespace snmalloc
static constexpr bool Aligned = true;
static constexpr bool ConcurrencySafe = false;
constexpr LargeBuddyRange() = default;
capptr::Chunk<void> alloc_range(size_t size)

View File

@@ -30,6 +30,8 @@ namespace snmalloc
static constexpr bool Aligned = ParentRange::Aligned;
static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;
capptr::Chunk<void> alloc_range(size_t size)
{
auto base = state->alloc_range(size);

View File

@@ -24,6 +24,11 @@ namespace snmalloc
static constexpr bool Aligned = pal_supports<AlignedAllocation, PAL>;
// Note we have always assumed the Pals to provide a concurrency safe
// API. If in the future this changes, then this would
// need to be changed.
static constexpr bool ConcurrencySafe = true;
constexpr PalRange() = default;
capptr::Chunk<void> alloc_range(size_t size)

View File

@@ -175,6 +175,8 @@ namespace snmalloc
static constexpr bool Aligned = true;
static_assert(ParentRange::Aligned, "ParentRange must be aligned");
static constexpr bool ConcurrencySafe = false;
constexpr SmallBuddyRange() = default;
capptr::Chunk<void> alloc_range(size_t size)

View File

@@ -31,6 +31,8 @@ namespace snmalloc
static constexpr bool Aligned = ParentRange::Aligned;
static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;
constexpr StatsRange() = default;
capptr::Chunk<void> alloc_range(size_t size)

View File

@@ -31,6 +31,8 @@ namespace snmalloc
static constexpr bool Aligned = ParentRange::Aligned;
static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe;
capptr::Chunk<void> alloc_range(size_t sub_size)
{
SNMALLOC_ASSERT(bits::is_pow2(sub_size));