[*] Win32 loopqueue optimization

This commit is contained in:
Reece Wilson 2023-12-01 10:33:55 +00:00
parent a189151c59
commit f05cafbff7
16 changed files with 73 additions and 9 deletions

View File

@ -528,6 +528,11 @@ namespace Aurora::IO::IPC
return true;
}
bool IPCMutexProxy::IsSignaledNoSpinIfUserland()
{
return this->IsSignaled();
}
bool IPCMutexProxy::WaitOn(AuUInt32 timeout)
{
auto futex = this->GetFutex();

View File

@ -23,6 +23,7 @@ namespace Aurora::IO::IPC
bool Unlock() override;
bool IsSignaledNoSpinIfUserland() override;
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override;

View File

@ -89,6 +89,11 @@ namespace Aurora::IO::IPC
return this->event_.GetType();
}
bool IPCEventProxy::IsSignaledNoSpinIfUserland()
{
return this->IsSignaled();
}
AUKN_SYM AuSPtr<IPCEvent> NewEvent(bool triggered, bool atomicRelease)
{
auto object = AuMakeShared<IPCEventProxy>(triggered, atomicRelease);
@ -215,6 +220,11 @@ namespace Aurora::IO::IPC
return this->semaphore_.IsSignaled();
}
bool IPCSemaphoreProxy::IsSignaledNoSpinIfUserland()
{
return this->IsSignaled();
}
bool IPCSemaphoreProxy::WaitOn(AuUInt32 timeout)
{
return this->semaphore_.WaitOn(timeout);

View File

@ -41,6 +41,7 @@ namespace Aurora::IO::IPC
bool Set() override;
bool Reset() override;
bool IsSignaledNoSpinIfUserland() override;
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override;
@ -61,6 +62,7 @@ namespace Aurora::IO::IPC
bool AddOne() override;
bool AddMany(AuUInt32 uCount) override;
bool IsSignaledNoSpinIfUserland() override;
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override;

View File

@ -37,6 +37,7 @@ namespace Aurora::IO::IPC
bool Unlock() override;
bool IsSignaledNoSpinIfUserland() override;
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override;
@ -63,6 +64,11 @@ namespace Aurora::IO::IPC
return this->mutex_.IsSignaled();
}
bool IPCMutexProxy::IsSignaledNoSpinIfUserland()
{
return this->IsSignaled();
}
bool IPCMutexProxy::WaitOn(AuUInt32 timeout)
{
return this->mutex_.WaitOn(timeout);
@ -150,6 +156,7 @@ namespace Aurora::IO::IPC
bool Set() override;
bool Reset() override;
bool IsSignaledNoSpinIfUserland() override;
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override;
@ -191,6 +198,11 @@ namespace Aurora::IO::IPC
return this->event_.GetType();
}
bool IPCEventProxy::IsSignaledNoSpinIfUserland()
{
return this->IsSignaled();
}
AUKN_SYM AuSPtr<IPCEvent> NewEvent(bool triggered, bool atomicRelease)
{
IPC::IPCHandle handle;
@ -269,7 +281,7 @@ namespace Aurora::IO::IPC
bool AddOne() override;
bool AddMany(AuUInt32 uCount) override;
bool IsSignaledNoSpinIfUserland() override;
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override;
@ -304,6 +316,11 @@ namespace Aurora::IO::IPC
return this->semaphore_.IsSignaled();
}
bool IPCSemaphoreProxy::IsSignaledNoSpinIfUserland()
{
return this->IsSignaled();
}
bool IPCSemaphoreProxy::WaitOn(AuUInt32 timeout)
{
return this->semaphore_.WaitOn(timeout);

View File

@ -11,6 +11,7 @@ namespace Aurora::IO::Loop
{
struct ILoopSourceEx : virtual ILoopSource
{
virtual bool IsSignaledNoSpinIfUserland() = 0;
virtual void OnPresleep() = 0;
virtual bool OnTrigger(AuUInt handle) = 0;
virtual void OnFinishSleep() = 0;

View File

@ -196,11 +196,16 @@ namespace Aurora::IO::Loop
});
}
bool LSLocalEvent::TryTake()
bool LSLocalEvent::IsSignaledNoSpinIfUserland()
{
return this->TryTakeNoSpin();
}
bool LSLocalEvent::TryTake()
{
return this->TryTakeSpin();
}
bool LSLocalEvent::TryTakeWaitMS(AuUInt32 timeout)
{
auto uEndTime = AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout);

