Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys_ppu: Hotfix for detached threads #7658

Merged
merged 1 commit into from
Mar 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 10 additions & 13 deletions rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,24 @@ void _sys_ppu_thread_exit(ppu_thread& ppu, u64 errorcode)

if (jid == umax)
{
// Detach detached thread, id will be removed on cleanup
static thread_local struct cleanup_t
// Simple structure to cleanup previous thread, because can't remove its own thread
struct ppu_thread_cleaner
{
const u32 id;
atomic_t<u32> id = 0;
};

cleanup_t(u32 id)
: id(id)
{
}
auto cleaner = g_fxo->get<ppu_thread_cleaner>();

cleanup_t(const cleanup_t&) = delete;

~cleanup_t()
if (cleaner->id || !cleaner->id.compare_and_swap_test(0, ppu.id)) [[likely]]
{
if (u32 old_id = cleaner->id.exchange(ppu.id))
{
if (!idm::remove<named_thread<ppu_thread>>(id))
if (!idm::remove<named_thread<ppu_thread>>(old_id))
{
sys_ppu_thread.fatal("Failed to remove detached thread! (id=0x%x)", id);
sys_ppu_thread.fatal("Failed to remove detached thread 0x%x", old_id);
}
}
}
to_cleanup(ppu.id);
}
else if (jid != 0)
{
Expand Down