37template<
class ... TYPES>
58 n_assert2(this->
maxId > index,
"max amount of allocations exceeded!\n");
88#define _DECL_ACQUIRE_RELEASE(ty) \
89 bool ty##Acquire(const ty id); \
90 void ty##Release(const ty id); \
93 ty##Lock(const ty element) : element(element) { this->didAcquire = ty##Acquire(this->element); } \
94 ~ty##Lock() { if (this->didAcquire) ty##Release(this->element); } \
100#define _IMPL_ACQUIRE_RELEASE(ty, allocator) \
101 bool ty##Acquire(const ty id) { return allocator.Acquire(id.id); } \
102 void ty##Release(const ty id) { allocator.Release(id.id); }
104template<
int MAX_ALLOCS,
class... TYPES>
122 this->
owners[index] = Threading::Thread::GetMyThreadId();
127 alloc_for_each_in_tuple(this->
objects);
128 index = this->
size++;
129 this->
owners.
Append(Threading::Thread::GetMyThreadId());
130 n_assert2(MAX_ALLOCS > index,
"max amount of allocations exceeded!\n");
An ID allocator associates an id with a slice in an N number of arrays.
Definition idallocator.h:39
Util::Array< Ids::Id32 > & FreeIds()
Returns the list of free ids.
Definition idallocator.h:72
const Ids::Id32 Size() const
return number of allocated ids
Definition idallocator.h:78
Ids::Id32 maxId
Definition idallocator.h:84
Ids::Id32 Alloc()
Allocate an object.
Definition idallocator.h:45
Util::Array< Ids::Id32 > freeIds
Definition idallocator.h:85
IdAllocator(Ids::Id32 maxid=0xFFFFFFFF)
constructor
Definition idallocator.h:42
void Dealloc(Ids::Id32 index)
Deallocate an object. Just places it in freeids array for recycling.
Definition idallocator.h:65
Definition idallocator.h:106
Ids::Id32 Alloc()
Allocate an object.
Definition idallocator.h:114
void Dealloc(Ids::Id32 index)
Deallocate an object. Just places it in freeids array for recycling.
Definition idallocator.h:138
Util::Array< Ids::Id32 > freeIds
Definition idallocator.h:147
IdAllocatorSafe()
constructor
Definition idallocator.h:109
void Lock()
Lock.
Definition spinlock.h:83
void Unlock()
Unlock.
Definition spinlock.h:103
The ArrayAllocator provides a variadic list of types which is to be contained in the allocator and fe...
Definition arrayallocator.h:34
uint32_t size
Definition arrayallocator.h:104
uint32_t Alloc()
allocate a new resource
Definition arrayallocator.h:175
The ArrayAllocatorSafe provides a thread safe variadic list of types which is to be contained in the ...
Definition arrayallocatorsafe.h:65
uint32_t size
Definition arrayallocatorsafe.h:143
Threading::Spinlock allocationLock
Definition arrayallocatorsafe.h:147
Util::PinnedArray< MAX_ALLOCS, Threading::ThreadId > owners
Definition arrayallocatorsafe.h:145
std::tuple< Util::PinnedArray< MAX_ALLOCS, TYPES >... > objects
Definition arrayallocatorsafe.h:144
Nebula's dynamic array class.
Definition array.h:60
TYPE & Back() const
return reference to last element
Definition array.h:993
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition array.h:1334
void EraseBack()
erase back
Definition array.h:1131
const SizeT Size() const
get number of elements in array
Definition array.h:880
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition pinnedarray.h:279
#define n_assert2(exp, msg)
Definition debug.h:51
This simple Id pool implements a set of free and used consecutive integers.
Definition id.h:135
uint32_t Id32
Definition id.h:138