s32 sys_rwlock_wlock(u32 rw_lock_id, u64 timeout) { sys_rwlock.Log("sys_rwlock_wlock(rw_lock_id=%d, timeout=%lld)", rw_lock_id, timeout); RWLock* rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; const u32 tid = GetCurrentPPUThread().GetId(); if (!rw->wlock_check(tid)) return CELL_EDEADLK; if (rw->wlock_trylock(tid, true)) return CELL_OK; u32 counter = 0; const u32 max_counter = timeout ? (timeout / 1000) : 20000; do { if (Emu.IsStopped()) { LOG_WARNING(HLE, "sys_rwlock_wlock(rw_lock_id=%d, ...) aborted", rw_lock_id); return CELL_ETIMEDOUT; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); if (rw->wlock_trylock(tid, true)) return CELL_OK; if (counter++ > max_counter) { if (!timeout) { counter = 0; } else { return CELL_ETIMEDOUT; } } } while (true); }
int sys_rwlock_wlock(u32 rw_lock_id, u64 timeout) { sys_rwlock.Log("sys_rwlock_wlock(rw_lock_id=%d, timeout=%lld)", rw_lock_id, timeout); RWLock* rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; const u32 tid = GetCurrentPPUThread().GetId(); if (!rw->wlock_check(tid)) return CELL_EDEADLK; if (rw->wlock_trylock(tid, true)) return CELL_OK; u32 counter = 0; const u32 max_counter = timeout ? (timeout / 1000) : 20000; do { if (Emu.IsStopped()) { ConLog.Warning("sys_rwlock_wlock(rw_lock_id=%d, ...) aborted", rw_lock_id); return CELL_ETIMEDOUT; } Sleep(1); if (rw->wlock_trylock(tid, true)) return CELL_OK; if (counter++ > max_counter) { if (!timeout) { counter = 0; } else { return CELL_ETIMEDOUT; } } } while (true); }
s32 sys_rwlock_trywlock(u32 rw_lock_id) { sys_rwlock.Log("sys_rwlock_trywlock(rw_lock_id=%d)", rw_lock_id); RWLock* rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; const u32 tid = GetCurrentPPUThread().GetId(); if (!rw->wlock_check(tid)) return CELL_EDEADLK; if (!rw->wlock_trylock(tid, false)) return CELL_EBUSY; return CELL_OK; }