]> Repos - portaudio/commitdiff
Report thread running so Pa_StartStream can return prior to PaStreamCallback
authorBjørn Damstedt Rasmussen <contact@bearware.dk>
Tue, 29 Dec 2020 06:31:58 +0000 (07:31 +0100)
committerBjørn Damstedt Rasmussen <contact@bearware.dk>
Tue, 29 Dec 2020 08:27:38 +0000 (09:27 +0100)
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.

src/hostapi/wasapi/pa_win_wasapi.c

index d791b666781a512b5865b785535f77c50d776fd5..191455037ba87f20a77e08516f1d2446c43389dc 100644 (file)
@@ -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)
     {
@@ -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);
 
@@ -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)
     {
@@ -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);