Default template args for FreeObject & friends

Now that explicit annotations have gotten us through the refactoring, it's time
for the scaffolding to disappear.  src/mem/freelist.h is left generic for any
future machinations, but `FreeObject::T<>`, the several `FreeObject::...Ptr<>`s,
`FreeListIter<>`, and `FreeListBuilder<>` are given default parameters and all
uses are shortened to use defaults where possible.
This commit is contained in:
Nathaniel Wesley Filardo
2021-10-08 13:57:48 +01:00
committed by Nathaniel Wesley Filardo
parent 7deb3b61da
commit bc365e0abb
7 changed files with 143 additions and 187 deletions

View File

@@ -35,12 +35,10 @@ namespace snmalloc
// Store the message queue on a separate cacheline. It is mutable data that
// is read by other threads.
alignas(CACHELINE_SIZE)
FreeObject::AtomicQueuePtr<capptr::bounds::AllocWild> back{nullptr};
alignas(CACHELINE_SIZE) FreeObject::AtomicQueuePtr back{nullptr};
// Store the two ends on different cache lines as access by different
// threads.
alignas(CACHELINE_SIZE)
FreeObject::QueuePtr<capptr::bounds::AllocWild> front{nullptr};
alignas(CACHELINE_SIZE) FreeObject::QueuePtr front{nullptr};
constexpr RemoteAllocator() = default;
@@ -50,9 +48,7 @@ namespace snmalloc
SNMALLOC_ASSERT(front != nullptr);
}
void
init(FreeObject::HeadPtr<capptr::bounds::Alloc, capptr::bounds::AllocWild>
stub)
void init(FreeObject::HeadPtr stub)
{
FreeObject::atomic_store_null(stub, key_global);
front = capptr_rewild(stub);
@@ -60,9 +56,9 @@ namespace snmalloc
invariant();
}
FreeObject::QueuePtr<capptr::bounds::AllocWild> destroy()
FreeObject::QueuePtr destroy()
{
FreeObject::QueuePtr<capptr::bounds::AllocWild> fnt = front;
FreeObject::QueuePtr fnt = front;
back.store(nullptr, std::memory_order_relaxed);
front = nullptr;
return fnt;
@@ -70,8 +66,7 @@ namespace snmalloc
inline bool is_empty()
{
FreeObject::QueuePtr<capptr::bounds::AllocWild> bk =
back.load(std::memory_order_relaxed);
FreeObject::QueuePtr bk = back.load(std::memory_order_relaxed);
return bk == front;
}
@@ -82,10 +77,8 @@ namespace snmalloc
*/
template<typename Domesticator>
void enqueue(
FreeObject::HeadPtr<capptr::bounds::Alloc, capptr::bounds::AllocWild>
first,
FreeObject::HeadPtr<capptr::bounds::Alloc, capptr::bounds::AllocWild>
last,
FreeObject::HeadPtr first,
FreeObject::HeadPtr last,
const FreeListKey& key,
Domesticator domesticate)
{
@@ -93,13 +86,13 @@ namespace snmalloc
FreeObject::atomic_store_null(last, key);
// exchange needs to be a release, so nullptr in next is visible.
FreeObject::QueuePtr<capptr::bounds::AllocWild> prev =
FreeObject::QueuePtr prev =
back.exchange(capptr_rewild(last), std::memory_order_release);
FreeObject::atomic_store_next(domesticate(prev), first, key);
}
FreeObject::QueuePtr<capptr::bounds::AllocWild> peek()
FreeObject::QueuePtr peek()
{
return front;
}
@@ -108,16 +101,12 @@ namespace snmalloc
* Returns the front message, or null if not possible to return a message.
*/
template<typename Domesticator>
std::pair<
FreeObject::HeadPtr<capptr::bounds::Alloc, capptr::bounds::AllocWild>,
bool>
std::pair<FreeObject::HeadPtr, bool>
dequeue(const FreeListKey& key, Domesticator domesticate)
{
invariant();
FreeObject::HeadPtr<capptr::bounds::Alloc, capptr::bounds::AllocWild>
first = domesticate(front);
FreeObject::HeadPtr<capptr::bounds::Alloc, capptr::bounds::AllocWild>
next = first->atomic_read_next(key, domesticate);
FreeObject::HeadPtr first = domesticate(front);
FreeObject::HeadPtr next = first->atomic_read_next(key, domesticate);
if (next != nullptr)
{