[*] WaitMultipleLoopSources optimizations cont
This commit is contained in:
parent
3f7f2639c4
commit
eceb037e70
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
namespace Aurora::IO::Loop
|
namespace Aurora::IO::Loop
|
||||||
{
|
{
|
||||||
AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjects(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout)
|
AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjects(const AuList<AuSPtr<ILoopSource>> &objects, bool bZeroTick, AuUInt32 dwTimeoutReq)
|
||||||
{
|
{
|
||||||
bool isWinLoop;
|
bool isWinLoop;
|
||||||
AuList<AuSPtr<ILoopSourceEx>> loopSourceExs;
|
AuList<AuSPtr<ILoopSourceEx>> loopSourceExs;
|
||||||
@ -68,15 +68,23 @@ namespace Aurora::IO::Loop
|
|||||||
source->OnPresleep();
|
source->OnPresleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AuUInt32 uTimeout {};
|
||||||
|
if (!bZeroTick)
|
||||||
|
{
|
||||||
|
uTimeout = dwTimeoutReq ?
|
||||||
|
dwTimeoutReq :
|
||||||
|
INFINITE;
|
||||||
|
}
|
||||||
|
|
||||||
DWORD ret;
|
DWORD ret;
|
||||||
if (isWinLoop &&
|
if (isWinLoop &&
|
||||||
pMsgWaitForMultipleObjectsEx)
|
pMsgWaitForMultipleObjectsEx)
|
||||||
{
|
{
|
||||||
ret = pMsgWaitForMultipleObjectsEx(handleArray.size(), handleArray.data(), timeout ? timeout : INFINITE, QS_ALLPOSTMESSAGE | QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE);
|
ret = pMsgWaitForMultipleObjectsEx(handleArray.size(), handleArray.data(), uTimeout, QS_ALLPOSTMESSAGE | QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = ::WaitForMultipleObjectsEx(handleArray.size(), handleArray.data(), false, timeout ? timeout : INFINITE, true);
|
ret = ::WaitForMultipleObjectsEx(handleArray.size(), handleArray.data(), false, uTimeout, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool error = ((ret == WAIT_TIMEOUT) ||
|
bool error = ((ret == WAIT_TIMEOUT) ||
|
||||||
|
@ -53,9 +53,9 @@ namespace Aurora::IO::Loop
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||||
AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjects(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout);
|
AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjects(const AuList<AuSPtr<ILoopSource>> &objects, bool bZeroTick, AuUInt32 timeout);
|
||||||
#endif
|
#endif
|
||||||
AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjectsFallback(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout, bool &bTimeout);
|
AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjectsFallback(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout, bool bZeroTick, bool &bTimeout);
|
||||||
|
|
||||||
void ResetLoopSourceFalseAlarm(const AuSPtr<Loop::ILoopSource> &pLoopSource)
|
void ResetLoopSourceFalseAlarm(const AuSPtr<Loop::ILoopSource> &pLoopSource)
|
||||||
{
|
{
|
||||||
@ -219,10 +219,11 @@ namespace Aurora::IO::Loop
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto pSource = *itr;
|
auto pSource = *itr;
|
||||||
|
auto eType = pSource->GetType();
|
||||||
|
|
||||||
if (pSource->GetType() == ELoopSource::eSourceMutex ||
|
if (eType == ELoopSource::eSourceMutex ||
|
||||||
pSource->GetType() == ELoopSource::eSourceSemaphore ||
|
eType == ELoopSource::eSourceSemaphore ||
|
||||||
pSource->GetType() == ELoopSource::eSourceEvent)
|
eType == ELoopSource::eSourceEvent)
|
||||||
{
|
{
|
||||||
auto pSourceEx = AuDynamicCast<Loop::ILoopSourceEx>(pSource);
|
auto pSourceEx = AuDynamicCast<Loop::ILoopSourceEx>(pSource);
|
||||||
|
|
||||||
@ -263,17 +264,20 @@ namespace Aurora::IO::Loop
|
|||||||
|
|
||||||
if (lsList2.size())
|
if (lsList2.size())
|
||||||
{
|
{
|
||||||
if (signalTemp.size())
|
bool bZeroTick { };
|
||||||
|
if ((bZeroTick = bool(signalTemp.size())))
|
||||||
{
|
{
|
||||||
uTimeoutMS = 1;
|
uTimeoutMS = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
||||||
signaled = WaitMultipleOrObjects(lsList2, uTimeoutMS);
|
signaled = WaitMultipleOrObjects(lsList2, bZeroTick, uTimeoutMS);
|
||||||
bTimedout = uTimeoutMS ?
|
bTimedout = uTimeoutMS && !bZeroTick ?
|
||||||
Time::SteadyClockNS() >= uTimeoutEnd :
|
Time::SteadyClockNS() >= uTimeoutEnd :
|
||||||
false;
|
false;
|
||||||
#else
|
#else
|
||||||
signaled = WaitMultipleOrObjectsFallback(lsList2, uTimeoutMS, bTimedout);
|
signaled = WaitMultipleOrObjectsFallback(lsList2, uTimeoutMS, bZeroTick, bTimedout);
|
||||||
|
bTimedout &= !bZeroTick;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +294,7 @@ namespace Aurora::IO::Loop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjectsFallback(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout, bool &bTimeout)
|
AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjectsFallback(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout, bool bZeroTick, bool &bTimeout)
|
||||||
{
|
{
|
||||||
AuList<AuSPtr<ILoopSourceEx>> loopSourceExs;
|
AuList<AuSPtr<ILoopSourceEx>> loopSourceExs;
|
||||||
AuList<AuSPtr<ILoopSource>> triggered;
|
AuList<AuSPtr<ILoopSource>> triggered;
|
||||||
@ -330,9 +334,9 @@ namespace Aurora::IO::Loop
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto extended = AuDynamicCast<ILoopSourceEx>(source))
|
if (auto pLoopSourceEx = AuDynamicCast<ILoopSourceEx>(source))
|
||||||
{
|
{
|
||||||
if (!AuTryInsert(loopSourceExs, extended))
|
if (!AuTryInsert(loopSourceExs, pLoopSourceEx))
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -361,21 +365,36 @@ namespace Aurora::IO::Loop
|
|||||||
source->OnPresleep();
|
source->OnPresleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bZeroTick)
|
||||||
|
{
|
||||||
|
(void)pQueue->PumpNonblocking();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
bTimeout = !pQueue->WaitAny(timeout);
|
bTimeout = !pQueue->WaitAny(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
for (AU_ITERATE_N(i, objects.size()))
|
for (AU_ITERATE_N(i, loopSourceExs.size()))
|
||||||
{
|
{
|
||||||
auto source = loopSourceExs[i];
|
auto pLoopSource = loopSourceExs[i];
|
||||||
|
|
||||||
if (std::find(triggered.begin(), triggered.end(), source) == triggered.end())
|
if (std::find(triggered.begin(), triggered.end(), pLoopSource) == triggered.end())
|
||||||
{
|
{
|
||||||
if (source->IsSignaled())
|
auto eType = pLoopSource->GetType();
|
||||||
|
|
||||||
|
if (!bTimeout ||
|
||||||
|
eType == ELoopSource::eSourceMutex ||
|
||||||
|
eType == ELoopSource::eSourceSemaphore ||
|
||||||
|
eType == ELoopSource::eSourceEvent)
|
||||||
{
|
{
|
||||||
triggered.push_back(source);
|
if (pLoopSource->IsSignaledNoSpinIfUserland())
|
||||||
|
{
|
||||||
|
triggered.push_back(pLoopSource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
source->OnFinishSleep();
|
pLoopSource->OnFinishSleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
return triggered;
|
return triggered;
|
||||||
|
Loading…
Reference in New Issue
Block a user