Revert "Revert "ALSA backend: separate flags for is-running and should-be-running""

sorry, c/p error
This reverts commit 9658b77327.
This commit is contained in:
Robin Gareus 2014-06-04 02:39:39 +02:00
parent 9658b77327
commit aec7ea4613
2 changed files with 17 additions and 11 deletions

View File

@ -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;
}

View File

@ -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<std::string> &) const;