27template<u
int SYNCPOINTS>
73template<u
int SYNCPOINTS>
83 for (
uint i = 0; i < SYNCPOINTS; i++)
99template<u
int SYNCPOINTS>
103 delete[] this->buffer;
109template<u
int SYNCPOINTS>
114 this->currentAllocation = 0;
115 this->currentInterval.lower = this->currentInterval.upper = this->freeInterval.lower;
118 for (
IndexT i = 0; i < this->events.Size(); i++)
121 if (ev.Peek() && this->freeInterval.lower)
124 this->freeInterval.upper = this->lockedIntervals[i].upper;
125 this->states[i] = Signaled;
134template<u
int SYNCPOINTS>
139 uint begin = this->currentInterval.upper;
140 uint end = begin + size;
141 if (end > this->size && this->freeInterval.lower >= this->freeInterval.upper)
146 end = this->freeInterval.upper;
148 else if (end > this->freeInterval.upper)
151 n_warning(
"Over-allocated RingAllocator!\n");
152 alloc.
data =
nullptr;
158 alloc.
data = this->buffer + begin;
162 this->currentInterval.upper = end;
163 this->currentAllocation += size;
170template<u
int SYNCPOINTS>
177 if (this->currentAllocation > 0)
180 this->lockedIntervals[this->nextEvent] = this->currentInterval;
181 this->states[this->nextEvent] = Waiting;
182 ret = &this->events[this->nextEvent];
183 this->nextEvent = (this->nextEvent + 1) % SYNCPOINTS;
186 this->freeInterval.lower = this->currentInterval.upper;
Allocates memory up-front, and then allows other systems to grab regions.
Definition ringallocator.h:29
Util::FixedArray< SyncState > states
Definition ringallocator.h:63
Threading::Event ev[SYNCPOINTS]
Definition ringallocator.h:47
Util::FixedArray< Interval > lockedIntervals
Definition ringallocator.h:61
SyncState
Definition ringallocator.h:55
@ Waiting
Definition ringallocator.h:57
@ Reset
Definition ringallocator.h:58
@ Signaled
Definition ringallocator.h:56
Threading::Event * End()
end allocation phase, insert sync points
Definition ringallocator.h:172
uint currentAllocation
Definition ringallocator.h:66
RingAllocator(const SizeT size)
constructor
Definition ringallocator.h:75
bool Allocate(const SizeT size, RingAlloc &alloc)
allocate memory
Definition ringallocator.h:136
uint nextEvent
Definition ringallocator.h:67
uint size
Definition ringallocator.h:46
byte * buffer
Definition ringallocator.h:45
Interval currentInterval
Definition ringallocator.h:64
void Start()
start allocation phase, checks sync points and unlocks regions if they have been signaled
Definition ringallocator.h:111
~RingAllocator()
destructor
Definition ringallocator.h:101
Util::FixedArray< Threading::Event > events
Definition ringallocator.h:62
Interval freeInterval
Definition ringallocator.h:65
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
void Resize(SizeT newSize)
resize array without deleting existing content
Definition fixedarray.h:483
void __cdecl n_warning(const char *msg,...)
This function is called when a warning should be issued which doesn't require abortion of the applica...
Definition debug.cc:161
#define n_assert(exp)
Definition debug.h:50
Definition arenaallocator.h:31
Definition ringallocator.h:22
byte * data
Definition ringallocator.h:24
uint offset
Definition ringallocator.h:23
Definition ringallocator.h:50
uint lower
Definition ringallocator.h:51
uint upper
Definition ringallocator.h:51
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
int IndexT
Definition types.h:48