From 5a73943be6e4e8dae5fd753838fbc0a87b6bdb2e Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 29 Feb 2020 11:41:16 +0200 Subject: [PATCH] Fix sys_timer_destroy Also some cleanup. --- rpcs3/Emu/Cell/lv2/sys_timer.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index d8fc9871b2..abf34c076c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -16,11 +16,9 @@ extern u64 get_guest_system_time(); void lv2_timer_context::operator()() { - while (!Emu.IsStopped()) + while (thread_ctrl::state() != thread_state::aborting) { - const u32 _state = state; - - if (_state == SYS_TIMER_STATE_RUN) + if (state == SYS_TIMER_STATE_RUN) { const u64 _now = get_guest_system_time(); const u64 next = expire; @@ -42,21 +40,16 @@ void lv2_timer_context::operator()() } // Stop after oneshot - state.compare_and_swap_test(SYS_TIMER_STATE_RUN, SYS_TIMER_STATE_STOP); + state.release(SYS_TIMER_STATE_STOP); continue; } // TODO: use single global dedicated thread for busy waiting, no timer threads lv2_obj::wait_timeout(next - _now); + continue; } - else if (_state == SYS_TIMER_STATE_STOP) - { - thread_ctrl::wait_for(10000); - } - else - { - break; - } + + thread_ctrl::wait_for(10000); } } @@ -83,13 +76,12 @@ error_code sys_timer_destroy(ppu_thread& ppu, u32 timer_id) const auto timer = idm::withdraw(timer_id, [&](lv2_timer& timer) -> CellError { - std::lock_guard lock(timer.mutex); - - if (!timer.port.expired()) + if (std::shared_lock lock(timer.mutex); !timer.port.expired()) { return CELL_EISCONN; } + timer = thread_state::aborting; return {}; });