diff --git a/rpcs3/Emu/CPU/CPUThread.h b/rpcs3/Emu/CPU/CPUThread.h index cfe76c9539..b6e44aa891 100644 --- a/rpcs3/Emu/CPU/CPUThread.h +++ b/rpcs3/Emu/CPU/CPUThread.h @@ -92,7 +92,7 @@ public: std::string get_name() const; // Get CPU state dump (everything) - virtual std::string dump_all() const = 0; + virtual std::string dump_all() const; // Get CPU register dump virtual std::string dump_regs() const; @@ -112,12 +112,6 @@ public: // Callback for cpu_flag::suspend virtual void cpu_sleep() {} - // Callback for cpu_flag::memory - virtual void cpu_mem() {} - - // Callback for vm::temporary_unlock - virtual void cpu_unmem() {} - // Callback for cpu_flag::ret virtual void cpu_return() {} diff --git a/rpcs3/Emu/Cell/PPUFunction.h b/rpcs3/Emu/Cell/PPUFunction.h index 0246038593..531f780071 100644 --- a/rpcs3/Emu/Cell/PPUFunction.h +++ b/rpcs3/Emu/Cell/PPUFunction.h @@ -86,9 +86,9 @@ namespace ppu_func_detail template struct bind_arg { - static_assert(std::is_same, ppu_thread>::value, "Invalid function argument type for ARG_CONTEXT"); + static_assert(std::is_base_of, ppu_thread>::value, "Invalid function argument type for ARG_CONTEXT"); - static FORCE_INLINE ppu_thread& get_arg(ppu_thread& ppu) + static FORCE_INLINE T& get_arg(ppu_thread& ppu) { return ppu; } @@ -184,7 +184,7 @@ namespace ppu_func_detail // TODO: check calculations const bool is_float = std::is_floating_point::value; const bool is_vector = std::is_same, v128>::value; - const bool is_context = std::is_same, ppu_thread>::value; + const bool is_context = std::is_base_of, ppu_thread>::value; const bool is_variadic = std::is_same, ppu_va_args_t>::value; const bool is_general = !is_float && !is_vector && !is_context && !is_variadic; diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 7db4f03ef1..7e5844add7 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -5,6 +5,7 @@ #include "Crypto/sha1.h" #include "Emu/perf_meter.hpp" #include "Emu/Memory/vm_reservation.h" +#include "Emu/Memory/vm_locking.h" #include "Emu/RSX/RSXThread.h" #include "Emu/VFS.h" #include "PPUThread.h" @@ -748,21 +749,20 @@ void ppu_thread::cpu_task() void ppu_thread::cpu_sleep() { - raddr = 0; // Clear reservation - vm::temporary_unlock(*this); + // Clear reservation + raddr = 0; + + // Setup wait flag and memory flags to relock itself + state += cpu_flag::wait + cpu_flag::memory; + + if (auto ptr = vm::g_tls_locked) + { + ptr->compare_and_swap(this, nullptr); + } + lv2_obj::awake(this); } -void ppu_thread::cpu_mem() -{ - vm::passive_lock(*this); -} - -void ppu_thread::cpu_unmem() -{ - state.test_and_set(cpu_flag::memory); -} - void ppu_thread::exec_task() { if (g_cfg.core.ppu_decoder == ppu_decoder_type::llvm) diff --git a/rpcs3/Emu/Cell/PPUThread.h b/rpcs3/Emu/Cell/PPUThread.h index fbd9cb1051..fbdfd712b1 100644 --- a/rpcs3/Emu/Cell/PPUThread.h +++ b/rpcs3/Emu/Cell/PPUThread.h @@ -74,8 +74,6 @@ public: virtual std::string dump_misc() const override; virtual void cpu_task() override final; virtual void cpu_sleep() override; - virtual void cpu_mem() override; - virtual void cpu_unmem() override; virtual ~ppu_thread() override; ppu_thread(const ppu_thread_params&, std::string_view name, u32 prio, int detached = 0); diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 9ae33cbe0e..7c1dc1b762 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -1453,16 +1453,6 @@ void spu_thread::cpu_task() } } -void spu_thread::cpu_mem() -{ - //vm::passive_lock(*this); -} - -void spu_thread::cpu_unmem() -{ - //state.test_and_set(cpu_flag::memory); -} - spu_thread::~spu_thread() { { @@ -3537,7 +3527,7 @@ bool spu_thread::set_ch_value(u32 ch, u32 value) std::lock_guard lock(group->mutex); // Use the syscall to set flag - const auto res = ch_in_mbox.get_count() ? CELL_EBUSY : 0u + sys_event_flag_set(data, 1ull << flag); + const auto res = ch_in_mbox.get_count() ? CELL_EBUSY : 0u + sys_event_flag_set(*this, data, 1ull << flag); if (res == CELL_EBUSY) { @@ -3562,7 +3552,7 @@ bool spu_thread::set_ch_value(u32 ch, u32 value) spu_log.trace("sys_event_flag_set_bit_impatient(id=%d, value=0x%x (flag=%d))", data, value, flag); // Use the syscall to set flag - sys_event_flag_set(data, 1ull << flag); + sys_event_flag_set(*this, data, 1ull << flag); return true; } else diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index 0ac83e7dbc..0276212ae8 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -624,8 +624,6 @@ public: virtual std::vector> dump_callstack_list() const override; virtual std::string dump_misc() const override; virtual void cpu_task() override final; - virtual void cpu_mem() override; - virtual void cpu_unmem() override; virtual void cpu_return() override; virtual ~spu_thread() override; void cpu_init(); diff --git a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp index 3edec008fc..1085b2ebe5 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp @@ -244,9 +244,9 @@ error_code sys_event_flag_trywait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, return CELL_OK; } -error_code sys_event_flag_set(u32 id, u64 bitptn) +error_code sys_event_flag_set(cpu_thread& cpu, u32 id, u64 bitptn) { - vm::temporary_unlock(); + cpu.state += cpu_flag::wait; // Warning: may be called from SPU thread. sys_event_flag.trace("sys_event_flag_set(id=0x%x, bitptn=0x%llx)", id, bitptn); diff --git a/rpcs3/Emu/Cell/lv2/sys_event_flag.h b/rpcs3/Emu/Cell/lv2/sys_event_flag.h index 985bd630cc..75eaae97da 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event_flag.h +++ b/rpcs3/Emu/Cell/lv2/sys_event_flag.h @@ -118,7 +118,7 @@ error_code sys_event_flag_create(ppu_thread& ppu, vm::ptr id, vm::ptr result, u64 timeout); error_code sys_event_flag_trywait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, vm::ptr result); -error_code sys_event_flag_set(u32 id, u64 bitptn); +error_code sys_event_flag_set(cpu_thread& cpu, u32 id, u64 bitptn); error_code sys_event_flag_clear(ppu_thread& ppu, u32 id, u64 bitptn); error_code sys_event_flag_cancel(ppu_thread& ppu, u32 id, vm::ptr num); error_code sys_event_flag_get(ppu_thread& ppu, u32 id, vm::ptr flags); diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 1294542c99..6ef13a4eca 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -332,7 +332,7 @@ namespace vm if (g_tls_locked && g_tls_locked->compare_and_swap_test(&cpu, nullptr)) { - cpu.cpu_unmem(); + cpu.state += cpu_flag::memory; } }