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)