Avoid tight loop in LockFS. Fixes Prince of Persia 2 slowdown during loading screen
This commit is contained in:
parent
63996f87eb
commit
0ea66ea0d8
|
@ -125,15 +125,23 @@ uint32_t fs_lock = 0;
|
|||
__declspec(naked) void LockFS()
|
||||
{
|
||||
__asm {
|
||||
pushfd
|
||||
pushad
|
||||
spinlock :
|
||||
mov eax, 1
|
||||
xchg eax, fs_lock
|
||||
test eax, eax
|
||||
jnz spinlock
|
||||
popad
|
||||
popfd
|
||||
// Backup Registers
|
||||
pushfd
|
||||
pushad
|
||||
|
||||
// Spin until we can aquire the lock
|
||||
spinlock :
|
||||
call SwitchToThread // Give other threads chance to run, prevents hogging entire timeslice waiting for spinlock
|
||||
// We do this here loop because SwitchToThread will overwrite eax, so it cannot go below
|
||||
// It's not worth wasting the extra cycles of pushing/popping eax to the stack around this call
|
||||
mov eax, 1
|
||||
xchg eax, fs_lock
|
||||
test eax, eax
|
||||
jnz spinlock
|
||||
|
||||
// Restore registers and return
|
||||
popad
|
||||
popfd
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue