From e30be64c44929edcd7cdc41269e72d4e604e7e3d Mon Sep 17 00:00:00 2001 From: Reece Date: Wed, 30 Jun 2021 10:41:58 +0100 Subject: [PATCH] [*] Prevent pinning another WorkItems lock within the parent scope of some ::Fail's --- Source/Async/WorkItem.cpp | 51 ++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/Source/Async/WorkItem.cpp b/Source/Async/WorkItem.cpp index fabd5636..9ccb38b5 100644 --- a/Source/Async/WorkItem.cpp +++ b/Source/Async/WorkItem.cpp @@ -28,32 +28,55 @@ namespace Aurora::Async void WorkItem::WaitFor(const AuSPtr &workItem) { - auto dependency = std::reinterpret_pointer_cast(workItem); - - Threading::LockGuard l(lock); - Threading::LockGuard l2(dependency->lock); - - dependency->waiters_.push_back(shared_from_this()); - waitOn_.push_back(workItem); - } - - void WorkItem::WaitFor(const AuList> &workItems) - { - Threading::LockGuard l(lock); + bool status {}; - for (auto &workItem : workItems) { auto dependency = std::reinterpret_pointer_cast(workItem); + + Threading::LockGuard l(lock); Threading::LockGuard l2(dependency->lock); if (dependency->HasFailed()) { - Fail(); + status = true; } dependency->waiters_.push_back(shared_from_this()); waitOn_.push_back(workItem); } + + if (status) + { + Fail(); + } + } + + void WorkItem::WaitFor(const AuList> &workItems) + { + bool status {}; + + { + Threading::LockGuard l(lock); + + for (auto &workItem : workItems) + { + auto dependency = std::reinterpret_pointer_cast(workItem); + Threading::LockGuard l2(dependency->lock); + + if (dependency->HasFailed()) + { + status = true; + } + + dependency->waiters_.push_back(shared_from_this()); + waitOn_.push_back(workItem); + } + } + + if (status) + { + Fail(); + } } void WorkItem::SetSchedTime(AuUInt32 ms)