[+] AuMemoryView::TryPromoteToSharedView
[+] AuMemoryView::TryDemoteFromSharedView [+] AuMemory::RequestHeapOfSharedRegion
This commit is contained in:
parent
44c7898c29
commit
298ab88648
@ -488,10 +488,15 @@ namespace Aurora::Memory
|
||||
AUKN_SHARED_SOO2_NCM(AllocHeap, Heap, kHeapSize, ((AuUInt, uLength)), AuUInt uLength);
|
||||
|
||||
/**
|
||||
* @warning the SOO variant cannot guarantee release-on-last-free.
|
||||
* @warning the SOO variant cannot guarantee release-on-last-free and will panic if an invalid memory handle is provided.
|
||||
*/
|
||||
AUKN_SHARED_SOO2_NCM(RequestHeapOfRegion, Heap, kHeapSize, ((const MemoryViewWrite &, memory)), const MemoryViewWrite &memory);
|
||||
|
||||
/**
|
||||
* @warning the SOO variant cannot guarantee release-on-last-free and will panic if an invalid memory handle is provided.
|
||||
*/
|
||||
AUKN_SHARED_SOO2_NCM(RequestHeapOfSharedRegion, Heap, kHeapSize, ((const AuSPtr<MemoryViewWrite> &, memory)), const AuSPtr<MemoryViewWrite> &pMemory);
|
||||
|
||||
/**
|
||||
* Proxies an existing heap with encapsulated statistics.
|
||||
* This is intended for debugging purposes when accurate heap stats of a heap-subset are desired.
|
||||
|
@ -367,6 +367,61 @@ namespace Aurora::Memory
|
||||
return this->controlBlock.pInUseCounter ||
|
||||
this->controlBlock.pPinner;
|
||||
}
|
||||
|
||||
AuSPtr<MemoryView> TryPromoteToSharedView(AuSPtr<void> pParent = {})
|
||||
{
|
||||
#if 0
|
||||
bool bHasControlBlock = this->HasControlBlock();
|
||||
|
||||
if (bHasControlBlock)
|
||||
{
|
||||
if (pParent)
|
||||
{
|
||||
return AuMakeShared<MemoryView>(*this, pParent);
|
||||
}
|
||||
else
|
||||
{
|
||||
return AuMakeShared<MemoryView>(*this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pParent)
|
||||
{
|
||||
return AuMakeShared<MemoryView>(*this, pParent);
|
||||
}
|
||||
else
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (pParent)
|
||||
{
|
||||
return AuMakeShared<MemoryView>(*this, pParent);
|
||||
}
|
||||
|
||||
if (this->HasControlBlock())
|
||||
{
|
||||
return AuMakeShared<MemoryView>(*this);
|
||||
}
|
||||
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
bool TryDemoteFromSharedView(const AuSPtr<MemoryView> &pCopy)
|
||||
{
|
||||
if (pCopy && pCopy->HasControlBlock())
|
||||
{
|
||||
AuResetMember(*this, AuConstReference(*pCopy.get()));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
using MemoryViewRead = MemoryView<true>;
|
||||
|
@ -31,6 +31,11 @@ namespace Aurora::Memory
|
||||
SysAssert(this->Init(memory));
|
||||
}
|
||||
|
||||
InternalHeap::InternalHeap(const AuSPtr<MemoryViewWrite> &pMemory)
|
||||
{
|
||||
SysAssert(this->Init(pMemory), "Couldn't initialize inline AuHeap! [OOM]");
|
||||
}
|
||||
|
||||
InternalHeap::InternalHeap(AuUInt uLength)
|
||||
{
|
||||
SysAssert(this->Init(uLength), "Couldn't initialize inline AuHeap! [OOM]");
|
||||
@ -70,6 +75,17 @@ namespace Aurora::Memory
|
||||
return this->Init(memory.length, memory.ptr);
|
||||
}
|
||||
|
||||
bool InternalHeap::Init(const AuSPtr<MemoryViewWrite> &pMemory)
|
||||
{
|
||||
if (!pMemory || !*pMemory)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this->pBloat_ = pMemory;
|
||||
return this->Init(pMemory->length, pMemory->ptr);
|
||||
}
|
||||
|
||||
bool InternalHeap::Init(AuUInt uLength, void *ptr)
|
||||
{
|
||||
SysAssert(!this->pBase_, "heap already initialized");
|
||||
@ -354,6 +370,35 @@ namespace Aurora::Memory
|
||||
static_cast<InternalHeap *>(pHeap)->RequestTermination();
|
||||
}
|
||||
|
||||
AUKN_SYM Heap *RequestHeapOfSharedRegionNew(const AuSPtr<MemoryViewWrite> &pMemory)
|
||||
{
|
||||
if (!pMemory)
|
||||
{
|
||||
SysPushErrorArg();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto pHeap = _new InternalHeap();
|
||||
if (!pHeap)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!pHeap->Init(pMemory))
|
||||
{
|
||||
delete pHeap;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return pHeap;
|
||||
}
|
||||
|
||||
AUKN_SYM void RequestHeapOfSharedRegionRelease(Heap *pHeap)
|
||||
{
|
||||
static_cast<InternalHeap *>(pHeap)->RequestTermination();
|
||||
}
|
||||
|
||||
AUROXTL_INTERFACE_SOO_SRC_EX(AURORA_SYMBOL_EXPORT, RequestHeapOfRegion, InternalHeap, (const MemoryViewWrite &, memory))
|
||||
AUROXTL_INTERFACE_SOO_SRC_EX(AURORA_SYMBOL_EXPORT, RequestHeapOfSharedRegion, InternalHeap, (const AuSPtr<MemoryViewWrite> &, memory))
|
||||
AUROXTL_INTERFACE_SOO_SRC_EX(AURORA_SYMBOL_EXPORT, AllocHeap, InternalHeap, (AuUInt, uLength))
|
||||
}
|
@ -23,10 +23,12 @@ namespace Aurora::Memory
|
||||
|
||||
InternalHeap();
|
||||
InternalHeap(const MemoryViewWrite &memory);
|
||||
InternalHeap(const AuSPtr<MemoryViewWrite> &pMemory);
|
||||
InternalHeap(AuUInt uLength);
|
||||
virtual ~InternalHeap();
|
||||
|
||||
bool Init(const MemoryViewWrite &memory);
|
||||
bool Init(const AuSPtr<MemoryViewWrite> &pMemory);
|
||||
bool Init(AuUInt uLength, void *ptr = nullptr);
|
||||
|
||||
static AuUInt GetHeapSize(const void *ptr);
|
||||
|
Loading…
Reference in New Issue
Block a user