[*] Harden IO processor item usage after parent processor release

This commit is contained in:
Reece Wilson 2023-12-11 20:18:36 +00:00
parent 9527a076cf
commit 073d77a17b
5 changed files with 35 additions and 4 deletions

View File

@ -35,6 +35,7 @@ namespace Aurora::IO
IOProcessor::~IOProcessor()
{
this->ReleaseAllWatches();
this->items.Deinit();
}
bool IOProcessor::Init()

View File

@ -14,6 +14,11 @@ namespace Aurora::IO
{
bool IOProcessorItem::StopWatch()
{
if (!this->pParent)
{
return false;
}
if (this->pParent->CheckThread() &&
this->pParent->bFrameStart)
{
@ -26,6 +31,11 @@ namespace Aurora::IO
bool IOProcessorItem::FailWatch()
{
if (!this->pParent)
{
return false;
}
if (this->pParent->CheckThread() &&
this->pParent->bFrameStart)
{
@ -36,9 +46,13 @@ namespace Aurora::IO
return this->pParent->items.ScheduleFinish(AuSharedFromThis(), true);
}
bool IOProcessorItem::OnFinished(const AuSPtr<AuLoop::ILoopSource>& source, AuUInt8 pos)
{
if (!this->pParent)
{
return true;
}
if (this->bSingleshot)
{
if (AuExchange(this->bTriggered, true))
@ -65,6 +79,11 @@ namespace Aurora::IO
void IOProcessorItem::IOAlert(bool force)
{
if (!this->pParent)
{
return;
}
if (!this->pParent->IsTickOnly())
{
bool bForceTick {};

View File

@ -13,9 +13,9 @@ namespace Aurora::IO
struct IOProcessorItem : AuLoop::ILoopSourceSubscriberEx, IIOProcessorItem, AuEnableSharedFromThis<IOProcessorItem>
{
IOProcessor *pParent;
bool bSingleshot{};
bool bTriggered{};
IOProcessor *pParent {};
bool bSingleshot {};
bool bTriggered {};
AuSPtr<IIOWaitableItem> pItem;
AuSPtr<IIOEventListener> pListener;

View File

@ -20,6 +20,16 @@ namespace Aurora::IO
return bool(this->cvEvent);
}
void IOProcessorItems::Deinit()
{
AU_LOCK_GUARD(this->mutex);
for (const auto &pItem : this->allItems)
{
pItem->pParent = nullptr;
}
}
bool IOProcessorItems::AddFrameTemp(const AuSPtr<IOProcessorItem> &item)
{
AU_TRY_LOCK_GUARD_RET_DEF(this->mutex);

View File

@ -31,6 +31,7 @@ namespace Aurora::IO
AuList<AuPair<AuSPtr<IOProcessorItem>, bool>> crossThreadAbort;
bool Init();
void Deinit();
bool AddFrameTemp(const AuSPtr<IOProcessorItem> &item);
bool AddFrameOrFallback(const AuSPtr<IOProcessorItem> &item);