Fix sys_spu_thread_un/bind_queue queue existence check

This commit is contained in:
Eladash 2019-11-27 21:52:38 +02:00 committed by Ivan
commit 8bd52c9843

View file

@ -1219,31 +1219,39 @@ error_code sys_spu_thread_bind_queue(ppu_thread& ppu, u32 id, u32 spuq, u32 spuq
std::lock_guard lock(thread->group->mutex); std::lock_guard lock(thread->group->mutex);
decltype(std::data(thread->spuq)) q{};
for (auto& v : thread->spuq) for (auto& v : thread->spuq)
{ {
if (auto q = v.second.lock()) // Check if the entry is assigned at all
if (const decltype(v.second) test{};
!v.second.owner_before(test) && !test.owner_before(v.second))
{ {
if (v.first == spuq_num || q == queue) if (!q)
{
q = &v;
}
continue;
}
if (v.first == spuq_num ||
(!v.second.owner_before(queue) && !queue.owner_before(v.second)))
{ {
return CELL_EBUSY; return CELL_EBUSY;
} }
} }
}
for (auto& v : thread->spuq) if (!q)
{ {
if (v.second.expired())
{
v.first = spuq_num;
v.second = queue;
return CELL_OK;
}
}
return CELL_EAGAIN; return CELL_EAGAIN;
} }
q->first = spuq_num;
q->second = queue;
return CELL_OK;
}
error_code sys_spu_thread_unbind_queue(ppu_thread& ppu, u32 id, u32 spuq_num) error_code sys_spu_thread_unbind_queue(ppu_thread& ppu, u32 id, u32 spuq_num)
{ {
vm::temporary_unlock(ppu); vm::temporary_unlock(ppu);
@ -1261,12 +1269,19 @@ error_code sys_spu_thread_unbind_queue(ppu_thread& ppu, u32 id, u32 spuq_num)
for (auto& v : thread->spuq) for (auto& v : thread->spuq)
{ {
if (v.first == spuq_num && !v.second.expired()) if (v.first != spuq_num)
{ {
v.second.reset(); continue;
return CELL_OK;
} }
if (const decltype(v.second) test{};
!v.second.owner_before(test) && !test.owner_before(v.second))
{
continue;
}
v.second.reset();
return CELL_OK;
} }
return CELL_ESRCH; return CELL_ESRCH;