Skip to content

Commit

Permalink
Report thread running so Pa_StartStream can return prior to PaStreamC…
Browse files Browse the repository at this point in the history
…allback

StartStream() calls WaitForSingleObject(stream->hThreadStart, 60*1000)
but it will not be able to return until X number of PaStreamCallback
have been performed by ProcessOutputBuffer().

The above behaviour will cause a deadlock if the user supplied
PaStreamCallback tries to access a shared lock currently held by the
function calling Pa_StartStream().

Also it's a bit weird that you start receiving PaStreamCallbacks
before Pa_StartStream() is able to complete.
  • Loading branch information
bear101 committed Dec 29, 2020
1 parent f4a9023 commit 2d8c7eb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/hostapi/wasapi/pa_win_wasapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5890,6 +5890,12 @@ PA_THREAD_FUNC ProcThreadEvent(void *param)
goto thread_error;
}

// Signal: stream running
stream->running = TRUE;

// Notify: thread started
SetEvent(stream->hThreadStart);

// Initialize event & start INPUT stream
if (stream->in.clientProc)
{
Expand Down Expand Up @@ -5940,12 +5946,6 @@ PA_THREAD_FUNC ProcThreadEvent(void *param)

}

// Signal: stream running
stream->running = TRUE;

// Notify: thread started
SetEvent(stream->hThreadStart);

// Notify: state
NotifyStateChanged(stream, paWasapiStreamStateThreadStart, ERROR_SUCCESS);

Expand Down Expand Up @@ -6171,6 +6171,12 @@ PA_THREAD_FUNC ProcThreadPoll(void *param)
// Boost thread priority
PaWasapi_ThreadPriorityBoost((void **)&stream->hAvTask, stream->nThreadPriority);

// Signal: stream running
stream->running = TRUE;

// Notify: thread started
SetEvent(stream->hThreadStart);

// Initialize event & start INPUT stream
if (stream->in.clientProc)
{
Expand Down Expand Up @@ -6238,12 +6244,6 @@ PA_THREAD_FUNC ProcThreadPoll(void *param)
}
}

// Signal: stream running
stream->running = TRUE;

// Notify: thread started
SetEvent(stream->hThreadStart);

// Notify: state
NotifyStateChanged(stream, paWasapiStreamStateThreadStart, ERROR_SUCCESS);

Expand Down

0 comments on commit 2d8c7eb

Please sign in to comment.