From aec7ea46131f9cc4b81890af30eef378f0973bbd Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 4 Jun 2014 02:39:39 +0200 Subject: [PATCH] Revert "Revert "ALSA backend: separate flags for is-running and should-be-running"" sorry, c/p error This reverts commit 9658b77327c21d5748604b882f67c5004ffd10ad. --- libs/backends/alsa/alsa_audiobackend.cc | 25 +++++++++++++++---------- libs/backends/alsa/alsa_audiobackend.h | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libs/backends/alsa/alsa_audiobackend.cc b/libs/backends/alsa/alsa_audiobackend.cc index 68f54fbe46..e9dc8c339b 100644 --- a/libs/backends/alsa/alsa_audiobackend.cc +++ b/libs/backends/alsa/alsa_audiobackend.cc @@ -39,7 +39,8 @@ size_t AlsaAudioBackend::_max_buffer_size = 8192; AlsaAudioBackend::AlsaAudioBackend (AudioEngine& e, AudioBackendInfo& info) : AudioBackend (e, info) , _pcmi (0) - , _running (false) + , _run (false) + , _active (false) , _freewheeling (false) , _capture_device("") , _playback_device("") @@ -416,7 +417,7 @@ static void * pthread_process (void *arg) int AlsaAudioBackend::_start (bool for_latency_measurement) { - if (_running) { + if (_active || _run) { PBD::error << _("AlsaAudioBackend: already active.") << endmsg; return -1; } @@ -505,6 +506,7 @@ AlsaAudioBackend::_start (bool for_latency_measurement) engine.buffer_size_change (_samples_per_period); engine.reconnect_ports (); + _run = true; if (_realtime_pthread_create (SCHED_FIFO, -20, &_main_thread, pthread_process, this)) @@ -513,6 +515,7 @@ AlsaAudioBackend::_start (bool for_latency_measurement) { PBD::error << _("AlsaAudioBackend: failed to create process thread.") << endmsg; delete _pcmi; _pcmi = 0; + _run = false; return -1; } else { PBD::warning << _("AlsaAudioBackend: cannot acquire realtime permissions.") << endmsg; @@ -520,11 +523,12 @@ AlsaAudioBackend::_start (bool for_latency_measurement) } int timeout = 5000; - while (!_running && --timeout > 0) { Glib::usleep (1000); } + while (!_active && --timeout > 0) { Glib::usleep (1000); } - if (timeout == 0 || !_running) { + if (timeout == 0 || !_active) { PBD::error << _("AlsaAudioBackend: failed to start process thread.") << endmsg; delete _pcmi; _pcmi = 0; + _run = false; return -1; } @@ -535,11 +539,11 @@ int AlsaAudioBackend::stop () { void *status; - if (!_running) { + if (!_active) { return 0; } - _running = false; + _run = false; if (pthread_join (_main_thread, &status)) { PBD::error << _("AlsaAudioBackend: failed to terminate.") << endmsg; return -1; @@ -560,7 +564,7 @@ AlsaAudioBackend::stop () unregister_system_ports(); delete _pcmi; _pcmi = 0; - return 0; + return (_active == false) ? 0 : -1; } int @@ -701,7 +705,7 @@ AlsaAudioBackend::my_name () const bool AlsaAudioBackend::available () const { - return true; + return _run && _active; } uint32_t @@ -1280,7 +1284,7 @@ void * AlsaAudioBackend::main_process_thread () { AudioEngine::thread_init_callback (this); - _running = true; + _active = true; _processed_samples = 0; uint64_t clock1, clock2; @@ -1288,7 +1292,7 @@ AlsaAudioBackend::main_process_thread () _pcmi->pcm_start (); int no_proc_errors = 0; - while (_running) { + while (_run) { long nr; bool xrun = false; if (!_freewheeling) { @@ -1407,6 +1411,7 @@ AlsaAudioBackend::main_process_thread () } _pcmi->pcm_stop (); + _active = false; return 0; } diff --git a/libs/backends/alsa/alsa_audiobackend.h b/libs/backends/alsa/alsa_audiobackend.h index 7ff172efbb..cb9e50af10 100644 --- a/libs/backends/alsa/alsa_audiobackend.h +++ b/libs/backends/alsa/alsa_audiobackend.h @@ -280,7 +280,8 @@ class AlsaAudioBackend : public AudioBackend { std::string _instance_name; Alsa_pcmi *_pcmi; - bool _running; + bool _run; /* keep going or stop, ardour thread */ + bool _active; /* is running, process thread */ bool _freewheeling; void enumerate_midi_devices (std::vector &) const;