void sceKernelLockLwMutexCB(u32 workareaPtr, int count, u32 timeoutPtr) { DEBUG_LOG(HLE,"sceKernelLockLwMutexCB(%08x, %i, %08x)", workareaPtr, count, timeoutPtr); NativeLwMutexWorkarea workarea; Memory::ReadStruct(workareaPtr, &workarea); u32 error = 0; if (__KernelLockLwMutex(workarea, count, error)) { Memory::WriteStruct(workareaPtr, &workarea); RETURN(0); __KernelReSchedule("lwmutex locked"); } else if (error) RETURN(error); else { LwMutex *mutex = kernelObjects.Get<LwMutex>(workarea.uid, error); if (mutex) { mutex->waitingThreads.push_back(__KernelGetCurThread()); __KernelWaitLwMutex(mutex, timeoutPtr); __KernelWaitCurThread(WAITTYPE_LWMUTEX, workarea.uid, count, timeoutPtr, true); __KernelCheckCallbacks(); } else RETURN(error); } }
int sceKernelLockLwMutexCB(u32 workareaPtr, int count, u32 timeoutPtr) { VERBOSE_LOG(HLE, "sceKernelLockLwMutexCB(%08x, %i, %08x)", workareaPtr, count, timeoutPtr); auto workarea = Memory::GetStruct<NativeLwMutexWorkarea>(workareaPtr); u32 error = 0; if (__KernelLockLwMutex(workarea, count, error)) return 0; else if (error) return error; else { LwMutex *mutex = kernelObjects.Get<LwMutex>(workarea->uid, error); if (mutex) { SceUID threadID = __KernelGetCurThread(); // May be in a tight loop timing out (where we don't remove from waitingThreads yet), don't want to add duplicates. if (std::find(mutex->waitingThreads.begin(), mutex->waitingThreads.end(), threadID) == mutex->waitingThreads.end()) mutex->waitingThreads.push_back(threadID); __KernelWaitLwMutex(mutex, timeoutPtr); __KernelWaitCurThread(WAITTYPE_LWMUTEX, workarea->uid, count, timeoutPtr, true, "lwmutex cb waited"); // Return value will be overwritten by wait. return 0; } else return error; } }
int sceKernelTryLockLwMutex_600(u32 workareaPtr, int count) { DEBUG_LOG(HLE, "sceKernelTryLockLwMutex_600(%08x, %i)", workareaPtr, count); auto workarea = Memory::GetStruct<NativeLwMutexWorkarea>(workareaPtr); u32 error = 0; if (__KernelLockLwMutex(workarea, count, error)) return 0; else if (error) return error; else return PSP_LWMUTEX_ERROR_TRYLOCK_FAILED; }
int sceKernelTryLockLwMutex_600(u32 workareaPtr, int count) { DEBUG_LOG(SCEKERNEL, "sceKernelTryLockLwMutex_600(%08x, %i)", workareaPtr, count); auto workarea = PSPPointer<NativeLwMutexWorkarea>::Create(workareaPtr); u32 error = 0; if (__KernelLockLwMutex(workarea, count, error)) return 0; else if (error) return error; else return PSP_LWMUTEX_ERROR_TRYLOCK_FAILED; }
int sceKernelTryLockLwMutex(u32 workareaPtr, int count) { DEBUG_LOG(HLE, "sceKernelTryLockLwMutex(%08x, %i)", workareaPtr, count); auto workarea = Memory::GetStruct<NativeLwMutexWorkarea>(workareaPtr); u32 error = 0; if (__KernelLockLwMutex(workarea, count, error)) return 0; // Unlike sceKernelTryLockLwMutex_600, this always returns the same error. else if (error) return PSP_MUTEX_ERROR_TRYLOCK_FAILED; else return PSP_MUTEX_ERROR_TRYLOCK_FAILED; }
int sceKernelTryLockLwMutex(u32 workareaPtr, int count) { DEBUG_LOG(SCEKERNEL, "sceKernelTryLockLwMutex(%08x, %i)", workareaPtr, count); auto workarea = PSPPointer<NativeLwMutexWorkarea>::Create(workareaPtr); u32 error = 0; if (__KernelLockLwMutex(workarea, count, error)) return 0; // Unlike sceKernelTryLockLwMutex_600, this always returns the same error. else if (error) return PSP_MUTEX_ERROR_TRYLOCK_FAILED; else return PSP_MUTEX_ERROR_TRYLOCK_FAILED; }
void sceKernelTryLockLwMutex_600(u32 workareaPtr, int count) { DEBUG_LOG(HLE,"sceKernelTryLockLwMutex_600(%08x, %i)", workareaPtr, count); NativeLwMutexWorkarea workarea; Memory::ReadStruct(workareaPtr, &workarea); u32 error = 0; if (__KernelLockLwMutex(workarea, count, error)) { Memory::WriteStruct(workareaPtr, &workarea); RETURN(0); __KernelReSchedule("lwmutex trylocked"); } else if (error) RETURN(error); else RETURN(PSP_LWMUTEX_ERROR_TRYLOCK_FAILED); }