JACK backend: add a mutex to serialize per-thread port register requests to server

Without this, two threads can both sleep on the same communication channel, and the wake order
is non-determinate, so the wrong thread may process the response to the other thread's request.
This commit is contained in:
Paul Davis 2023-09-12 22:31:45 -06:00
parent 36f8d48e93
commit 88ee3af3ea
2 changed files with 12 additions and 5 deletions

View File

@ -324,6 +324,8 @@ class JACKAudioBackend : public AudioBackend {
JACKSession* _session;
Glib::Threads::Mutex port_registration_mutex;
protected:
int _start (bool for_latency_measurement);
};

View File

@ -583,11 +583,16 @@ JACKAudioBackend::monitoring_input (PortHandle port)
PortEngine::PortPtr
JACKAudioBackend::register_port (const std::string& shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags)
{
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, PortEngine::PortPtr());
jack_port_t* jack_port = jack_port_register (_priv_jack, shortname.c_str(),
ardour_data_type_to_jack_port_type (type),
ardour_port_flags_to_jack_flags (flags),
0);
jack_port_t* jack_port;
{
Glib::Threads::Mutex::Lock lm (port_registration_mutex);
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, PortEngine::PortPtr());
jack_port = jack_port_register (_priv_jack, shortname.c_str(),
ardour_data_type_to_jack_port_type (type),
ardour_port_flags_to_jack_flags (flags),
0);
}
if (!jack_port) {
return PortEngine::PortPtr();
}