diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2015-08-26 21:18:44 +1000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2015-09-02 12:07:15 +1000 |
commit | 2dbdaaa8f52190757c8bea0096b26b92dde2692a (patch) | |
tree | 46df379fe59845252e33199e666794cad88736ab | |
parent | f58282844d24964f6ea2b160353d2cddd6b9a168 (diff) |
Refactor part of PortAudioBackend::_start/stop into new methods
-rw-r--r-- | libs/backends/portaudio/portaudio_backend.cc | 34 | ||||
-rw-r--r-- | libs/backends/portaudio/portaudio_backend.h | 4 |
2 files changed, 31 insertions, 7 deletions
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; +} - return 0; +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 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; |