View File

@ -32,6 +32,7 @@ namespace Aurora::IO::Loop
bool TryTake();
bool TryTakeWaitMS(AuUInt32 timeout);
bool IsSignaledNoSpinIfUserland() override;
void OnPresleep() override;
void OnFinishSleep() override;

View File

@ -85,6 +85,11 @@ namespace Aurora::IO::Loop
return this->TryTake();
}
bool LSLocalMutex::IsSignaledNoSpinIfUserland()
{
return this->TryTakeNoSpin();
}
bool LSLocalMutex::WaitOn(AuUInt32 timeout)
{
return this->TryTakeWaitMS(timeout);
@ -110,7 +115,7 @@ namespace Aurora::IO::Loop
bool LSLocalMutex::TryTake()
{
return TryTakeNoSpin();
return this->TryTakeSpin();
}
bool LSLocalMutex::TryTakeWaitMS(AuUInt32 timeout)

View File

@ -19,6 +19,7 @@ namespace Aurora::IO::Loop
bool TryInit();
bool IsSignaled() override;
bool IsSignaledNoSpinIfUserland() override;
bool WaitOn(AuUInt32 timeout) override;
ELoopSource GetType() override;

View File

@ -98,6 +98,11 @@ namespace Aurora::IO::Loop
return this->TryTake();
}
bool LSLocalSemaphore::IsSignaledNoSpinIfUserland()
{
return this->TryTakeNoSpin();
}
bool LSLocalSemaphore::WaitOn(AuUInt32 timeout)
{
return this->TryTakeWaitMS(timeout);
@ -133,7 +138,7 @@ namespace Aurora::IO::Loop
bool LSLocalSemaphore::TryTake()
{
return this->TryTakeNoSpin();
return this->TryTakeSpin();
}
bool LSLocalSemaphore::TryTakeWaitMS(AuUInt32 timeout)

View File

@ -20,6 +20,7 @@ namespace Aurora::IO::Loop
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
bool IsSignaledNoSpinIfUserland() override;
ELoopSource GetType() override;
bool AddOne() override;

View File

@ -1177,6 +1177,8 @@ namespace Aurora::IO::Loop
bool singular = source.source->Singular();
bool bPollTriggered = this->handleArrayOr_[queueIterator.startingIndexOr] == this->hDummy_;
bool bAltTrigger {};
if (!bPollTriggered)
{
if (!singular)
@ -1184,10 +1186,10 @@ namespace Aurora::IO::Loop
for (const auto &handle : source.source->GetHandles())
{
if ((firstTriggered == handle) ||
(::WaitForSingleObject(reinterpret_cast<HANDLE>(handle), 0) == WAIT_OBJECT_0))
(bAltTrigger = source.source->IsSignaledNoSpinIfUserland()))
{
lastHandle = handle;
wasTriggered = true;
wasTriggered = !bAltTrigger;
break;
}
}
@ -1196,15 +1198,15 @@ namespace Aurora::IO::Loop
{
auto handle = source.source->GetHandle();
if ((firstTriggered == handle) ||
(::WaitForSingleObject(reinterpret_cast<HANDLE>(handle), 0) == WAIT_OBJECT_0))
(bAltTrigger = source.source->IsSignaledNoSpinIfUserland()))
{
lastHandle = firstTriggered;
wasTriggered = true;
wasTriggered = !bAltTrigger;
}
}
}
if (bPollTriggered || (wasTriggered && source.source->OnTrigger(lastHandle)))
if (bPollTriggered || (bAltTrigger) || (wasTriggered && source.source->OnTrigger(lastHandle)))
{
bool failing {};

View File

@ -10,6 +10,11 @@
namespace Aurora::IO::Loop
{
bool WaitSingleBase::IsSignaledNoSpinIfUserland()
{
return this->IsSignaled();
}
bool WaitSingleBase::IsSignaled()
{
bool val {};

View File

@ -29,6 +29,7 @@ namespace Aurora::IO::Loop
struct WaitSingleBase : virtual ILoopSourceEx
{
virtual bool IsSignaledNoSpinIfUserland() override;
virtual bool IsSignaled() override;
virtual bool WaitOn(AuUInt32 timeout) override;

View File

@ -18,6 +18,8 @@ namespace Aurora::IO::Net
IPAddress NetAdapter::ToAddress()
{
AuMemory::GetDefaultDiscontiguousHeapShared()->NewClass<NetAdapter>();
return this->address;
}