[*] cleanup: added gUseNativeWaitSemapahore

This commit is contained in:
Reece Wilson 2023-06-16 00:05:46 +01:00
parent 25b933aafa
commit 48075bfda7
4 changed files with 19 additions and 14 deletions

View File

@ -90,5 +90,7 @@ namespace Aurora
!gRuntimeConfig.threadingConfig.bPerferNt51XpCondvarsOver8 && !gRuntimeConfig.threadingConfig.bPerferNt51XpCondvarsOver8 &&
(pRtlWaitOnAddress || AuBuild::kCurrentPlatform != AuBuild::EPlatform::ePlatformWin32)) || (pRtlWaitOnAddress || AuBuild::kCurrentPlatform != AuBuild::EPlatform::ePlatformWin32)) ||
!pNtWaitForKeyedEvent; !pNtWaitForKeyedEvent;
gUseNativeWaitSemapahore = bool(pWaitOnAddress);
} }
} }

View File

@ -106,4 +106,5 @@ namespace Aurora
inline bool gUseNativeWaitMutex {}; inline bool gUseNativeWaitMutex {};
inline bool gUseNativeWaitCondvar {}; inline bool gUseNativeWaitCondvar {};
inline bool gUseNativeWaitSemapahore {};
} }

View File

@ -14,4 +14,6 @@
namespace Aurora namespace Aurora
{ {
void InitProcAddresses(); void InitProcAddresses();
inline bool gUseNativeWaitRWLock {};
} }

View File

@ -65,7 +65,7 @@ namespace Aurora::Threading::Primitives
AuUInt64 uStart = AuTime::SteadyClockNS(); AuUInt64 uStart = AuTime::SteadyClockNS();
AuUInt64 uEnd = uTimeout ? uStart + uTimeout : 0; AuUInt64 uEnd = uTimeout ? uStart + uTimeout : 0;
if (pWaitOnAddress) if (gUseNativeWaitSemapahore)
{ {
AuUInt32 uYieldCounter {}; AuUInt32 uYieldCounter {};
auto old = this->value_; auto old = this->value_;
@ -120,9 +120,21 @@ namespace Aurora::Threading::Primitives
void SemaphoreImpl::Unlock(long count) void SemaphoreImpl::Unlock(long count)
{ {
if (!pWaitOnAddress) if (gUseNativeWaitSemapahore)
{ {
AuAtomicAdd<AuInt32>(&this->value_, count);
if (count == 1)
{
pWakeByAddressSingle(&this->value_);
}
else
{
pWakeByAddressAll(&this->value_);
}
this->mutex.Lock(); this->mutex.Lock();
}
else
{
AuAtomicAdd<AuInt32>(&this->value_, count); AuAtomicAdd<AuInt32>(&this->value_, count);
if (count == 1) if (count == 1)
@ -139,18 +151,6 @@ namespace Aurora::Threading::Primitives
} }
this->mutex.Unlock(); this->mutex.Unlock();
} }
else
{
AuAtomicAdd<AuInt32>(&this->value_, count);
if (count == 1)
{
pWakeByAddressSingle(&this->value_);
}
else
{
pWakeByAddressAll(&this->value_);
}
}
} }
void SemaphoreImpl::Unlock() void SemaphoreImpl::Unlock()