diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index 1a7ff1b011..963c367f5a 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -89,14 +89,12 @@ void CPUThread::Wait(const CPUThread& thr) bool CPUThread::Sync() { - wxCriticalSectionLocker lock(m_cs_sync); - return m_sync_wait; } int CPUThread::ThreadStatus() { - if(Emu.IsStopped()) + if(Emu.IsStopped() || IsStopped() || IsPaused()) { return CPUThread_Stopped; } @@ -236,7 +234,7 @@ void CPUThread::Pause() DoPause(); Emu.CheckStatus(); - ThreadBase::Stop(); + // ThreadBase::Stop(); // "Abort() called" exception #ifndef QT_UI wxGetApp().SendDbgCommand(DID_PAUSED_THREAD, this); #endif diff --git a/rpcs3/Emu/CPU/CPUThreadManager.cpp b/rpcs3/Emu/CPU/CPUThreadManager.cpp index fb27b755e4..46bdce578b 100644 --- a/rpcs3/Emu/CPU/CPUThreadManager.cpp +++ b/rpcs3/Emu/CPU/CPUThreadManager.cpp @@ -93,7 +93,7 @@ CPUThread* CPUThreadManager::GetThread(u32 id) { CPUThread* res; - Emu.GetIdManager().GetIDData(id, res); + if (!Emu.GetIdManager().GetIDData(id, res)) return nullptr; return res; } diff --git a/rpcs3/Emu/Cell/PPCThread.cpp b/rpcs3/Emu/Cell/PPCThread.cpp index f3657fd9ce..640e384a7f 100644 --- a/rpcs3/Emu/Cell/PPCThread.cpp +++ b/rpcs3/Emu/Cell/PPCThread.cpp @@ -16,6 +16,7 @@ PPCThread* GetCurrentPPCThread() PPCThread::PPCThread(CPUThreadType type) : CPUThread(type) { + memset(m_args, 0, sizeof(m_args)); } PPCThread::~PPCThread() @@ -24,7 +25,6 @@ PPCThread::~PPCThread() void PPCThread::DoReset() { - memset(m_args, 0, sizeof(u64) * 4); } void PPCThread::InitStack() diff --git a/rpcs3/Emu/Memory/DynamicMemoryBlockBase.inl b/rpcs3/Emu/Memory/DynamicMemoryBlockBase.inl index 8c456e6c86..b59dbca43c 100644 --- a/rpcs3/Emu/Memory/DynamicMemoryBlockBase.inl +++ b/rpcs3/Emu/Memory/DynamicMemoryBlockBase.inl @@ -174,7 +174,7 @@ u64 DynamicMemoryBlockBase::AllocAlign(u32 size, u32 align) template bool DynamicMemoryBlockBase::Alloc() { - return AllocAlign(GetSize() - GetUsedSize(), 0) != 0; + return AllocAlign(GetSize() - GetUsedSize()) != 0; } template diff --git a/rpcs3/Emu/Memory/MemoryBlock.h b/rpcs3/Emu/Memory/MemoryBlock.h index adccf58cc9..2b0d11c04e 100644 --- a/rpcs3/Emu/Memory/MemoryBlock.h +++ b/rpcs3/Emu/Memory/MemoryBlock.h @@ -123,7 +123,7 @@ public: virtual u8* GetMem(u64 addr) const { return mem + addr; } virtual bool AllocFixed(u64 addr, u32 size) { return false; } - virtual u64 AllocAlign(u32 size, u32 align = 0) { return 0; } + virtual u64 AllocAlign(u32 size, u32 align = 1) { return 0; } virtual bool Alloc() { return false; } virtual bool Free(u64 addr) { return false; } virtual bool Lock(u64 addr, u32 size) { return false; } @@ -215,7 +215,7 @@ public: virtual void Delete(); virtual bool AllocFixed(u64 addr, u32 size); - virtual u64 AllocAlign(u32 size, u32 align = 0); + virtual u64 AllocAlign(u32 size, u32 align = 1); virtual bool Alloc(); virtual bool Free(u64 addr); virtual bool Lock(u64 addr, u32 size); diff --git a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp index a6fa5a6830..2c5ade09ac 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp @@ -176,8 +176,8 @@ void fsAioRead(u32 fd, mem_ptr_t aio, int xid, mem_func_ptr_toffset, buf_addr, (u64)aio->size, res, xid, path.c_str()); @@ -195,6 +195,7 @@ int cellFsAioRead(mem_ptr_t aio, mem32_t aio_id, mem_func_ptr_tcond.WaitTimeout(timeout ? timeout : INFINITE); + u32 counter = 0; + const u32 max_counter = timeout ? (timeout / 1000) : 20000; + do + { + if (Emu.IsStopped()) return CELL_ETIMEDOUT; - return CELL_OK; + switch (cond_data->cond.WaitTimeout(1)) + { + wxCOND_NO_ERROR: return CELL_OK; + wxCOND_TIMEOUT: break; + default: return CELL_EPERM; + } + + if (counter++ > max_counter) + { + if (!timeout) + { + sys_cond.Warning("sys_cond_wait(cond_id=0x%x, timeout=0x%llx): TIMEOUT", cond_id, timeout); + counter = 0; + } + else + { + return CELL_ETIMEDOUT; + } + } + } while (true); } int sys_cond_signal(u32 cond_id) diff --git a/rpcs3/Emu/SysCalls/lv2/SC_Mutex.cpp b/rpcs3/Emu/SysCalls/lv2/SC_Mutex.cpp index 86ec296176..75681aba06 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_Mutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_Mutex.cpp @@ -48,9 +48,28 @@ int sys_mutex_lock(u32 mutex_id, u64 timeout) mutex* mtx_data = nullptr; if(!sys_mtx.CheckId(mutex_id, mtx_data)) return CELL_ESRCH; - mtx_data->mtx.Lock(); + u32 counter = 0; + const u32 max_counter = timeout ? (timeout / 1000) : 20000; + do + { + if (Emu.IsStopped()) return CELL_ETIMEDOUT; - return CELL_OK; + if (mtx_data->mtx.TryLock() == wxMUTEX_NO_ERROR) return CELL_OK; + Sleep(1); + + if (counter++ > max_counter) + { + if (!timeout) + { + sys_mtx.Warning("sys_mutex_lock(mutex_id=0x%x, timeout=0x%llx): TIMEOUT", mutex_id, timeout); + counter = 0; + } + else + { + return CELL_ETIMEDOUT; + } + } + } while (true); } int sys_mutex_trylock(u32 mutex_id) @@ -60,7 +79,7 @@ int sys_mutex_trylock(u32 mutex_id) mutex* mtx_data = nullptr; if(!sys_mtx.CheckId(mutex_id, mtx_data)) return CELL_ESRCH; - if(mtx_data->mtx.TryLock()) return 1; + if (mtx_data->mtx.TryLock() != wxMUTEX_NO_ERROR) return CELL_EBUSY; return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/SC_PPU_Thread.cpp b/rpcs3/Emu/SysCalls/lv2/SC_PPU_Thread.cpp index 9e8d8f8f70..9ab7bee427 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_PPU_Thread.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_PPU_Thread.cpp @@ -131,7 +131,7 @@ int sys_ppu_thread_restart(u32 thread_id) return CELL_OK; } -int sys_ppu_thread_create(u32 thread_id_addr, u32 entry, u32 arg, int prio, u32 stacksize, u64 flags, u32 threadname_addr) +int sys_ppu_thread_create(u32 thread_id_addr, u32 entry, u64 arg, int prio, u32 stacksize, u64 flags, u32 threadname_addr) { sysPrxForUser.Log("sys_ppu_thread_create(thread_id_addr=0x%x, entry=0x%x, arg=0x%x, prio=%d, stacksize=0x%x, flags=0x%llx, threadname_addr=0x%x('%s'))", thread_id_addr, entry, arg, prio, stacksize, flags, threadname_addr, Memory.ReadString(threadname_addr).mb_str());