From 3c0564c9b72040d0af062c95a6b522aa5bc4a09c Mon Sep 17 00:00:00 2001 From: eladash Date: Tue, 26 Mar 2019 21:08:49 +0200 Subject: [PATCH] Fix timer state after event queue was destroyed * Hw tests show state is unaffected by external destruction of the event queue * Minor race regarding state check fixed (can result in an undestroyable state) --- rpcs3/Emu/Cell/lv2/sys_timer.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index 755f42cbe7..8f27d2f354 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "Emu/Memory/vm.h" #include "Emu/System.h" #include "Emu/IdManager.h" @@ -33,17 +33,17 @@ void lv2_timer_context::operator()() if (const auto queue = port.lock()) { queue->send(source, data1, data2, next); - - if (period) - { - // Set next expiration time and check again (HACK) - expire += period; - continue; - } } - // Stop: oneshot or the event port was disconnected (TODO: is it correct?) - state = SYS_TIMER_STATE_STOP; + if (period) + { + // Set next expiration time and check again (HACK) + expire += period; + continue; + } + + // Stop after oneshot + state.compare_and_swap_test(SYS_TIMER_STATE_RUN, SYS_TIMER_STATE_STOP); continue; }