[*] Resolve WakeOnAddress emu-mode bug and a potential dead-lock
This commit is contained in:
parent
b88c61c16d
commit
63b72a9fb5
@ -276,10 +276,13 @@ namespace Aurora::Threading
|
||||
{
|
||||
Lock();
|
||||
if (auto pLoadFromMemory = this->waitList.pHead)
|
||||
{
|
||||
if (pLoadFromMemory != pReturn)
|
||||
{
|
||||
pReturn->pNext = pLoadFromMemory;
|
||||
pLoadFromMemory->pBefore = pReturn;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->waitList.pTail = pReturn;
|
||||
@ -337,6 +340,11 @@ namespace Aurora::Threading
|
||||
}
|
||||
|
||||
pLast = pCurrentHead;
|
||||
|
||||
if (pCurrentHead->pBefore == pCurrentHead)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pCurrentHead = pCurrentHead->pBefore;
|
||||
}
|
||||
}
|
||||
@ -345,6 +353,53 @@ namespace Aurora::Threading
|
||||
return bRetStatus;
|
||||
}
|
||||
|
||||
void ProcessWaitNodeContainer::RemoveSelf(WaitEntry *pSelf)
|
||||
{
|
||||
Lock();
|
||||
{
|
||||
auto pCurrentHead = this->waitList.pTail;
|
||||
decltype(pCurrentHead) pLast {};
|
||||
|
||||
while (pCurrentHead)
|
||||
{
|
||||
if (pCurrentHead == pSelf)
|
||||
{
|
||||
if (pLast)
|
||||
{
|
||||
pLast->pNext = pCurrentHead->pNext;
|
||||
}
|
||||
|
||||
if (this->waitList.pHead == pCurrentHead)
|
||||
{
|
||||
this->waitList.pHead = pCurrentHead->pNext;
|
||||
}
|
||||
|
||||
if (pCurrentHead->pNext)
|
||||
{
|
||||
pCurrentHead->pNext->pBefore = pCurrentHead->pBefore;
|
||||
}
|
||||
|
||||
if (this->waitList.pTail == pCurrentHead)
|
||||
{
|
||||
this->waitList.pTail = pCurrentHead->pBefore;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
pLast = pCurrentHead;
|
||||
|
||||
if (pCurrentHead->pBefore == pCurrentHead)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pCurrentHead = pCurrentHead->pBefore;
|
||||
}
|
||||
}
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void ProcessWaitNodeContainer::Lock()
|
||||
{
|
||||
DoSpinLockOnVar(&this->uAtomic);
|
||||
@ -376,6 +431,16 @@ namespace Aurora::Threading
|
||||
return this->list[AuHashCode(pAddressIDC) % AuArraySize(this->list)].IterateWake(callback);
|
||||
}
|
||||
|
||||
void ProcessWaitContainer::RemoveSelf(const void *pAddress, WaitEntry *pSelf)
|
||||
{
|
||||
#if defined(FALLBACK_WAKEONADDRESS_SUPPORTS_NONEXACT_MATCHING)
|
||||
auto pAddressIDC = (void *)(AuUInt(pAddress) & ~(8 - 1));
|
||||
#else
|
||||
auto pAddressIDC = pAddress;
|
||||
#endif
|
||||
return this->list[AuHashCode(pAddressIDC) % AuArraySize(this->list)].RemoveSelf(pSelf);
|
||||
}
|
||||
|
||||
bool IsNativeWaitOnSupported()
|
||||
{
|
||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||
@ -450,6 +515,12 @@ namespace Aurora::Threading
|
||||
#if defined(HACK_NO_INVALID_ACCESS_LEAK_SHARED_REF_ON_DESTROYED_THREAD)
|
||||
pTempHoldMe.reset();
|
||||
#endif
|
||||
|
||||
if (!bResult)
|
||||
{
|
||||
gProcessWaitables.RemoveSelf(pTargetAddress, pWaitEntry);
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,8 @@ namespace Aurora::Threading
|
||||
template <typename T>
|
||||
bool IterateWake(T callback);
|
||||
|
||||
void RemoveSelf(WaitEntry *pSelf);
|
||||
|
||||
void Lock();
|
||||
|
||||
void Unlock();
|
||||
@ -100,5 +102,7 @@ namespace Aurora::Threading
|
||||
|
||||
template <typename T>
|
||||
bool IterateWake(const void *pAddress, T callback);
|
||||
|
||||
void RemoveSelf(const void *pAddress, WaitEntry *pSelf);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user