1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-03 14:13:11 +02:00

Fix for Bug 781.

Fixes race condition on Audio thread state by using a mutex, so can play and use . (scrubbing forward) and SPACE (play/stop) safely.  Previously crashed.  Patch by Paul Licameli.
This commit is contained in:
james.k.crook@gmail.com 2014-11-06 17:48:26 +00:00
parent 94d97f87b8
commit ed1338cdec
2 changed files with 12 additions and 10 deletions

View File

@ -542,7 +542,6 @@ AudioIO::AudioIO()
mLastSilentBufSize = 0;
mStreamToken = 0;
mStopStreamCount = 0;
mLastPaError = paNoError;
@ -1605,12 +1604,7 @@ void AudioIO::StopStream()
)
return;
// Avoid race condition by making sure this function only
// gets called once at a time
mStopStreamCount++; // <- note that this is not atomic, therefore has
// a race condition -RBD
if (mStopStreamCount != 1)
return;
wxMutexLocker locker(mSuspendAudioThread);
#if defined(EXPERIMENTAL_REALTIME_EFFECTS)
// No longer need effects processing
@ -1839,7 +1833,6 @@ void AudioIO::StopStream()
// Only set token to 0 after we're totally finished with everything
//
mStreamToken = 0;
mStopStreamCount = 0;
}
void AudioIO::SetPaused(bool state)
@ -3449,6 +3442,12 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
if (gAudioIO->mSeek)
{
int token = gAudioIO->mStreamToken;
wxMutexLocker locker(gAudioIO->mSuspendAudioThread);
if (token != gAudioIO->mStreamToken)
// This stream got destroyed while we waited for it
return paAbort;
// Pause audio thread and wait for it to finish
gAudioIO->mAudioThreadFillBuffersLoopRunning = false;
while( gAudioIO->mAudioThreadFillBuffersLoopActive == true )

View File

@ -490,8 +490,7 @@ private:
WaveTrackArray mPlaybackTracks;
Mixer **mPlaybackMixers;
int mStreamToken;
int mStopStreamCount;
volatile int mStreamToken;
static int mNextStreamToken;
double mFactor;
double mRate;
@ -602,6 +601,10 @@ private:
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *timeInfo,
PaStreamCallbackFlags statusFlags, void *userData );
// Serialize main thread and PortAudio thread's attempts to pause and change
// the state used by the third, Audio thread.
wxMutex mSuspendAudioThread;
};
#endif