From fa07233a17036bc1cab69d5854b5c768ff762f5b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 13 Dec 2016 23:46:55 +0100 Subject: mutex 'er up Some overzealous locking to track down RequestObject related crashes. bc0fa4d689a4 wrongly locked the current event loop's request_invalidation_lock instead of the invalidation's list lock. Also Abstract UI is able to delete requests concurrently with with EventLoop invalidation. e.g. PortManager::PortRegisteredOrUnregistered and GlobalPortMatrixWindow so the lock needs to be exposed. If this solves various issues, mutexes should to be consolidated (request_buffer_map_lock + request_invalidation_lock) and be chosen such that there is as little contention as possible. --- libs/pbd/pbd/abstract_ui.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libs/pbd/pbd/abstract_ui.cc') diff --git a/libs/pbd/pbd/abstract_ui.cc b/libs/pbd/pbd/abstract_ui.cc index 594dec34dd..ed358cb7cf 100644 --- a/libs/pbd/pbd/abstract_ui.cc +++ b/libs/pbd/pbd/abstract_ui.cc @@ -240,7 +240,8 @@ AbstractUI::handle_ui_requests () request_buffer_map_lock.lock (); if (vec.buf[0]->invalidation) { DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1: removing invalidation record for that request\n", event_loop_name())); - Glib::Threads::Mutex::Lock lm (request_invalidation_lock); + assert (vec.buf[0]->invalidation->event_loop); + Glib::Threads::Mutex::Lock lm (vec.buf[0]->invalidation->event_loop->request_invalidation_mutex()); if (!(*i).second->dead) { vec.buf[0]->invalidation->requests.remove (vec.buf[0]); } @@ -257,6 +258,7 @@ AbstractUI::handle_ui_requests () /* clean up any dead request buffers (their thread has exited) */ + Glib::Threads::Mutex::Lock lr (request_invalidation_lock); for (i = request_buffers.begin(); i != request_buffers.end(); ) { if ((*i).second->dead) { DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 deleting dead per-thread request buffer for %3 @ %4\n", @@ -304,8 +306,9 @@ AbstractUI::handle_ui_requests () */ if (req->invalidation) { - Glib::Threads::Mutex::Lock lm (request_invalidation_lock); DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 remove request from its invalidation list\n", event_loop_name(), pthread_name())); + assert (req->invalidation->event_loop && req->invalidation->event_loop != this); + Glib::Threads::Mutex::Lock lm (req->invalidation->event_loop->request_invalidation_mutex()); /* after this call, if the object referenced by the * invalidation record is deleted, it will no longer -- cgit v1.2.3