[*] Simplify RWLock some more

This commit is contained in:
Reece Wilson 2023-09-23 02:40:23 +01:00
parent 0a1db024e8
commit 76bd36939e

View File

@ -566,6 +566,7 @@ namespace Aurora::Threading::Primitives
}
else
{
RWLockBarrierSelf();
this->GetCondition().Signal();
}
}
@ -581,6 +582,7 @@ namespace Aurora::Threading::Primitives
}
else
{
RWLockBarrierSelf();
this->GetConditionWriter().Signal();
}
}
@ -597,6 +599,7 @@ namespace Aurora::Threading::Primitives
}
else
{
RWLockBarrierSelf();
this->GetCondition().Broadcast();
}
}
@ -615,6 +618,7 @@ namespace Aurora::Threading::Primitives
}
else
{
RWLockBarrierSelf();
this->GetConditionWriter().Broadcast();
}
}
@ -725,29 +729,7 @@ namespace Aurora::Threading::Primitives
if (uVal == 0 || bAlt)
{
bool bElevation {};
if (!gUseFutexRWLock)
{
#if 0
RWLockAcquire; /* actually locking this->iState_, out of branch. required for the mutually exclusive correctness of the condition. this is a fence. */
bElevation = AuAtomicLoad(&this->dwWritersPending_) > 0;
#else
bElevation = AuAtomicLoad(&this->dwWritersPending_) > 0;
// Do barrier to ensure the sleep count is incremented and therefore validate the condition is in a to-wake state
if (bElevation)
{
RWLockBarrierSelf();
}
#endif
}
else
{
bElevation = AuAtomicLoad(&this->dwWritersPending_) > 0;
}
if (bElevation)
if (AuAtomicLoad(&this->dwWritersPending_) > 0)
{
this->SignalOneWriter();
}
@ -757,29 +739,13 @@ namespace Aurora::Threading::Primitives
template<bool bIsWriteRecursionAllowed>
void RWLockImpl<bIsWriteRecursionAllowed>::UnlockWrite()
{
bool bElevationPending {};
if constexpr (!bIsWriteRecursionAllowed)
{
this->reentrantWriteLockHandle_ = 0;
if (!gUseFutexRWLock)
{
AuAtomicStore(&this->iState_, 0);
AuAtomicStore(&this->iState_, 0);
bElevationPending = AuAtomicLoad(&this->dwWritersPending_) > 0;
if (bElevationPending)
{
RWLockBarrierSelf();
}
}
else
{
AuAtomicStore(&this->iState_, 0);
bElevationPending = AuAtomicLoad(&this->dwWritersPending_) > 0;
}
if (bElevationPending)
if (AuAtomicLoad(&this->dwWritersPending_) > 0)
{
this->SignalOneWriter();
}
@ -810,21 +776,7 @@ namespace Aurora::Threading::Primitives
if (val == 0)
{
if (!gUseFutexRWLock)
{
bElevationPending = AuAtomicLoad(&this->dwWritersPending_) > 0;
if (bElevationPending)
{
RWLockBarrierSelf();
}
}
else
{
bElevationPending = AuAtomicLoad(&this->dwWritersPending_) > 0;
}
if (bElevationPending)
if (AuAtomicLoad(&this->dwWritersPending_) > 0)
{
this->SignalOneWriter();
}
@ -974,11 +926,6 @@ namespace Aurora::Threading::Primitives
{
if (AuAtomicCompareExchange(&this->iState_, 1, -1) == -1)
{
if (!gUseFutexRWLock)
{
RWLockBarrierSelf();
}
this->SignalManyReader();
return true;
}