diff --git a/src/backend/backend.h b/src/backend/backend.h index 03f04f7..5bf8015 100644 --- a/src/backend/backend.h +++ b/src/backend/backend.h @@ -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)); } diff --git a/src/backend/commitrange.h b/src/backend/commitrange.h index a0032d6..43b1f88 100644 --- a/src/backend/commitrange.h +++ b/src/backend/commitrange.h @@ -25,6 +25,8 @@ namespace snmalloc static constexpr bool Aligned = ParentRange::Aligned; + static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; + constexpr CommitRange() = default; capptr::Chunk alloc_range(size_t size) diff --git a/src/backend/empty_range.h b/src/backend/empty_range.h index 5feabd9..36680f3 100644 --- a/src/backend/empty_range.h +++ b/src/backend/empty_range.h @@ -19,6 +19,8 @@ namespace snmalloc static constexpr bool Aligned = true; + static constexpr bool ConcurrencySafe = true; + constexpr EmptyRange() = default; capptr::Chunk alloc_range(size_t) diff --git a/src/backend/globalrange.h b/src/backend/globalrange.h index 7b4bb0b..d8ae667 100644 --- a/src/backend/globalrange.h +++ b/src/backend/globalrange.h @@ -37,6 +37,8 @@ namespace snmalloc static constexpr bool Aligned = ParentRange::Aligned; + static constexpr bool ConcurrencySafe = true; + constexpr GlobalRange() = default; capptr::Chunk alloc_range(size_t size) diff --git a/src/backend/largebuddyrange.h b/src/backend/largebuddyrange.h index 5b2954d..a4a807a 100644 --- a/src/backend/largebuddyrange.h +++ b/src/backend/largebuddyrange.h @@ -271,6 +271,8 @@ namespace snmalloc static constexpr bool Aligned = true; + static constexpr bool ConcurrencySafe = false; + constexpr LargeBuddyRange() = default; capptr::Chunk alloc_range(size_t size) diff --git a/src/backend/pagemapregisterrange.h b/src/backend/pagemapregisterrange.h index de55b13..4084eed 100644 --- a/src/backend/pagemapregisterrange.h +++ b/src/backend/pagemapregisterrange.h @@ -30,6 +30,8 @@ namespace snmalloc static constexpr bool Aligned = ParentRange::Aligned; + static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; + capptr::Chunk alloc_range(size_t size) { auto base = state->alloc_range(size); diff --git a/src/backend/palrange.h b/src/backend/palrange.h index 82d36ce..5fa3fe6 100644 --- a/src/backend/palrange.h +++ b/src/backend/palrange.h @@ -24,6 +24,11 @@ namespace snmalloc static constexpr bool Aligned = pal_supports; + // 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 alloc_range(size_t size) diff --git a/src/backend/smallbuddyrange.h b/src/backend/smallbuddyrange.h index b813b67..4ee0758 100644 --- a/src/backend/smallbuddyrange.h +++ b/src/backend/smallbuddyrange.h @@ -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 alloc_range(size_t size) diff --git a/src/backend/statsrange.h b/src/backend/statsrange.h index 0a61fef..0693983 100644 --- a/src/backend/statsrange.h +++ b/src/backend/statsrange.h @@ -31,6 +31,8 @@ namespace snmalloc static constexpr bool Aligned = ParentRange::Aligned; + static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; + constexpr StatsRange() = default; capptr::Chunk alloc_range(size_t size) diff --git a/src/backend/subrange.h b/src/backend/subrange.h index c83bdab..dd48243 100644 --- a/src/backend/subrange.h +++ b/src/backend/subrange.h @@ -31,6 +31,8 @@ namespace snmalloc static constexpr bool Aligned = ParentRange::Aligned; + static constexpr bool ConcurrencySafe = ParentRange::ConcurrencySafe; + capptr::Chunk alloc_range(size_t sub_size) { SNMALLOC_ASSERT(bits::is_pow2(sub_size));