[*] Prevent pinning another WorkItems lock within the parent scope of some ::Fail's

This commit is contained in:
Reece Wilson 2021-06-30 10:41:58 +01:00
parent 6de84b474e
commit e30be64c44

View File

@ -28,32 +28,55 @@ namespace Aurora::Async
void WorkItem::WaitFor(const AuSPtr<IWorkItem> &workItem) void WorkItem::WaitFor(const AuSPtr<IWorkItem> &workItem)
{ {
auto dependency = std::reinterpret_pointer_cast<WorkItem>(workItem); bool status {};
Threading::LockGuard<Threading::Primitives::SpinLock> l(lock);
Threading::LockGuard<Threading::Primitives::SpinLock> l2(dependency->lock);
dependency->waiters_.push_back(shared_from_this());
waitOn_.push_back(workItem);
}
void WorkItem::WaitFor(const AuList<AuSPtr<IWorkItem>> &workItems)
{
Threading::LockGuard<Threading::Primitives::SpinLock> l(lock);
for (auto &workItem : workItems)
{ {
auto dependency = std::reinterpret_pointer_cast<WorkItem>(workItem); auto dependency = std::reinterpret_pointer_cast<WorkItem>(workItem);
Threading::LockGuard<Threading::Primitives::SpinLock> l(lock);
Threading::LockGuard<Threading::Primitives::SpinLock> l2(dependency->lock); Threading::LockGuard<Threading::Primitives::SpinLock> l2(dependency->lock);
if (dependency->HasFailed()) if (dependency->HasFailed())
{ {
Fail(); status = true;
} }
dependency->waiters_.push_back(shared_from_this()); dependency->waiters_.push_back(shared_from_this());
waitOn_.push_back(workItem); waitOn_.push_back(workItem);
} }
if (status)
{
Fail();
}
}
void WorkItem::WaitFor(const AuList<AuSPtr<IWorkItem>> &workItems)
{
bool status {};
{
Threading::LockGuard<Threading::Primitives::SpinLock> l(lock);
for (auto &workItem : workItems)
{
auto dependency = std::reinterpret_pointer_cast<WorkItem>(workItem);
Threading::LockGuard<Threading::Primitives::SpinLock> 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) void WorkItem::SetSchedTime(AuUInt32 ms)