7template <
typename Object>
11 if (mPages !=
nullptr)
14 JPH_ASSERT(mNumFreeObjects.load(memory_order_relaxed) == mNumPages * mPageSize);
17 uint32 num_pages = mNumObjectsAllocated / mPageSize;
18 for (
uint32 page = 0; page < num_pages; ++page)
24template <
typename Object>
39 mPages =
reinterpret_cast<ObjectStorage **
>(
Allocate(mNumPages *
sizeof(ObjectStorage *)));
42 mNumObjectsAllocated = 0;
43 mFirstFreeObjectInNewPage = 0;
49 mFirstFreeObjectAndTag = cInvalidObjectIndex;
52template <
typename Object>
64 first_free = mFirstFreeObjectInNewPage.fetch_add(1, memory_order_relaxed);
68 lock_guard lock(mPageMutex);
73 return cInvalidObjectIndex;
75 mNumObjectsAllocated += mPageSize;
108template <
typename Object>
115 if (
ioBatch.mFirstObjectIndex == cInvalidObjectIndex)
118 GetStorage(
ioBatch.mLastObjectIndex).mNextFreeObject.store(
inObjectIndex, memory_order_release);
123template <
typename Object>
126 if (
ioBatch.mFirstObjectIndex != cInvalidObjectIndex)
171template <
typename Object>
203template<
typename Object>
206 uint32 index =
reinterpret_cast<ObjectStorage *
>(
inObject)->mNextFreeObject.load(memory_order_relaxed);
208 DestructObject(index);
#define JPH_CACHE_LINE_SIZE
Definition Core.h:466
std::uint64_t uint64
Definition Core.h:443
unsigned int uint
Definition Core.h:439
#define JPH_NAMESPACE_END
Definition Core.h:367
std::uint32_t uint32
Definition Core.h:442
#define JPH_NAMESPACE_BEGIN
Definition Core.h:361
#define JPH_IF_ENABLE_ASSERTS(...)
Definition IssueReporting.h:35
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
constexpr bool IsPowerOf2(T inV)
Check if inV is a power of 2.
Definition Math.h:73
uint CountTrailingZeros(uint32 inValue)
Compute number of trailing zero bits (how many low bits are zero)
Definition Math.h:95
AllocateFunction Allocate
Definition Memory.cpp:59
FreeFunction Free
Definition Memory.cpp:60
AlignedFreeFunction AlignedFree
Definition Memory.cpp:62
AlignedAllocateFunction AlignedAllocate
Definition Memory.cpp:61
@ Object
Start of a new object.
void Init(uint inMaxObjects, uint inPageSize)
Initialize the free list, up to inMaxObjects can be allocated.
Definition FixedSizeFreeList.inl:25
void DestructObjectBatch(Batch &ioBatch)
Lockless destruct batch of objects.
Definition FixedSizeFreeList.inl:124
uint32 ConstructObject(Parameters &&... inParameters)
Lockless construct a new object, inParameters are passed on to the constructor.
Definition FixedSizeFreeList.inl:54
~FixedSizeFreeList()
Destructor.
Definition FixedSizeFreeList.inl:8
void DestructObject(uint32 inObjectIndex)
Lockless destruct an object and return it to the free pool.
Definition FixedSizeFreeList.inl:172
void AddObjectToBatch(Batch &ioBatch, uint32 inObjectIndex)
Definition FixedSizeFreeList.inl:109
Definition Reference.h:204
A batch of objects that can be destructed.
Definition FixedSizeFreeList.h:97