diff options
| author | Marcus Tomlinson <themarcustomlinson@gmail.com> | 2022-07-10 00:16:28 +0100 |
|---|---|---|
| committer | Marcus Tomlinson <themarcustomlinson@gmail.com> | 2022-07-10 00:16:28 +0100 |
| commit | 472df628d0168c2bbd87321c61afddf5674656f5 (patch) | |
| tree | 10a9430788fbec73f3b18b08f9685475fb0edc1b | |
| parent | b98b7c5b6fdc2f5455c834fddb27efbfb7d775ec (diff) | |
WASAPI : Fix racy handle closure in stop / abort
| -rw-r--r-- | RtAudio.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/RtAudio.cpp b/RtAudio.cpp index c56a78c..e702ec2 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -5272,11 +5272,13 @@ RtAudioErrorType RtApiWasapi::startStream( void ) RtAudioErrorType RtApiWasapi::stopStream( void ) { + MUTEX_LOCK( &stream_.mutex ); if ( stream_.state != STREAM_RUNNING && stream_.state != STREAM_STOPPING ) { if ( stream_.state == STREAM_STOPPED ) errorText_ = "RtApiWasapi::stopStream(): the stream is already stopped!"; else if ( stream_.state == STREAM_CLOSED ) errorText_ = "RtApiWasapi::stopStream(): the stream is closed!"; + MUTEX_UNLOCK( &stream_.mutex ); return error( RTAUDIO_WARNING ); } @@ -5288,10 +5290,12 @@ RtAudioErrorType RtApiWasapi::stopStream( void ) // close thread handle if ( stream_.callbackInfo.thread && !CloseHandle( ( void* ) stream_.callbackInfo.thread ) ) { errorText_ = "RtApiWasapi::stopStream: Unable to close callback thread."; + MUTEX_UNLOCK( &stream_.mutex ); return error( RTAUDIO_THREAD_ERROR ); } stream_.callbackInfo.thread = (ThreadHandle) NULL; + MUTEX_UNLOCK( &stream_.mutex ); return RTAUDIO_NO_ERROR; } @@ -5299,11 +5303,13 @@ RtAudioErrorType RtApiWasapi::stopStream( void ) RtAudioErrorType RtApiWasapi::abortStream( void ) { + MUTEX_LOCK( &stream_.mutex ); if ( stream_.state != STREAM_RUNNING ) { if ( stream_.state == STREAM_STOPPED ) errorText_ = "RtApiWasapi::abortStream(): the stream is already stopped!"; else if ( stream_.state == STREAM_STOPPING || stream_.state == STREAM_CLOSED ) errorText_ = "RtApiWasapi::abortStream(): the stream is stopping or closed!"; + MUTEX_UNLOCK( &stream_.mutex ); return error( RTAUDIO_WARNING ); } @@ -5315,10 +5321,12 @@ RtAudioErrorType RtApiWasapi::abortStream( void ) // close thread handle if ( stream_.callbackInfo.thread && !CloseHandle( ( void* ) stream_.callbackInfo.thread ) ) { errorText_ = "RtApiWasapi::abortStream: Unable to close callback thread."; + MUTEX_UNLOCK( &stream_.mutex ); return error( RTAUDIO_THREAD_ERROR ); } stream_.callbackInfo.thread = (ThreadHandle) NULL; + MUTEX_UNLOCK( &stream_.mutex ); return RTAUDIO_NO_ERROR; } |
