Fix sys_ppu_thread_start error checking, fix rare bug in sys_ppu_thread_create

* Correct error code to EBUSY.
* lv2_obj::awake was called even when EBSUY should be returned.
* Fix sys_ppu_thread_create for a newly created thread with the same id as ppu_thread::id_base. (can happen if main thread exited before its creation)
This commit is contained in:
Eladash 2020-04-29 08:03:07 +03:00
parent c1dc6838fa
commit dd6825a7bd
3 changed files with 23 additions and 15 deletions

View file

@ -441,26 +441,37 @@ error_code sys_ppu_thread_start(ppu_thread& ppu, u32 thread_id)
{
sys_ppu_thread.trace("sys_ppu_thread_start(thread_id=0x%x)", thread_id);
const auto thread = idm::get<named_thread<ppu_thread>>(thread_id, [&](ppu_thread& thread)
const auto thread = idm::get<named_thread<ppu_thread>>(thread_id, [&](ppu_thread& thread) -> CellError
{
if (thread.joiner == ppu_join_status::exited)
{
return false;
return CELL_ESRCH;
}
if (!thread.state.test_and_reset(cpu_flag::stop))
{
// Already started
return CELL_EBUSY;
}
lv2_obj::awake(&thread);
return true;
thread.cmd_list
({
{ppu_cmd::opd_call, 0}, thread.entry_func
});
return {};
});
if (!thread || !thread.ret)
if (!thread)
{
return CELL_ESRCH;
}
if (!thread->state.test_and_reset(cpu_flag::stop))
if (thread.ret)
{
// TODO: what happens there?
return CELL_EPERM;
return thread.ret;
}
else
{