From fe0e997335c34af0d71e7536fd507e1cab322d24 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 24 Jun 2022 19:24:48 +0200 Subject: [PATCH] Backend: prefer debug_msg over PBD::Transmitter in threads PBD::Transmitter is neither thread-safe nor rt-safe. This likely fixes a crash on macOS when process-threads are started. Many threads simultaneously enter coreaudio_process_thread() and log a message calling `PBD::info << .. << endmsg` simultaneously. --- libs/backends/alsa/alsa_audiobackend.cc | 5 +++-- libs/backends/coreaudio/coreaudio_backend.cc | 17 +++++++++-------- libs/backends/dummy/dummy_audiobackend.cc | 5 +++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libs/backends/alsa/alsa_audiobackend.cc b/libs/backends/alsa/alsa_audiobackend.cc index f979a1ecf3..111108af1a 100644 --- a/libs/backends/alsa/alsa_audiobackend.cc +++ b/libs/backends/alsa/alsa_audiobackend.cc @@ -35,6 +35,7 @@ #include "pbd/file_utils.h" #include "pbd/pthread_utils.h" +#include "ardour/debug.h" #include "ardour/filesystem_paths.h" #include "ardour/port_manager.h" #include "ardouralsautil/devicelist.h" @@ -1730,7 +1731,7 @@ AlsaAudioBackend::set_latency_range (PortEngine::PortHandle port_handle, bool fo { BackendPortPtr port = boost::dynamic_pointer_cast (port_handle); if (!valid_port (port)) { - PBD::error << _("AlsaPort::set_latency_range (): invalid port.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendPorts, "AlsaPort::set_latency_range (): invalid port."); } port->set_latency_range (latency_range, for_playback); } @@ -1742,7 +1743,7 @@ AlsaAudioBackend::get_latency_range (PortEngine::PortHandle port_handle, bool fo LatencyRange r; if (!valid_port (port)) { - PBD::error << _("AlsaPort::get_latency_range (): invalid port.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendPorts, "AlsaPort::get_latency_range (): invalid port."); r.min = 0; r.max = 0; return r; diff --git a/libs/backends/coreaudio/coreaudio_backend.cc b/libs/backends/coreaudio/coreaudio_backend.cc index 9273cd127a..e90382f68d 100644 --- a/libs/backends/coreaudio/coreaudio_backend.cc +++ b/libs/backends/coreaudio/coreaudio_backend.cc @@ -31,6 +31,8 @@ #include "pbd/error.h" #include "pbd/file_utils.h" #include "pbd/pthread_utils.h" + +#include "ardour/debug.h" #include "ardour/filesystem_paths.h" #include "ardour/port_manager.h" #include "pbd/i18n.h" @@ -832,7 +834,7 @@ CoreAudioBackend::coreaudio_process_thread (void *arg) ThreadData* td = reinterpret_cast (arg); if (pbd_mach_set_realtime_policy (pthread_self (), td->period_ns, false)) { - PBD::warning << _("AudioEngine: process thread failed to set mach realtime policy.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendThreads, "AudioEngine: process thread failed to set mach realtime policy.\n"); } #if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000 @@ -841,21 +843,20 @@ CoreAudioBackend::coreaudio_process_thread (void *arg) int res = os_workgroup_join (td->_workgroup, &td->_join_token); switch (res) { case 0: - PBD::info << _("AudioEngine: process thread joined AUHAL workgroup.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendThreads, "AudioEngine: process thread joined AUHAL workgroup."); break; case EALREADY: - PBD::warning << _("AudioEngine: process thread is already in a workgroup.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendThreads, "AudioEngine: process thread is already in a workgroup."); td->_joined_workgroup = false; break; case EINVAL: - PBD::warning << _("AudioEngine: invalid workgroup for process thread.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendThreads, "AudioEngine: invalid workgroup for process thread."); td->_joined_workgroup = false; break; default: td->_joined_workgroup = false; - PBD::warning << _("AudioEngine: process thread failed to join AUHAL workgroup.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendThreads, "AudioEngine: process thread failed to join AUHAL workgroup."); break; - } } #endif @@ -1216,7 +1217,7 @@ CoreAudioBackend::set_latency_range (PortEngine::PortHandle port_handle, bool fo { boost::shared_ptr port = boost::dynamic_pointer_cast (port_handle); if (!valid_port (port)) { - PBD::warning << _("BackendPort::set_latency_range (): invalid port.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendPorts, "BackendPort::set_latency_range (): invalid port."); return; } port->set_latency_range (latency_range, for_playback); @@ -1228,7 +1229,7 @@ CoreAudioBackend::get_latency_range (PortEngine::PortHandle port_handle, bool fo boost::shared_ptr port = boost::dynamic_pointer_cast (port_handle); LatencyRange r; if (!valid_port (port)) { - PBD::warning << _("BackendPort::get_latency_range (): invalid port.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendPorts, "BackendPort::get_latency_range (): invalid port."); r.min = 0; r.max = 0; return r; diff --git a/libs/backends/dummy/dummy_audiobackend.cc b/libs/backends/dummy/dummy_audiobackend.cc index ea8fcfb5a7..7f3abd8dee 100644 --- a/libs/backends/dummy/dummy_audiobackend.cc +++ b/libs/backends/dummy/dummy_audiobackend.cc @@ -38,6 +38,7 @@ #include "pbd/compose.h" #include "pbd/pthread_utils.h" +#include "ardour/debug.h" #include "ardour/port_manager.h" #include "pbd/i18n.h" @@ -871,7 +872,7 @@ DummyAudioBackend::set_latency_range (PortEngine::PortHandle port_handle, bool f { BackendPortPtr port = boost::dynamic_pointer_cast (port_handle); if (!valid_port (port)) { - PBD::error << _("DummyPort::set_latency_range (): invalid port.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendPorts, "DummyPort::set_latency_range (): invalid port."); } port->set_latency_range (latency_range, for_playback); } @@ -882,7 +883,7 @@ DummyAudioBackend::get_latency_range (PortEngine::PortHandle port_handle, bool f LatencyRange r; BackendPortPtr port = boost::dynamic_pointer_cast (port_handle); if (!valid_port (port)) { - PBD::error << _("DummyPort::get_latency_range (): invalid port.") << endmsg; + DEBUG_TRACE (PBD::DEBUG::BackendPorts, "DummyPort::get_latency_range (): invalid port."); r.min = 0; r.max = 0; return r;