JobSystem now automatically free Jobs (#91)

* JobSystem now automatically free Jobs

Until now Job allocation used a linear allocator
strategy which required to “reset” the JobSystem
periodically — typically once per frame in
filament.

This is no longer required. We use a pool allocator
now, which doesn’t add much overhead. It does
use a spin-lock for thread-safety though, since
we assume very little contention, this shouldn’t
be a problem.

* Thread Safe Object Pool Allocator

A lock-less, thread-safe object pool allocator,
now used for storing JobSystem’s jobs allocations.
This gets rid of the spin-lock introduced in the
previous cl.
This commit is contained in:
Mathias Agopian
2018-08-13 22:25:15 -07:00
committed by Romain Guy
parent bb553bf53d
commit d9ba3998d2
4 changed files with 140 additions and 97 deletions
+21 -9
View File
@@ -55,11 +55,8 @@ void LinearAllocator::swap(LinearAllocator& rhs) noexcept {
// FreeList
// ------------------------------------------------------------------------------------------------
FreeList::FreeList(void* begin, void* end,
FreeListBase::Node* FreeListBase::init(void* begin, void* end,
size_t elementSize, size_t alignment, size_t extra) noexcept
#ifndef NDEBUG
: mBegin(begin), mEnd(end)
#endif
{
void* const p = pointermath::align(begin, alignment, extra);
void* const n = pointermath::align(pointermath::add(p, elementSize), alignment, extra);
@@ -70,18 +67,33 @@ FreeList::FreeList(void* begin, void* end,
const size_t num = (uintptr_t(end) - uintptr_t(p)) / d;
// set first entry
mNext = static_cast<FreeList*>(p);
Node* head = static_cast<Node*>(p);
// next entry
FreeList* cur = mNext;
Node* cur = head;
for (size_t i=1 ; i<num ; ++i) {
FreeList* next = pointermath::add(cur, d);
cur->mNext = next;
Node* next = pointermath::add(cur, d);
cur->next = next;
cur = next;
}
assert(cur < end);
assert(pointermath::add(cur, d) <= end);
cur->mNext = nullptr;
cur->next = nullptr;
return head;
}
FreeList::FreeList(void* begin, void* end,
size_t elementSize, size_t alignment, size_t extra) noexcept
: mHead(init(begin, end, elementSize, alignment, extra))
#ifndef NDEBUG
, mBegin(begin), mEnd(end)
#endif
{
}
AtomicFreeList::AtomicFreeList(void* begin, void* end,
size_t elementSize, size_t alignment, size_t extra) noexcept
: mHead(init(begin, end, elementSize, alignment, extra)) {
}
TrackingPolicy::HighWatermark::~HighWatermark() noexcept {