From e505655c2be78dc3e0124840ea0afbee41de1f11 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 1 Jul 2014 08:02:34 -0700 Subject: [PATCH] Fix a potential crash/race condition. If anything is behind, it might run __AudioWakeThreads() within reschedule, and get confused. --- Core/HLE/__sceAudio.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index 4f74c7fe32..99daed620f 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -285,6 +285,7 @@ u32 __AudioEnqueue(AudioChannel &chan, int chanNum, bool blocking) { inline void __AudioWakeThreads(AudioChannel &chan, int result, int step) { u32 error; + bool wokeThreads = false; for (size_t w = 0; w < chan.waitingThreads.size(); ++w) { AudioChannelWaitInfo &waitInfo = chan.waitingThreads[w]; waitInfo.numSamples -= step; @@ -295,7 +296,7 @@ inline void __AudioWakeThreads(AudioChannel &chan, int result, int step) { // DEBUG_LOG(SCEAUDIO, "Woke thread %i for some buffer filling", waitingThread); u32 ret = result == 0 ? __KernelGetWaitValue(waitInfo.threadID, error) : SCE_ERROR_AUDIO_CHANNEL_NOT_RESERVED; __KernelResumeThreadFromWait(waitInfo.threadID, ret); - __KernelReSchedule("audio drain"); + wokeThreads = true; chan.waitingThreads.erase(chan.waitingThreads.begin() + w--); } @@ -303,6 +304,10 @@ inline void __AudioWakeThreads(AudioChannel &chan, int result, int step) { else if (waitID == 0) chan.waitingThreads.erase(chan.waitingThreads.begin() + w--); } + + if (wokeThreads) { + __KernelReSchedule("audio drain"); + } } void __AudioWakeThreads(AudioChannel &chan, int result) {