diff --git a/Source/Async/GroupState.cpp b/Source/Async/GroupState.cpp index 0fb0a47c..35fd7f59 100644 --- a/Source/Async/GroupState.cpp +++ b/Source/Async/GroupState.cpp @@ -76,13 +76,7 @@ namespace Aurora::Async } AuAtomicAdd(&pWorker->cvHasWork, 1u); - - pWorker->cvVariable->Broadcast(); - - if (auto pEventLS = pWorker->eventLs) - { - pEventLS->Set(); - } + pWorker->SetEvent(); } } diff --git a/Source/Async/ThreadPool.cpp b/Source/Async/ThreadPool.cpp index 0f810691..f9c5d8c9 100644 --- a/Source/Async/ThreadPool.cpp +++ b/Source/Async/ThreadPool.cpp @@ -160,10 +160,7 @@ namespace Aurora::Async pWorker->cvVariable->Signal(); } - if (AuAtomicTestAndSet(&pWorker->cvLSActive, 0u) == 0) - { - pWorker->eventLs->Set(); - } + pWorker->SetEvent(false); } } diff --git a/Source/Async/ThreadState.hpp b/Source/Async/ThreadState.hpp index 1f73dab1..ffd298f5 100644 --- a/Source/Async/ThreadState.hpp +++ b/Source/Async/ThreadState.hpp @@ -75,6 +75,22 @@ namespace Aurora::Async AuSPtr eventLs; AuSPtr asyncLoopSourceShared; + inline void SetEvent(bool bBoth = true) + { + if (auto pEvent = this->eventLs) + { + if (AuAtomicTestAndSet(&this->cvLSActive, 0u) == 0) + { + pEvent->Set(); + } + } + + if (bBoth) + { + this->cvVariable->Signal(); + } + } + // AuUInt32 uShutdownFence { 1 }; }; diff --git a/Source/Async/ThreadWorkerQueueShim.cpp b/Source/Async/ThreadWorkerQueueShim.cpp index 2d8cdd83..566195fb 100644 --- a/Source/Async/ThreadWorkerQueueShim.cpp +++ b/Source/Async/ThreadWorkerQueueShim.cpp @@ -17,7 +17,7 @@ namespace Aurora::Async { if (LoopQueue::Commit()) { - this->commitPending_ = false; + AuAtomicSub(&this->commitPending_, 1u); } } } @@ -54,11 +54,17 @@ namespace Aurora::Async void AsyncLoop::Schedule() { - this->commitPending_ = true; - if (AuThreads::GetThread() != this->pParent->threadObject.get()) { - this->pParent->cvVariable->Broadcast(); + AuAtomicAdd(&this->commitPending_, 1u); + { + AU_LOCK_GUARD(this->pParent->parent.lock()->workQueue.mutex); + this->pParent->SetEvent(); + } + } + else + { + this->commitPending_ = 1; } } diff --git a/Source/Async/ThreadWorkerQueueShim.hpp b/Source/Async/ThreadWorkerQueueShim.hpp index cad09f9a..7dc98323 100644 --- a/Source/Async/ThreadWorkerQueueShim.hpp +++ b/Source/Async/ThreadWorkerQueueShim.hpp @@ -26,6 +26,6 @@ namespace Aurora::Async bool CommitPending(); private: - bool commitPending_ {}; + AuUInt32 commitPending_ {}; }; } \ No newline at end of file diff --git a/Source/IO/AuIOProcessor.cpp b/Source/IO/AuIOProcessor.cpp index 3e6b72ca..e0c5c659 100644 --- a/Source/IO/AuIOProcessor.cpp +++ b/Source/IO/AuIOProcessor.cpp @@ -728,11 +728,6 @@ namespace Aurora::IO const AuSPtr &pListener, bool bSingleshot) { - if (!CheckThread()) - { - AU_THROW_STRING("Wrong Thread"); - } - auto item = AuMakeShared(); if (!item) { diff --git a/Source/IO/Loop/LoopQueue.NT.cpp b/Source/IO/Loop/LoopQueue.NT.cpp index 2ec353a6..b7a33b3e 100644 --- a/Source/IO/Loop/LoopQueue.NT.cpp +++ b/Source/IO/Loop/LoopQueue.NT.cpp @@ -375,6 +375,7 @@ namespace Aurora::IO::Loop try { AU_DEBUG_MEMCRUNCH; + AU_LOCK_GUARD(this->sourceMutex_); bool bShouldRebuild {};