diff --git a/libs/backends/portaudio/portaudio_backend.cc b/libs/backends/portaudio/portaudio_backend.cc index ccb62627b9..f9fddf6169 100644 --- a/libs/backends/portaudio/portaudio_backend.cc +++ b/libs/backends/portaudio/portaudio_backend.cc @@ -545,6 +545,16 @@ PortAudioBackend::_start (bool for_latency_measurement) _run = true; _port_change_flag = false; + if (!start_blocking_process_thread()) { + return -1; + } + + return 0; +} + +bool +PortAudioBackend::start_blocking_process_thread () +{ if (_realtime_pthread_create (SCHED_FIFO, -20, 100000, &_main_thread, pthread_process, this)) { @@ -552,7 +562,7 @@ PortAudioBackend::_start (bool for_latency_measurement) { DEBUG_AUDIO("Failed to create main audio thread\n"); _run = false; - return -1; + return false; } else { PBD::warning << get_error_string(AquireRealtimePermissionError) << endmsg; } @@ -567,27 +577,37 @@ PortAudioBackend::_start (bool for_latency_measurement) _run = false; unregister_ports(); _active = false; - return -1; + return false; + } + return true; +} + +bool +PortAudioBackend::stop_blocking_process_thread () +{ + void *status; + + if (pthread_join (_main_thread, &status)) { + DEBUG_AUDIO("Failed to stop main audio thread\n"); + return false; } - return 0; + return true; } int PortAudioBackend::stop () { - void *status; if (!_run) { return 0; } _run = false; - if (pthread_join (_main_thread, &status)) { - DEBUG_AUDIO("Failed to stop main audio thread\n"); + + if (!stop_blocking_process_thread ()) { return -1; } - unregister_ports(); return (_active == false) ? 0 : -1; diff --git a/libs/backends/portaudio/portaudio_backend.h b/libs/backends/portaudio/portaudio_backend.h index 9867f0de9c..f1f607e0df 100644 --- a/libs/backends/portaudio/portaudio_backend.h +++ b/libs/backends/portaudio/portaudio_backend.h @@ -319,6 +319,10 @@ class PortAudioBackend : public AudioBackend { void* main_process_thread (); + private: // Methods + bool start_blocking_process_thread (); + bool stop_blocking_process_thread (); + private: std::string _instance_name; PortAudioIO *_pcmio;