[*] WhyOnAddress
This commit is contained in:
parent
4febc0e6dc
commit
298b095cc1
@ -12,6 +12,7 @@
|
||||
#include <Time/Time.hpp>
|
||||
|
||||
#define HACK_NO_INVALID_ACCESS_LEAK_SHARED_REF_ON_DESTROYED_THREAD
|
||||
// WOA_ALWAYS_DUMB_OS_TARGET -> iOS, notarized MacOS, Win9x, Xbox 360, etc
|
||||
|
||||
namespace Aurora::Threading
|
||||
{
|
||||
@ -257,8 +258,6 @@ namespace Aurora::Threading
|
||||
if (!pReturn->bAlive)
|
||||
{
|
||||
pReturn->bAlive = true;
|
||||
pReturn->pBefore = nullptr;
|
||||
pReturn->pNext = nullptr;
|
||||
if (auto pLoadFromMemory = this->waitList.pHead)
|
||||
{
|
||||
pLoadFromMemory->pBefore = pReturn;
|
||||
@ -278,8 +277,6 @@ namespace Aurora::Threading
|
||||
if (!pReturn->bAlive)
|
||||
{
|
||||
pReturn->bAlive = true;
|
||||
pReturn->pBefore = nullptr;
|
||||
pReturn->pNext = nullptr;
|
||||
if (auto pLoadFromMemory = this->waitList.pTail)
|
||||
{
|
||||
pLoadFromMemory->pNext = pReturn;
|
||||
@ -311,9 +308,10 @@ namespace Aurora::Threading
|
||||
{
|
||||
// FIFO
|
||||
auto pCurrentHead = this->waitList.pTail;
|
||||
decltype(pCurrentHead) pLast {};
|
||||
while (pCurrentHead)
|
||||
{
|
||||
decltype(pCurrentHead) pBefore {};
|
||||
|
||||
#if !defined(WOA_SEMAPHORE_MODE)
|
||||
// Insertion barrier
|
||||
{
|
||||
@ -323,36 +321,11 @@ namespace Aurora::Threading
|
||||
|
||||
auto [bCont, bRemove] = callback(*pCurrentHead);
|
||||
|
||||
pBefore = pCurrentHead->pBefore;
|
||||
|
||||
if (bRemove)
|
||||
{
|
||||
if (this->waitList.pHead == pCurrentHead)
|
||||
{
|
||||
this->waitList.pHead = pCurrentHead->pNext;
|
||||
}
|
||||
|
||||
if (this->waitList.pTail == pCurrentHead)
|
||||
{
|
||||
if (auto pBefore = pCurrentHead->pBefore)
|
||||
{
|
||||
this->waitList.pTail = pBefore;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->waitList.pTail = this->waitList.pHead;
|
||||
}
|
||||
}
|
||||
|
||||
if (pCurrentHead->pBefore)
|
||||
{
|
||||
pCurrentHead->pBefore->pNext = pCurrentHead->pNext;
|
||||
}
|
||||
|
||||
if (pCurrentHead->pNext)
|
||||
{
|
||||
pCurrentHead->pNext->pBefore = pCurrentHead->pBefore;
|
||||
}
|
||||
|
||||
pCurrentHead->bAlive = false;
|
||||
this->RemoveEntry(pCurrentHead, true);
|
||||
}
|
||||
|
||||
if (!bCont)
|
||||
@ -361,13 +334,12 @@ namespace Aurora::Threading
|
||||
break;
|
||||
}
|
||||
|
||||
pLast = pCurrentHead;
|
||||
|
||||
if (pCurrentHead->pBefore == pCurrentHead)
|
||||
if (pBefore == pCurrentHead)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pCurrentHead = pCurrentHead->pBefore;
|
||||
|
||||
pCurrentHead = pBefore;
|
||||
}
|
||||
}
|
||||
Unlock();
|
||||
@ -375,59 +347,48 @@ namespace Aurora::Threading
|
||||
return bRetStatus;
|
||||
}
|
||||
|
||||
void ProcessWaitNodeContainer::RemoveEntry(WaitEntry *pEntry,
|
||||
bool bAllUnderLock)
|
||||
{
|
||||
if (this->waitList.pHead == pEntry)
|
||||
{
|
||||
this->waitList.pHead = pEntry->pNext;
|
||||
}
|
||||
|
||||
if (this->waitList.pTail == pEntry)
|
||||
{
|
||||
this->waitList.pTail = pEntry->pBefore;
|
||||
}
|
||||
|
||||
if (pEntry->pBefore)
|
||||
{
|
||||
pEntry->pBefore->pNext = pEntry->pNext;
|
||||
}
|
||||
|
||||
if (pEntry->pNext)
|
||||
{
|
||||
pEntry->pNext->pBefore = pEntry->pBefore;
|
||||
}
|
||||
|
||||
if (bAllUnderLock)
|
||||
{
|
||||
pEntry->pBefore = nullptr;
|
||||
pEntry->pNext = nullptr;
|
||||
pEntry->bAlive = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessWaitNodeContainer::RemoveSelf(WaitEntry *pSelf)
|
||||
{
|
||||
Lock();
|
||||
{
|
||||
auto pCurrentHead = this->waitList.pTail;
|
||||
decltype(pCurrentHead) pLast {};
|
||||
|
||||
while (pCurrentHead)
|
||||
{
|
||||
if (pCurrentHead == pSelf)
|
||||
{
|
||||
if (this->waitList.pHead == pCurrentHead)
|
||||
{
|
||||
this->waitList.pHead = pCurrentHead->pNext;
|
||||
}
|
||||
|
||||
if (this->waitList.pTail == pCurrentHead)
|
||||
{
|
||||
if (auto pBefore = pCurrentHead->pBefore)
|
||||
{
|
||||
this->waitList.pTail = pBefore;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->waitList.pTail = this->waitList.pHead;
|
||||
}
|
||||
}
|
||||
|
||||
if (pCurrentHead->pBefore)
|
||||
{
|
||||
pCurrentHead->pBefore->pNext = pCurrentHead->pNext;
|
||||
}
|
||||
|
||||
if (pCurrentHead->pNext)
|
||||
{
|
||||
pCurrentHead->pNext->pBefore = pCurrentHead->pBefore;
|
||||
}
|
||||
|
||||
pCurrentHead->bAlive = false;
|
||||
break;
|
||||
}
|
||||
|
||||
pLast = pCurrentHead;
|
||||
|
||||
if (pCurrentHead->pBefore == pCurrentHead)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pCurrentHead = pCurrentHead->pBefore;
|
||||
}
|
||||
this->Lock();
|
||||
this->RemoveEntry(pSelf, false);
|
||||
this->Unlock();
|
||||
}
|
||||
Unlock();
|
||||
|
||||
pSelf->pBefore = nullptr;
|
||||
pSelf->pNext = nullptr;
|
||||
pSelf->bAlive = false;
|
||||
}
|
||||
|
||||
void ProcessWaitNodeContainer::Lock()
|
||||
@ -472,6 +433,9 @@ namespace Aurora::Threading
|
||||
|
||||
AUKN_SYM bool IsWaitOnRecommended()
|
||||
{
|
||||
#if defined(WOA_ALWAYS_DUMB_OS_TARGET)
|
||||
return false;
|
||||
#endif
|
||||
static AuOptionalEx<bool> gIsWaitOnRecommendedCache {};
|
||||
|
||||
if (gIsWaitOnRecommendedCache)
|
||||
@ -952,20 +916,32 @@ namespace Aurora::Threading
|
||||
|
||||
void InternalLTSWakeAll(const void *pTargetAddress)
|
||||
{
|
||||
#if defined(WOA_ALWAYS_DUMB_OS_TARGET)
|
||||
WakeAllOnAddress(pTargetAddress);
|
||||
#else
|
||||
auto [pWakeAddress, uDelta, uMask] = DecodeAddress(pTargetAddress, 1);
|
||||
RunOSWakeAllOnAddress(pWakeAddress);
|
||||
#endif
|
||||
}
|
||||
|
||||
void InternalLTSWakeOne(const void *pTargetAddress)
|
||||
{
|
||||
#if defined(WOA_ALWAYS_DUMB_OS_TARGET)
|
||||
WakeOnAddress(pTargetAddress);
|
||||
#else
|
||||
auto [pWakeAddress, uDelta, uMask] = DecodeAddress(pTargetAddress, 1);
|
||||
RunOSWakeNOnAddress(pWakeAddress, uDelta ? INT_MAX : 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void InternalLTSWakeCount(const void *pTargetAddress, AuUInt32 uCount)
|
||||
{
|
||||
#if defined(WOA_ALWAYS_DUMB_OS_TARGET)
|
||||
WakeNOnAddress(pTargetAddress, uCount);
|
||||
#else
|
||||
auto [pWakeAddress, uDelta, uMask] = DecodeAddress(pTargetAddress, 1);
|
||||
RunOSWakeNOnAddress(pWakeAddress, uDelta ? INT_MAX : uCount);
|
||||
#endif
|
||||
}
|
||||
|
||||
AUKN_SYM bool WaitOnAddress(const void *pTargetAddress,
|
||||
|
@ -92,6 +92,7 @@ namespace Aurora::Threading
|
||||
bool IterateWake(T callback);
|
||||
|
||||
void RemoveSelf(WaitEntry *pSelf);
|
||||
void RemoveEntry(WaitEntry *pSelf, bool bAllUnderLock);
|
||||
|
||||
void Lock();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user