[*] Updated to a fixed version of O(1) heap (partial update from 2022'Sept was incomplete)

This commit is contained in:
Reece Wilson 2024-01-07 04:45:33 +00:00
parent 0d6d073b85
commit bab44d097a

View File

@ -98,9 +98,6 @@ namespace Aurora::Memory
void UpdateStats() override; void UpdateStats() override;
private: private:
AuThreadPrimitives::Mutex mutex_;
O1HeapInstance *heap_ {}; O1HeapInstance *heap_ {};
int count_ {}; int count_ {};
bool isDangling_ {}; bool isDangling_ {};
@ -136,7 +133,6 @@ namespace Aurora::Memory
{ {
if (this->heap_) if (this->heap_)
{ {
o1HeapReleaseCpp(this->heap_);// ->~O1HeapInstance(); // TODO: make free func
this->heap_ = nullptr; this->heap_ = nullptr;
} }
@ -168,19 +164,7 @@ namespace Aurora::Memory
this->ownsMemory_ = true; this->ownsMemory_ = true;
} }
this->heap_ = o1heapInit(this->base_, length, this->heap_ = o1heapInit(this->base_, length);
[this](const O1HeapInstance *const handle) -> void
{
SysAssertDbg(this->mutex_, "missing mutex");
this->mutex_->Lock();
},
[this](const O1HeapInstance *const handle) -> void
{
SysAssertDbg(this->mutex_, "missing mutex");
this->mutex_->Unlock();
}
);
return true; return true;
} }
@ -335,16 +319,16 @@ namespace Aurora::Memory
void InternalHeap::RequestTermination() void InternalHeap::RequestTermination()
{ {
this->mutex_->Lock(); if (AuAtomicLoad(&this->count_))
if (this->count_)
{ {
SysPushErrorMemory("Heap life was less than its allocations, waiting for final free"); SysPushErrorMemory("Heap life was less than its allocations, waiting for final free");
SysPushErrorMemory("Reporting using mayday!"); SysPushErrorMemory("Reporting using mayday!");
// Write a crash dump for later review, and do not panic.
// We just have a leak with no sign of corruption
Telemetry::Mayday(); Telemetry::Mayday();
this->isDangling_ = true; this->isDangling_ = true;
this->mutex_->Unlock();
} }
else else
{ {