From 08612262719194521ab66c31aeced8b6b7d94299 Mon Sep 17 00:00:00 2001 From: eladash Date: Sat, 9 Feb 2019 11:34:36 +0200 Subject: [PATCH] Make more use of the new atomic_t<>::release --- rpcs3/Emu/Cell/PPUThread.cpp | 14 ++++---- rpcs3/Emu/Cell/SPUThread.cpp | 54 ++++++++++++++++-------------- rpcs3/Emu/Cell/SPUThread.h | 8 ++--- rpcs3/Emu/Cell/lv2/sys_lwcond.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp | 2 +- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 87a27546e4..843f819e01 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -1092,17 +1092,18 @@ extern bool ppu_stwcx(ppu_thread& ppu, u32 addr, u32 reg_value) vm::passive_unlock(ppu); auto& res = vm::reservation_lock(addr, sizeof(u32)); + const u64 old_time = res.load() & ~1ull; - const bool result = ppu.rtime == (res & ~1ull) && data.compare_and_swap_test(old_data, reg_value); + const bool result = ppu.rtime == old_time && data.compare_and_swap_test(old_data, reg_value); if (result) { - res++; + res.release(old_time + 2); vm::reservation_notifier(addr, sizeof(u32)).notify_all(); } else { - res &= ~1ull; + res.release(old_time); } vm::passive_lock(ppu); @@ -1185,17 +1186,18 @@ extern bool ppu_stdcx(ppu_thread& ppu, u32 addr, u64 reg_value) vm::passive_unlock(ppu); auto& res = vm::reservation_lock(addr, sizeof(u64)); + const u64 old_time = res.load() & ~1ull; - const bool result = ppu.rtime == (res & ~1ull) && data.compare_and_swap_test(old_data, reg_value); + const bool result = ppu.rtime == old_time && data.compare_and_swap_test(old_data, reg_value); if (result) { - res++; + res.release(old_time + 2); vm::reservation_notifier(addr, sizeof(u64)).notify_all(); } else { - res &= ~1ull; + res.release(old_time); } vm::passive_lock(ppu); diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 15bbe78db9..96973c6c17 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -471,20 +471,20 @@ void spu_thread::cpu_init() ch_tag_upd = 0; ch_tag_mask = 0; mfc_prxy_mask = 0; - ch_tag_stat.data.store({}); + ch_tag_stat.data.release({}); ch_stall_mask = 0; - ch_stall_stat.data.store({}); - ch_atomic_stat.data.store({}); + ch_stall_stat.data.release({}); + ch_atomic_stat.data.release({}); ch_in_mbox.clear(); - ch_out_mbox.data.store({}); - ch_out_intr_mbox.data.store({}); + ch_out_mbox.data.release({}); + ch_out_intr_mbox.data.release({}); snr_config = 0; - ch_snr1.data.store({}); - ch_snr2.data.store({}); + ch_snr1.data.release({}); + ch_snr2.data.release({}); ch_event_mask = 0; ch_event_stat = 0; @@ -494,9 +494,9 @@ void spu_thread::cpu_init() ch_dec_start_timestamp = get_timebased_time(); // ??? ch_dec_value = 0; - run_ctrl = 0; - status = 0; - npc = 0; + run_ctrl.release(0); + status.release(0); + npc.release(0); int_ctrl[0].clear(); int_ctrl[1].clear(); @@ -810,28 +810,28 @@ void spu_thread::do_dma_transfer(const spu_mfc_cmd& args) { auto& res = vm::reservation_lock(eal, 1); *reinterpret_cast(dst) = *reinterpret_cast(src); - res++; + res.release(res.load() + 1); break; } case 2: { auto& res = vm::reservation_lock(eal, 2); *reinterpret_cast(dst) = *reinterpret_cast(src); - res++; + res.release(res.load() + 1); break; } case 4: { auto& res = vm::reservation_lock(eal, 4); *reinterpret_cast(dst) = *reinterpret_cast(src); - res++; + res.release(res.load() + 1); break; } case 8: { auto& res = vm::reservation_lock(eal, 8); *reinterpret_cast(dst) = *reinterpret_cast(src); - res++; + res.release(res.load() + 1); break; } default: @@ -850,7 +850,7 @@ void spu_thread::do_dma_transfer(const spu_mfc_cmd& args) size -= 16; } - res++; + res.release(res.load() + 1); break; } @@ -874,7 +874,7 @@ void spu_thread::do_dma_transfer(const spu_mfc_cmd& args) size -= 16; } - *lock = 0; + lock->release(0); break; } } @@ -1086,12 +1086,12 @@ void spu_thread::do_putlluc(const spu_mfc_cmd& args) // TODO: vm::check_addr vm::writer_lock lock(addr); mov_rdata(data.data(), to_write.data()); - res++; + res.release(res.load() + 1); } else { mov_rdata(data.data(), to_write.data()); - res++; + res.release(res.load() + 1); } } @@ -1281,6 +1281,7 @@ bool spu_thread::process_mfc_cmd() else { auto& res = vm::reservation_lock(addr, 128); + const u64 old_time = res.load() & ~1ull; if (g_cfg.core.spu_accurate_getllar) { @@ -1290,15 +1291,15 @@ bool spu_thread::process_mfc_cmd() // TODO: vm::check_addr vm::writer_lock lock(addr); - ntime = res & ~1ull; + ntime = old_time; mov_rdata(dst.data(), data.data()); - res &= ~1ull; + res.release(old_time); } else { - ntime = res & ~1ull; + ntime = old_time; mov_rdata(dst.data(), data.data()); - res &= ~1ull; + res.release(old_time); } } @@ -1355,8 +1356,9 @@ bool spu_thread::process_mfc_cmd() else if (auto& data = vm::_ref(addr); rdata == data) { auto& res = vm::reservation_lock(raddr, 128); + const u64 old_time = res.load() & ~1ull; - if (rtime == (res & ~1ull)) + if (rtime == old_time) { *reinterpret_cast*>(&data) += 0; @@ -1367,17 +1369,17 @@ bool spu_thread::process_mfc_cmd() if (rdata == data) { mov_rdata(data.data(), to_write.data()); - res++; + res.release(old_time + 2); result = 1; } else { - res &= ~1ull; + res.release(old_time); } } else { - res &= ~1ull; + res.release(old_time); } } } diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index 21bd74d22c..55181a622d 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -276,8 +276,8 @@ struct spu_channel_4_t public: void clear() { - values.store({}); - value3 = 0; + values.release({}); + value3.release(0); } // push unconditionally (overwriting latest value), returns true if needs signaling @@ -364,8 +364,8 @@ struct spu_int_ctrl_t void clear() { - mask = 0; - stat = 0; + mask.release(0); + stat.release(0); tag = nullptr; } }; diff --git a/rpcs3/Emu/Cell/lv2/sys_lwcond.cpp b/rpcs3/Emu/Cell/lv2/sys_lwcond.cpp index f5645fb371..92537e81d9 100644 --- a/rpcs3/Emu/Cell/lv2/sys_lwcond.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_lwcond.cpp @@ -266,7 +266,7 @@ error_code _sys_lwcond_queue_wait(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id return cpu; } - mutex->signaled = 1; + mutex->signaled.release(1); return nullptr; }); diff --git a/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp b/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp index 7ebaffc224..8e1ee29c5c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp @@ -175,7 +175,7 @@ error_code _sys_lwmutex_unlock(ppu_thread& ppu, u32 lwmutex_id) return cpu; } - mutex.signaled = 1; + mutex.signaled.release(1); return nullptr; });