23 BufferManager::Warnings::State ::
25 storeSizeExceeded(false),
35 BufferManager::Warnings ::
36 Warnings(BufferManager& bufferManager) :
37 bufferManager(bufferManager)
42 void BufferManager::Warnings ::
43 update(
const Status::t status)
47 if (this->state.storeSizeExceeded || this->state.tooManyBuffers) {
48 this->bufferManager.log_ACTIVITY_HI_ClearedErrorState();
50 this->state.storeSizeExceeded =
false;
51 this->state.tooManyBuffers =
false;
53 case Status::STORE_SIZE_EXCEEDED:
54 if (!this->state.storeSizeExceeded) {
55 this->bufferManager.log_WARNING_HI_StoreSizeExceeded();
56 this->state.storeSizeExceeded =
true;
59 case Status::TOO_MANY_BUFFERS:
60 if (!this->state.tooManyBuffers) {
61 this->bufferManager.log_WARNING_HI_TooManyBuffers();
62 this->state.tooManyBuffers =
true;
75 BufferManager::Store ::
76 Store(
const U32 size) :
78 memoryBase(new
U8[size]),
86 BufferManager::Store ::
89 delete[] this->memoryBase;
92 U32 BufferManager::Store ::
93 getAllocatedSize(
void)
const
95 return this->freeIndex;
106 FW_ASSERT(this->allocatedSize <= this->totalSize);
107 FW_ASSERT(this->freeIndex <= this->totalSize);
108 if (this->freeIndex + s > this->totalSize) {
110 newPadSize = this->totalSize - this->freeIndex;
112 if (this->allocatedSize + s + newPadSize > this->totalSize) {
118 if (this->freeIndex + s > this->totalSize) {
120 FW_ASSERT(this->padSize == 0, this->padSize);
121 this->padSize = newPadSize;
122 this->allocatedSize += newPadSize;
125 result = &this->memoryBase[this->freeIndex];
126 this->allocatedSize += s;
127 this->freeIndex += s;
128 FW_ASSERT(this->allocatedSize <= this->totalSize);
129 FW_ASSERT(this->freeIndex <= this->totalSize);
134 void BufferManager::Store ::
140 FW_ASSERT(this->allocatedSize >= size, this->allocatedSize, size);
141 this->allocatedSize -= size;
142 if (address == this->memoryBase) {
144 FW_ASSERT(this->allocatedSize >= padSize, this->allocatedSize, padSize);
145 this->allocatedSize -= this->padSize;
154 BufferManager::AllocationQueue ::
155 AllocationQueue(
const U32 size) :
157 data(new Entry[size]),
166 BufferManager::AllocationQueue ::
167 ~AllocationQueue(
void)
172 U32 BufferManager::AllocationQueue ::
175 const U32
id = this->nextId;
181 U32 BufferManager::AllocationQueue ::
182 getNextIndex(
const U32 index)
185 const U32 result = index + 1;
186 return result == this->totalSize ? 0 : result;
189 U32 BufferManager::AllocationQueue ::
190 getAllocationSize(
void)
const
192 return this->allocationSize;
196 BufferManager::AllocationQueue ::
202 FW_ASSERT(this->allocationSize <= this->totalSize);
203 if (this->allocationSize == this->totalSize) {
205 return Allocate::FULL;
207 FW_ASSERT(this->allocateIndex < this->totalSize);
208 Entry& e = this->data[allocateIndex];
209 id = this->getNextId();
212 this->allocateIndex = this->getNextIndex(this->allocateIndex);
213 ++this->allocationSize;
214 return Allocate::SUCCESS;
218 BufferManager::AllocationQueue ::
220 const U32 expectedId,
227 if (this->allocationSize == 0) {
228 FW_ASSERT(this->freeIndex == this->allocateIndex);
231 FW_ASSERT(this->freeIndex < this->totalSize);
232 Entry& e = this->data[this->freeIndex];
235 if (expectedId != sawId) {
236 return Free::ID_MISMATCH;
238 this->freeIndex = this->getNextIndex(this->freeIndex);
239 --this->allocationSize;
240 return Free::SUCCESS;
249 const char *
const compName,
251 const U32 maxNumBuffers
256 allocationQueue(maxNumBuffers)
288 Warnings::Status::t warningStatus = Warnings::Status::SUCCESS;
292 this->
store.allocate(size, address);
293 if (status == BufferManager::Store::FAILURE) {
294 warningStatus = Warnings::Status::STORE_SIZE_EXCEEDED;
298 if (warningStatus == Warnings::Status::SUCCESS) {
301 if (status == AllocationQueue::Allocate::FULL) {
302 this->
store.free(size, address);
303 warningStatus = Warnings::Status::TOO_MANY_BUFFERS;
307 if (warningStatus == Warnings::Status::SUCCESS) {
309 buffer.
setdata(
reinterpret_cast<U64>(address));
312 this->warnings.update(warningStatus);
323 const U32 instance =
static_cast<U32
>(this->
getInstance());
327 U8 *
const address =
reinterpret_cast<U8*
>(buffer.
getdata());
335 status == AllocationQueue::Free::SUCCESS,
336 status, expectedId, sawId,
size
341 this->
store.free(size, address);