[*] Fix some old known Win32 loop queue issues under bullshit real world conditions

(recursion, any retries, etc)
This commit is contained in:
Reece Wilson 2023-10-03 22:02:48 +01:00
parent 9686457891
commit 605862094e
2 changed files with 30 additions and 8 deletions

View File

@ -691,7 +691,11 @@ namespace Aurora::IO::Loop
// OK - All signals are set
// Take ownership of the queue ready for a potential purge of objects
StartUserAndTakeOwn();
if (!StartUserAndTakeOwn())
{
StartUserAndTakeOwn_Release();
return bReturnStatus;
}
// Le great iterate
Iterator queueIterator(this);
@ -778,6 +782,7 @@ namespace Aurora::IO::Loop
PumpHooks();
}
while (!bTriggerWin32 &&
!ret &&
WaitForSingleObject(this->hEvent_, 0) == WAIT_OBJECT_0);
return ret;
@ -825,6 +830,7 @@ namespace Aurora::IO::Loop
PumpHooks();
}
while (!bTriggerWin32 &&
!ret &&
WaitForSingleObject(this->hEvent_, 0) == WAIT_OBJECT_0);
return ret;
@ -1074,7 +1080,11 @@ namespace Aurora::IO::Loop
}
}
StartUserAndTakeOwn();
if (!StartUserAndTakeOwn())
{
StartUserAndTakeOwn_Release();
return true;
}
AuUInt firstTriggered { reinterpret_cast<AuUInt>(this->handleArrayOr_[indexOfTriggered]) };
{
@ -1235,18 +1245,25 @@ namespace Aurora::IO::Loop
StartUserAndTakeOwn_Release();
return triggeredCount;
}
void LoopQueue::StartUserAndTakeOwn()
bool LoopQueue::StartUserAndTakeOwn()
{
this->rwMutex_->UpgradeReadToWrite(0);
if (AuAtomicAdd(&this->uNestedWriteLock_, 1u) > 1)
{
return false;
}
if (!this->rwMutex_->UpgradeReadToWrite(100))
{
return false;
}
this->isCommitableInFuture_ = true;
return true;
}
bool LoopQueue::TryPumpWin32()
{
bool bMsgPump {};
@ -1345,7 +1362,10 @@ namespace Aurora::IO::Loop
this->CommitLocked();
}
this->rwMutex_->DowngradeWriteToRead();
if (AuAtomicSub(&this->uNestedWriteLock_, 1u) == 0)
{
this->rwMutex_->DowngradeWriteToRead();
}
}
// callee must own handle array

View File

@ -84,7 +84,7 @@ namespace Aurora::IO::Loop
bool WaitAnyNBSpurious(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuList<AuSPtr<ILoopSource>> *trigger, bool poll, bool &bTriggerWin32);
bool ChugWaitAny(AuUInt64 internalEndTime, AuUInt32 &chuggerIndex, AuUInt32 &offset);
void StartUserAndTakeOwn();
bool StartUserAndTakeOwn();
void StartUserAndTakeOwn_Release();
bool TryPumpWin32();
@ -111,6 +111,8 @@ namespace Aurora::IO::Loop
bool isCommitableInFuture_ {};
bool willCommitInFuture_ {};
AuUInt32 uNestedWriteLock_ {};
// we're only supporting one msg AddSource for now
AuSPtr<ILoopSource> msgSource_;