Skip to content

Commit

Permalink
Make MME wait forever for the thread to exit
Browse files Browse the repository at this point in the history
See PortAudio#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.
  • Loading branch information
dechamps committed Jun 2, 2024
1 parent 18a606e commit 5782ced
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/hostapi/wmme/pa_win_wmme.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5782ced

Please sign in to comment.