diff --git a/Source/Async/GroupState.cpp b/Source/Async/GroupState.cpp index a10b3679..0e148c42 100644 --- a/Source/Async/GroupState.cpp +++ b/Source/Async/GroupState.cpp @@ -20,8 +20,7 @@ namespace Aurora::Async AuSPtr GroupState::GetThreadByIndex(ThreadId_t uIndex) { - AU_LOCK_GUARD(this->workersMutex); - + // TODO: deinit mutex if (AuArraySize(this->wpWorkers) > uIndex) { if (auto pState = AuTryLockMemoryType(this->wpWorkers[uIndex])) @@ -30,6 +29,8 @@ namespace Aurora::Async } } + AU_LOCK_GUARD(this->workersMutex); + auto itr = this->workers.find(uIndex); if (itr == this->workers.end()) { diff --git a/Source/IO/Loop/LoopQueue.NT.cpp b/Source/IO/Loop/LoopQueue.NT.cpp index 75f56e44..bb84eaf3 100644 --- a/Source/IO/Loop/LoopQueue.NT.cpp +++ b/Source/IO/Loop/LoopQueue.NT.cpp @@ -653,7 +653,7 @@ namespace Aurora::IO::Loop { if (this->bIsWinLoop_) { - status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayAnd_.data() + index, timeDelta, QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); + status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayAnd_.data() + index, timeDelta, QS_ALLINPUT | QS_ALLPOSTMESSAGE, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); } else { @@ -881,7 +881,7 @@ namespace Aurora::IO::Loop { do { - status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayOr_.data() + index, sleepMS, QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); + status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayOr_.data() + index, sleepMS, QS_ALLINPUT | QS_ALLPOSTMESSAGE, MWMO_ALERTABLE); { auto temp2 = status; @@ -983,7 +983,7 @@ namespace Aurora::IO::Loop { if (this->bIsWinLoop_) { - temp = ::MsgWaitForMultipleObjectsEx(this->handleArrayOr_.size(), this->handleArrayOr_.data(), sleepDelta, QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); + temp = ::MsgWaitForMultipleObjectsEx(this->handleArrayOr_.size(), this->handleArrayOr_.data(), sleepDelta, QS_ALLINPUT | QS_ALLPOSTMESSAGE, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); } else { @@ -1032,11 +1032,15 @@ namespace Aurora::IO::Loop } else { - if (!poll && - TryPumpWin32()) + static Aurora::Utility::RateLimiter limit(AuMSToNS(24)); + + if (limit.CheckExchangePass()) { - triggeredCount++; - bTriggerWin32 = true; + if (!poll && TryPumpWin32()) + { + triggeredCount++; + bTriggerWin32 = true; + } } } diff --git a/Source/Threading/Primitives/AuRWLock.cpp b/Source/Threading/Primitives/AuRWLock.cpp index 1be4bbc0..c9893744 100644 --- a/Source/Threading/Primitives/AuRWLock.cpp +++ b/Source/Threading/Primitives/AuRWLock.cpp @@ -653,8 +653,19 @@ namespace Aurora::Threading::Primitives if (!gUseFutexRWLock) { + #if 0 AU_LOCK_GUARD(this->mutex_); /* actually locking this->state_, out of branch. required for the mutually exclusive correctness of the condition. this is a fence. */ bElevation = AuAtomicLoad(&this->writersPending_) > 0; + #else + bElevation = AuAtomicLoad(&this->writersPending_) > 0; + + // Do barrier to ensure the sleep count is incremented and therefore validate the condition is in a to-wake state + if (bElevation) + { + this->mutex_.Lock(); + this->mutex_.Unlock(); + } + #endif } else { @@ -769,8 +780,8 @@ namespace Aurora::Threading::Primitives if (!gUseFutexRWLock) { - AU_LOCK_GUARD(this->mutex_); AuAtomicAdd(&this->writersPending_, 1); + AU_LOCK_GUARD(this->mutex_); while (this->state_ != 1) {