diff --git a/src/ds/dllist.h b/src/ds/dllist.h index b833a45..8893261 100644 --- a/src/ds/dllist.h +++ b/src/ds/dllist.h @@ -10,7 +10,7 @@ namespace snmalloc * Invalid pointer class. This is similar to `std::nullptr_t`, but allows * other values. */ - template + template struct InvalidPointer { /** @@ -40,10 +40,17 @@ namespace snmalloc * systems the sentinel should be a value in unmapped memory. */ template - operator T*() + operator T*() const { return reinterpret_cast(Sentinel); } + /** + * Implicit conversion to an address, returns the sentinel value. + */ + operator address_t() const + { + return Sentinel; + } }; template diff --git a/src/mem/pagemap.h b/src/mem/pagemap.h index ebf8cf6..7e907c9 100644 --- a/src/mem/pagemap.h +++ b/src/mem/pagemap.h @@ -78,7 +78,7 @@ namespace snmalloc (INDEX_LEVELS * BITS_PER_INDEX_LEVEL) + BITS_FOR_LEAF + GRANULARITY_BITS; // Value used to represent when a node is being added too - static constexpr address_t LOCKED_ENTRY = 1; + static constexpr InvalidPointer<1> LOCKED_ENTRY; struct Leaf { @@ -112,16 +112,14 @@ namespace snmalloc // to see that correctly. PagemapEntry* value = e->load(std::memory_order_relaxed); - if (address_cast(value) <= LOCKED_ENTRY) + if ((value == nullptr) || (value == LOCKED_ENTRY)) { if constexpr (create_addr) { value = nullptr; if (e->compare_exchange_strong( - value, - pointer_cast(LOCKED_ENTRY), - std::memory_order_relaxed)) + value, LOCKED_ENTRY, std::memory_order_relaxed)) { auto& v = default_memory_provider; value = v.alloc_chunk();