34#define __Lock(name, element) auto __allocator_lock_##name##__ = Util::AllocatorLock(&name, element);
37#define __LockName(allocator, name, element) auto __allocator_lock_##name##__ = Util::AllocatorLock(&allocator, element);
49 this->
didAcquire = this->allocator->Acquire(this->element);
63template <
uint MAX_ALLOCS = 0xFFFF,
class ... TYPES>
66 static_assert(
soa_names_unique<TYPES...>::value,
"NamedSlot names must be unique within an ArrayAllocatorSafe");
101 template <
int MEMBER>
105 template <
int MEMBER>
109 template <
int MEMBER>
113 template <
int MEMBER>
117 template <
int MEMBER>
121 void Set(
const uint32_t index, TYPES...);
146 std::tuple<Util::PinnedArray<MAX_ALLOCS, soa_value_type_t<TYPES>>...>
objects;
155template<
uint MAX_ALLOCS,
class ...TYPES>
166template<
uint MAX_ALLOCS,
class ...TYPES>
171 bool rhsLocked = rhs.allocationLock.Lock();
173 this->
size = rhs.size;
177 if (rhsLocked) rhs.allocationLock.Unlock();
183template<
uint MAX_ALLOCS,
class ...TYPES>
196template<
uint MAX_ALLOCS,
class ...TYPES>
206template<
uint MAX_ALLOCS,
class ...TYPES>
219template<
uint MAX_ALLOCS,
class ...TYPES>
224 bool rhsLocked = rhs.allocationLock.Lock();
226 this->
size = rhs.size;
230 if (rhsLocked) rhs.allocationLock.Unlock();
237template<
uint MAX_ALLOCS,
class ...TYPES>
243 auto i = this->
size++;
244 this->
owners.Append(Threading::Thread::GetMyThreadId());
252template<
uint MAX_ALLOCS,
class ...TYPES>
266template<
uint MAX_ALLOCS,
class ...TYPES>
280template<
uint MAX_ALLOCS,
class ...TYPES>
290template<
uint MAX_ALLOCS,
class ...TYPES>
303template<
uint MAX_ALLOCS,
class ...TYPES>
316template<
uint MAX_ALLOCS,
class ...TYPES>
321 n_assert(this->
owners[index] == Threading::Thread::GetMyThreadId());
328template<
uint MAX_ALLOCS,
class ...TYPES>
334 n_assert(this->
owners[index] == Threading::Thread::GetMyThreadId() || this->
owners[index] == Threading::InvalidThreadId);
341template<
uint MAX_ALLOCS,
class ...TYPES>
347 n_assert(this->
owners[index] == Threading::Thread::GetMyThreadId() || this->
owners[index] == Threading::InvalidThreadId);
354template<
uint MAX_ALLOCS,
class ...TYPES>
359 n_assert(this->
owners[index] == Threading::Thread::GetMyThreadId());
366template<
uint MAX_ALLOCS,
class ...TYPES>
377template<
uint MAX_ALLOCS,
class ...TYPES>
388template<
uint MAX_ALLOCS,
class ...TYPES>
398template<
uint MAX_ALLOCS,
class ...TYPES>
408template<
uint MAX_ALLOCS,
class ...TYPES>
414 n_assert(currentThread == Threading::InvalidThreadId);
420template<
uint MAX_ALLOCS,
class ...TYPES>
425 if (this->
owners[index] == myThread)
431 Threading::Thread::YieldThread();
439template<
uint MAX_ALLOCS,
class ...TYPES>
443 n_assert(this->
owners[index] == Threading::Thread::GetMyThreadId());
bool Acquire(const uint32_t index)
Acquire element, asserts if false and returns true if this call acquired.
Definition arrayallocatorsafe.h:422
uint32_t size
Definition arrayallocatorsafe.h:145
~ArrayAllocatorSafe()
destructor
Definition arrayallocatorsafe.h:198
void operator=(const ArrayAllocatorSafe< MAX_ALLOCS, TYPES... > &rhs)
assign operator
Definition arrayallocatorsafe.h:208
const uint32_t Size() const
get number of used indices
Definition arrayallocatorsafe.h:282
uint32_t Alloc()
allocate a new resource
Definition arrayallocatorsafe.h:239
const tuple_array_t< MEMBER, TYPES... > & ConstGet(const uint32_t index) const
Get const explicitly.
Definition arrayallocatorsafe.h:331
void Reserve(uint32_t size)
grow capacity of arrays to size
Definition arrayallocatorsafe.h:292
Threading::Spinlock allocationLock
Definition arrayallocatorsafe.h:149
void EraseIndex(const uint32_t id)
Erase element for each.
Definition arrayallocatorsafe.h:254
void Set(const uint32_t index, const tuple_array_t< MEMBER, TYPES... > &type)
set single item
Definition arrayallocatorsafe.h:357
void Release(const uint32_t index)
Release an object, the next thread that acquires may use this instance as it fits.
Definition arrayallocatorsafe.h:441
void UpdateSize()
Any reserve and direct array access might mess with the size.
Definition arrayallocatorsafe.h:400
Util::PinnedArray< MAX_ALLOCS, Threading::ThreadId > owners
Definition arrayallocatorsafe.h:147
tuple_array_t< MEMBER, TYPES... > & Get(const uint32_t index)
get single item from resource
Definition arrayallocatorsafe.h:319
ArrayAllocatorSafe()
constructor
Definition arrayallocatorsafe.h:157
void EraseIndexSwap(const uint32_t id)
Erase element for each.
Definition arrayallocatorsafe.h:268
const Util::Array< tuple_array_t< MEMBER, TYPES... > > & GetArray() const
get array const reference
Definition arrayallocatorsafe.h:369
void TryAcquire(const uint32_t index)
Spinlock to acquire.
Definition arrayallocatorsafe.h:410
void Clear()
clear entire allocator and start from scratch.
Definition arrayallocatorsafe.h:305
std::tuple< Util::PinnedArray< MAX_ALLOCS, soa_value_type_t< TYPES > >... > objects
Definition arrayallocatorsafe.h:146
Nebula's dynamic array class.
Definition array.h:61
Definition pinnedarray.h:17
Set()
default constructor
Definition set.h:79
#define n_assert(exp)
Definition debug.h:58
int Exchange(int volatile *dest, int value)
interlocked exchange
Definition gccinterlocked.cc:94
int CompareExchange(int volatile *dest, int exchange, int comparand)
interlocked compare-exchange
Definition gccinterlocked.cc:112
pthread_t ThreadId
Definition linuxthreadid.h:15
int64_t ThreadIdStorage
Definition linuxthreadid.h:17
A quad tree designed to return regions of free 2D space.
Definition Random.cs:5
void erase_index_for_each_in_tuple(std::tuple< Ts... > &tuple, uint32_t i, std::index_sequence< Is... >)
Entry point for erasing an element.
Definition tupleutility.h:368
void reserve_for_each_in_tuple(std::tuple< Ts... > &tuple, uint32_t size, std::index_sequence< Is... >)
Entry point for reserving in each array.
Definition tupleutility.h:455
void alloc_for_each_in_tuple(std::tuple< Ts... > &tuple, std::index_sequence< Is... >)
Unpacks allocations for each member in a tuble.
Definition tupleutility.h:307
void clear_for_each_in_tuple(std::tuple< Ts... > &tuple, std::index_sequence< Is... >)
Unpacks allocations for each member in a tuple.
Definition tupleutility.h:327
void set_for_each_in_tuple(std::tuple< Ts... > &tuple, uint32_t i, std::index_sequence< Is... >, TYPES const &... values)
Entry point for setting values in each array at an index.
Definition tupleutility.h:435
constexpr int soa_tuple_index_v
Definition tupleutility.h:167
void erase_index_swap_for_each_in_tuple(std::tuple< Ts... > &tuple, uint32_t i, std::index_sequence< Is... >)
Entry point for erasing an element by swapping with the last and reducing size.
Definition tupleutility.h:392
soa_value_type_t< std::tuple_element_t< soa_tuple_index_v< MEMBER, TYPES... >, std::tuple< TYPES... > > > tuple_array_t
Get type of contained element in Util::Array stored in std::tuple.
Definition tupleutility.h:495
T * allocator
Definition arrayallocatorsafe.h:60
bool didAcquire
Definition arrayallocatorsafe.h:58
uint32_t element
Definition arrayallocatorsafe.h:59
~AllocatorLock()
Definition arrayallocatorsafe.h:52
AllocatorLock(T *allocator, uint32_t element)
Definition arrayallocatorsafe.h:45
Definition tupleutility.h:121
unsigned int uint
Definition types.h:41