rpcs3/rpcs3/Emu/Cell/Modules/sys_spinlock.cpp
Nekotekina 1b37e775be Migration to named_thread<>
Add atomic_t<>::try_dec instead of fetch_dec_sat
Add atomic_t<>::try_inc
GDBDebugServer is broken (needs rewrite)
Removed old_thread class (former named_thread)
Removed storing/rethrowing exceptions from thread
Emu.Stop doesn't inject an exception anymore
task_stack helper class removed
thread_base simplified (no shared_from_this)
thread_ctrl::spawn simplified (creates detached thread)
Implemented overrideable thread detaching logic
Disabled cellAdec, cellDmux, cellFsAio
SPUThread renamed to spu_thread
RawSPUThread removed, spu_thread used instead
Disabled deriving from ppu_thread
Partial support for thread renaming
lv2_timer... simplified, screw it
idm/fxm: butchered support for on_stop/on_init
vm: improved allocation structure (added size)
2018-10-19 22:22:35 +03:00

60 lines
1.2 KiB
C++

#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/Cell/PPUModule.h"
#include "sysPrxForUser.h"
extern logs::channel sysPrxForUser;
void sys_spinlock_initialize(vm::ptr<atomic_be_t<u32>> lock)
{
sysPrxForUser.trace("sys_spinlock_initialize(lock=*0x%x)", lock);
if (*lock)
{
*lock = 0;
}
}
error_code sys_spinlock_lock(ppu_thread& ppu, vm::ptr<atomic_be_t<u32>> lock)
{
sysPrxForUser.trace("sys_spinlock_lock(lock=*0x%x)", lock);
// Try to exchange with 0xabadcafe, repeat until exchanged with 0
while (*lock || lock->exchange(0xabadcafe))
{
if (ppu.test_stopped())
{
return 0;
}
}
return not_an_error(ppu.gpr[3]);
}
s32 sys_spinlock_trylock(vm::ptr<atomic_be_t<u32>> lock)
{
sysPrxForUser.trace("sys_spinlock_trylock(lock=*0x%x)", lock);
if (*lock || lock->exchange(0xabadcafe))
{
return CELL_EBUSY;
}
return CELL_OK;
}
void sys_spinlock_unlock(vm::ptr<atomic_be_t<u32>> lock)
{
sysPrxForUser.trace("sys_spinlock_unlock(lock=*0x%x)", lock);
*lock = 0;
}
void sysPrxForUser_sys_spinlock_init()
{
REG_FUNC(sysPrxForUser, sys_spinlock_initialize);
REG_FUNC(sysPrxForUser, sys_spinlock_lock);
REG_FUNC(sysPrxForUser, sys_spinlock_trylock);
REG_FUNC(sysPrxForUser, sys_spinlock_unlock);
}