Skip to content

Commit

Permalink
Merge pull request #1673 from NZJenkins/perf_tweaks
Browse files Browse the repository at this point in the history
Add sleeps/waits in various places
  • Loading branch information
PatrickvL committed Jul 19, 2019
2 parents 1edbc20 + 0ea66ea commit eaa87ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/core/hle/DSOUND/DirectSound/DirectSound.cpp
Expand Up @@ -525,9 +525,10 @@ static void dsound_thread_worker(LPVOID nullPtr)
{
SetThreadAffinityMask(GetCurrentThread(), g_CPUOthers);

while (true) {
Sleep(0);
DSoundMutexGuardLock;
while (true) {
Sleep(1);

DSoundMutexGuardLock;

vector_ds_stream::iterator ppDSStream = g_pDSoundStreamCache.begin();
for (; ppDSStream != g_pDSoundStreamCache.end(); ppDSStream++) {
Expand Down
1 change: 1 addition & 0 deletions src/core/kernel/init/CxbxKrnl.cpp
Expand Up @@ -657,6 +657,7 @@ void TriggerPendingConnectedInterrupts()
if (HalSystemInterrupts[i].IsPending() && EmuInterruptList[i] && EmuInterruptList[i]->Connected) {
HalSystemInterrupts[i].Trigger(EmuInterruptList[i]);
}
SwitchToThread();
}
}

Expand Down
26 changes: 17 additions & 9 deletions src/core/kernel/support/EmuFS.cpp
Expand Up @@ -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
}
}
Expand Down

0 comments on commit eaa87ae

Please sign in to comment.