From 5782cedb99332f21d3bae5161e21a29dc8be32d4 Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sun, 2 Jun 2024 15:03:43 +0100 Subject: [PATCH 1/2] Make MME wait forever for the thread to exit See #919 for rationale. Note that the previous Pa_StopStream() uses a bounded timeout to abort the stream if it doesn't stop within the alloted time, and then another bounded timeout to wait for the streaming thread to exit. This commit preserves the first timeout as it makes sense and appears to be safe, but gets rid of the second one so that we wait indefinitely for the streaming thread to exit. --- src/hostapi/wmme/pa_win_wmme.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/hostapi/wmme/pa_win_wmme.c b/src/hostapi/wmme/pa_win_wmme.c index 3639d6d2e..50ecabf97 100644 --- a/src/hostapi/wmme/pa_win_wmme.c +++ b/src/hostapi/wmme/pa_win_wmme.c @@ -3463,12 +3463,7 @@ static PaError StopStream( PaStream *s ) /* try to abort */ stream->abortProcessing = 1; SetEvent( stream->abortEvent ); - waitResult = WaitForSingleObject( stream->processingThread, timeoutMs ); - if( waitResult == WAIT_TIMEOUT ) - { - PA_DEBUG(("WinMME StopStream: timed out while waiting for background thread to finish.\n")); - result = paTimedOut; - } + WaitForSingleObject( stream->processingThread, INFINITE ); } CloseHandle( stream->processingThread ); @@ -3575,8 +3570,6 @@ static PaError AbortStream( PaStream *s ) { PaError result = paNoError; PaWinMmeStream *stream = (PaWinMmeStream*)s; - DWORD timeoutMs; - DWORD waitResult; MMRESULT mmresult; unsigned int i; @@ -3630,17 +3623,7 @@ static PaError AbortStream( PaStream *s ) PA_DEBUG(("WinMME AbortStream: waiting for background thread.\n")); - /* Calculate timeOut longer than longest time it could take to return all buffers. */ - timeoutMs = (DWORD)(stream->allBuffersDurationMs * 1.5); - if( timeoutMs < PA_MME_MIN_TIMEOUT_MSEC_ ) - timeoutMs = PA_MME_MIN_TIMEOUT_MSEC_; - - waitResult = WaitForSingleObject( stream->processingThread, timeoutMs ); - if( waitResult == WAIT_TIMEOUT ) - { - PA_DEBUG(("WinMME AbortStream: timed out while waiting for background thread to finish.\n")); - return paTimedOut; - } + WaitForSingleObject( stream->processingThread, INFINITE ); CloseHandle( stream->processingThread ); stream->processingThread = NULL; From 148b6a39fc89cd1fb48771740157e39189fc888b Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sun, 2 Jun 2024 15:11:14 +0100 Subject: [PATCH 2/2] Make DirectSound wait forever for the thread to exit See #919 for rationale. --- src/hostapi/dsound/pa_win_ds.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hostapi/dsound/pa_win_ds.c b/src/hostapi/dsound/pa_win_ds.c index b0ab18725..b902144f3 100644 --- a/src/hostapi/dsound/pa_win_ds.c +++ b/src/hostapi/dsound/pa_win_ds.c @@ -3089,9 +3089,7 @@ static PaError StopStream( PaStream *s ) #else if( stream->processingThread ) { - if( WaitForSingleObject( stream->processingThreadCompleted, 30*100 ) == WAIT_TIMEOUT ) - return paUnanticipatedHostError; - + WaitForSingleObject(stream->processingThreadCompleted, INFINITE ); #ifdef CLOSE_THREAD_HANDLE CloseHandle( stream->processingThread ); /* Delete thread. */ stream->processingThread = NULL;