diff --git a/rpcs3/Emu/Cell/Modules/cellVdec.cpp b/rpcs3/Emu/Cell/Modules/cellVdec.cpp index aec18bd4fc..749facb6b7 100644 --- a/rpcs3/Emu/Cell/Modules/cellVdec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellVdec.cpp @@ -116,7 +116,7 @@ struct vdec_context final u32 frc_set{}; // Frame Rate Override u64 next_pts{}; u64 next_dts{}; - u32 ppu_tid{}; + atomic_t ppu_tid{}; std::deque out; atomic_t out_max = 60; @@ -202,7 +202,7 @@ struct vdec_context final void exec(ppu_thread& ppu, u32 vid) { - ppu_tid = ppu.id; + ppu_tid.release(ppu.id); // pcmd can be nullptr for (auto* pcmd : in_cmd) @@ -687,12 +687,17 @@ error_code cellVdecClose(ppu_thread& ppu, u32 handle) vdec->out_max = 0; vdec->in_cmd.push(vdec_close); - while (!atomic_storage::load(vdec->ppu_tid)) + while (!vdec->ppu_tid) { thread_ctrl::wait_for(1000); } - ppu_execute<&sys_interrupt_thread_disestablish>(ppu, vdec->ppu_tid); + const u32 tid = vdec->ppu_tid.exchange(-1); + + if (tid != umax) + { + ppu_execute<&sys_interrupt_thread_disestablish>(ppu, tid); + } if (!idm::remove_verify(handle, std::move(vdec))) {