Fix sys_raw_spu_destroy

This commit is contained in:
Eladash 2020-03-15 08:10:33 +02:00 committed by Ivan
parent 33d01fd252
commit 9e14e835e7
2 changed files with 11 additions and 8 deletions

View file

@ -955,14 +955,15 @@ void spu_int_ctrl_t::set(u64 ints)
ints &= mask; ints &= mask;
// notify if at least 1 bit was set // notify if at least 1 bit was set
if (ints && ~stat.fetch_or(ints) & ints && !tag.expired()) if (ints && ~stat.fetch_or(ints) & ints)
{ {
reader_lock rlock(id_manager::g_mutex); std::shared_lock rlock(id_manager::g_mutex);
if (const auto tag_ptr = tag.lock()) if (const auto tag_ptr = tag.lock())
{ {
if (auto handler = tag_ptr->handler.lock()) if (auto handler = tag_ptr->handler.lock())
{ {
rlock.unlock();
handler->exec(); handler->exec();
} }
} }

View file

@ -1690,7 +1690,12 @@ error_code sys_raw_spu_destroy(ppu_thread& ppu, u32 id)
sys_spu.warning("sys_raw_spu_destroy(id=%d)", id); sys_spu.warning("sys_raw_spu_destroy(id=%d)", id);
const auto thread = idm::get<named_thread<spu_thread>>(spu_thread::find_raw_spu(id)); auto thread = idm::get<named_thread<spu_thread>>(spu_thread::find_raw_spu(id), [](named_thread<spu_thread>& thread)
{
// Stop thread
thread.state += cpu_flag::exit;
thread = thread_state::aborting;
});
if (!thread) [[unlikely]] if (!thread) [[unlikely]]
{ {
@ -1699,9 +1704,6 @@ error_code sys_raw_spu_destroy(ppu_thread& ppu, u32 id)
// TODO: CELL_EBUSY is not returned // TODO: CELL_EBUSY is not returned
// Stop thread
thread->state += cpu_flag::stop;
// Kernel objects which must be removed // Kernel objects which must be removed
std::vector<std::pair<std::shared_ptr<lv2_obj>, u32>> to_remove; std::vector<std::pair<std::shared_ptr<lv2_obj>, u32>> to_remove;
@ -1742,7 +1744,7 @@ error_code sys_raw_spu_destroy(ppu_thread& ppu, u32 id)
idm::remove_verify<lv2_obj, lv2_int_serv>(pair.second, std::move(pair.first)); idm::remove_verify<lv2_obj, lv2_int_serv>(pair.second, std::move(pair.first));
} }
if (!idm::remove_verify<named_thread<spu_thread>>(thread->id, std::move(thread))) if (!idm::remove_verify<named_thread<spu_thread>>(id, std::move(thread)))
{ {
// Other thread destroyed beforehead // Other thread destroyed beforehead
return CELL_ESRCH; return CELL_ESRCH;
@ -1770,7 +1772,7 @@ error_code sys_raw_spu_create_interrupt_tag(ppu_thread& ppu, u32 id, u32 class_i
auto thread = idm::check_unlocked<named_thread<spu_thread>>(spu_thread::find_raw_spu(id)); auto thread = idm::check_unlocked<named_thread<spu_thread>>(spu_thread::find_raw_spu(id));
if (!thread) if (!thread || *thread == thread_state::aborting)
{ {
error = CELL_ESRCH; error = CELL_ESRCH;
return result; return result;