[*] RWLock: Upgrade UpgradeReadToWrite sleep path
This commit is contained in:
parent
68b4fe5f8b
commit
e2909ebe74
@ -162,7 +162,7 @@ namespace Aurora::Threading::Primitives
|
||||
|
||||
if (uTimeout)
|
||||
{
|
||||
iSecondTimeout = uTimeout - AuTime::SteadyClockNS();
|
||||
iSecondTimeout = AuInt64(uTimeout) - AuTime::SteadyClockNS();
|
||||
|
||||
if (iSecondTimeout <= 0)
|
||||
{
|
||||
@ -269,21 +269,20 @@ namespace Aurora::Threading::Primitives
|
||||
}
|
||||
}
|
||||
|
||||
AuAtomicAdd(&this->writersPending_, 1);
|
||||
|
||||
AU_LOCK_GUARD(this->mutex_);
|
||||
AuAtomicAdd(&this->writersPending_, 1);
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (this->state_ != 0)
|
||||
{
|
||||
AuInt64 uSecondTimeout = 0;
|
||||
AuInt64 iSecondTimeout = 0;
|
||||
|
||||
if (uTimeout)
|
||||
{
|
||||
uSecondTimeout = uTimeout - AuTime::SteadyClockNS();
|
||||
iSecondTimeout = AuInt64(uTimeout) - AuTime::SteadyClockNS();
|
||||
|
||||
if (uSecondTimeout <= 0)
|
||||
if (iSecondTimeout <= 0)
|
||||
{
|
||||
AuAtomicSub(&this->writersPending_, 1);
|
||||
return false;
|
||||
@ -291,9 +290,9 @@ namespace Aurora::Threading::Primitives
|
||||
}
|
||||
|
||||
#if defined(AURWLOCK_NO_SIZE_OPTIMIZED_CONDVAR)
|
||||
if (!this->GetConditionWriter().WaitForSignalNS(uSecondTimeout))
|
||||
if (!this->GetConditionWriter().WaitForSignalNS(iSecondTimeout))
|
||||
#else
|
||||
if (!this->GetConditionWriter().WaitForSignalNsEx(AuUnsafeRaiiToShared(&this->mutex_), uSecondTimeout))
|
||||
if (!this->GetConditionWriter().WaitForSignalNsEx(AuUnsafeRaiiToShared(&this->mutex_), iSecondTimeout))
|
||||
#endif
|
||||
{
|
||||
AuAtomicSub(&this->writersPending_, 1);
|
||||
@ -348,9 +347,8 @@ namespace Aurora::Threading::Primitives
|
||||
}
|
||||
}
|
||||
|
||||
AuAtomicAdd(&this->writersPending_, 1);
|
||||
|
||||
AU_LOCK_GUARD(this->mutex_);
|
||||
AuAtomicAdd(&this->writersPending_, 1);
|
||||
|
||||
AuInt64 uEndTime = uTimeout ? AuTime::SteadyClockNS() + uTimeout : 0;
|
||||
|
||||
@ -561,15 +559,45 @@ namespace Aurora::Threading::Primitives
|
||||
}
|
||||
|
||||
template<bool bIsWriteRecursionAllowed>
|
||||
bool RWLockImpl<bIsWriteRecursionAllowed>::UpgradeReadToWrite(AuUInt64 timeout)
|
||||
bool RWLockImpl<bIsWriteRecursionAllowed>::UpgradeReadToWrite(AuUInt64 uTimeout)
|
||||
{
|
||||
if (this->state_ == 1)
|
||||
{
|
||||
AU_LOCK_GUARD(this->mutex_);
|
||||
|
||||
while (this->state_ != 1)
|
||||
if (this->state_ == 1)
|
||||
{
|
||||
this->reentrantWriteLockHandle_ = GetThreadCookie();
|
||||
this->state_ = -1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
auto uEndTime = uTimeout ? AuTime::SteadyClockNS() + uTimeout : 0;
|
||||
|
||||
AU_LOCK_GUARD(this->mutex_);
|
||||
AuAtomicAdd(&this->writersPending_, 1);
|
||||
|
||||
if (!this->GetConditionWriter().WaitForSignal(timeout))
|
||||
while (this->state_ != 1)
|
||||
{
|
||||
AuInt64 iSecondTimeout {};
|
||||
|
||||
if (uTimeout)
|
||||
{
|
||||
iSecondTimeout = AuInt64(uEndTime) - AuTime::SteadyClockNS();
|
||||
|
||||
if (iSecondTimeout <= 0)
|
||||
{
|
||||
AuAtomicSub(&this->writersPending_, 1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(AURWLOCK_NO_SIZE_OPTIMIZED_CONDVAR)
|
||||
if (!this->GetConditionWriter().WaitForSignalNS(iSecondTimeout))
|
||||
#else
|
||||
if (!this->GetConditionWriter().WaitForSignalNsEx(AuUnsafeRaiiToShared(&this->mutex_), iSecondTimeout))
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user