[*] Minor mostly unnoticeable primitive improvements

This commit is contained in:
Reece Wilson 2023-06-23 20:05:53 +01:00
parent 74e036b809
commit 0d05fd3d33
3 changed files with 26 additions and 11 deletions

View File

@ -96,10 +96,12 @@ namespace Aurora::Threading::Primitives
}
void EventImpl::Set()
{
{
AU_LOCK_GUARD(this->mutex_);
SysAssertExp((this->bPermitMultipleTriggers_) || (!this->bTriggered_), "Can not trigger an awake event object");
this->bTriggered_ = true;
}
this->condition_.Broadcast();
}

View File

@ -316,9 +316,12 @@ namespace Aurora::Threading::Primitives
return;
}
AU_LOCK_GUARD(this->mutex_);
AuInt32 val {};
auto val = AuAtomicSub(&this->state_, 1);
{
AU_LOCK_GUARD(this->mutex_);
val = AuAtomicSub(&this->state_, 1);
}
if ((val == 1) && (this->bElevaterPending_))
{
@ -335,20 +338,30 @@ namespace Aurora::Threading::Primitives
template<bool bIsWriteRecursionAllowed>
void RWLockImpl<bIsWriteRecursionAllowed>::UnlockWrite()
{
AU_LOCK_GUARD(this->mutex_);
if constexpr (!bIsWriteRecursionAllowed)
{
{
AU_LOCK_GUARD(this->mutex_);
this->reentrantWriteLockHandle_ = 0;
this->state_ = 0;
}
this->GetConditionWriter().Broadcast();
this->GetCondition().Broadcast();
}
else
{
if (AuAtomicAdd(&this->state_, 1) == 0)
AuInt32 val {};
{
AU_LOCK_GUARD(this->mutex_);
val = AuAtomicAdd(&this->state_, 1);
this->reentrantWriteLockHandle_ = 0;
}
if (val == 0)
{
this->GetConditionWriter().Broadcast();
this->GetCondition().Broadcast();
}

View File

@ -134,8 +134,9 @@ namespace Aurora::Threading::Primitives
}
else
{
this->mutex.Lock();
this->mutex.Lock(); // do not remove
AuAtomicAdd<AuInt32>(&this->value_, count);
this->mutex.Unlock();
if (count == 1)
{
@ -149,7 +150,6 @@ namespace Aurora::Threading::Primitives
this->var.Signal();
}
}
this->mutex.Unlock();
}
}