Refactor part of PortAudioBackend::_start/stop into new methods
authorTim Mayberry <mojofunk@gmail.com>
Wed, 26 Aug 2015 11:18:44 +0000 (21:18 +1000)
committerTim Mayberry <mojofunk@gmail.com>
Wed, 2 Sep 2015 02:07:15 +0000 (12:07 +1000)
libs/backends/portaudio/portaudio_backend.cc
libs/backends/portaudio/portaudio_backend.h

index ccb62627b92718f7598bb82bb31dce94a99be038..f9fddf6169aeefece2e1843e0c6a1fb11feccac9 100644 (file)
@@ -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;
index 9867f0de9c44ad9a18db2765d90f6465d119d9f1..f1f607e0df19cf015092de232160c50f6765a90f 100644 (file)
@@ -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;