From 95aa39d1c4df2989d828b59218c0a0aa8e4107d8 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 9 Jun 2022 01:46:27 +0200 Subject: [PATCH] Update call_slot() API, inform caller if slot cannot be queued It can happen that ::get_request() returns NULL if the EventPool is full. In that case the slot is never called. In this case the caller can now take action. --- libs/pbd/pbd/abstract_ui.cc | 12 ++++++++---- libs/pbd/pbd/abstract_ui.h | 4 ++-- libs/pbd/pbd/event_loop.h | 2 +- luasession/luasession.cc | 3 ++- session_utils/common.cc | 3 ++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libs/pbd/pbd/abstract_ui.cc b/libs/pbd/pbd/abstract_ui.cc index ae3f9d49c9..4650fafcbd 100644 --- a/libs/pbd/pbd/abstract_ui.cc +++ b/libs/pbd/pbd/abstract_ui.cc @@ -431,13 +431,13 @@ AbstractUI::send_request (RequestObject *req) } } -template void +template bool AbstractUI::call_slot (InvalidationRecord* invalidation, const boost::function& f) { if (caller_is_self()) { DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 direct dispatch of call slot via functor @ %3, invalidation %4\n", event_loop_name(), pthread_name(), &f, invalidation)); f (); - return; + return true; } /* object destruction may race with realtime signal emission. @@ -453,7 +453,7 @@ AbstractUI::call_slot (InvalidationRecord* invalidation, const bo if (invalidation) { if (!invalidation->valid()) { DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 ignoring call-slot using functor @ %3, dead invalidation %4\n", event_loop_name(), pthread_name(), &f, invalidation)); - return; + return true; } invalidation->ref (); invalidation->event_loop = this; @@ -465,7 +465,10 @@ AbstractUI::call_slot (InvalidationRecord* invalidation, const bo if (invalidation) { invalidation->unref (); } - return; + /* event is lost, this can be critical in some cases, so + * inform the caller. See also Session::process_rtop + */ + return false; } DEBUG_TRACE (PBD::DEBUG::AbstractUI, string_compose ("%1/%2 queue call-slot using functor @ %3, invalidation %4\n", event_loop_name(), pthread_name(), &f, invalidation)); @@ -485,6 +488,7 @@ AbstractUI::call_slot (InvalidationRecord* invalidation, const bo req->invalidation = invalidation; send_request (req); + return true; } template void* diff --git a/libs/pbd/pbd/abstract_ui.h b/libs/pbd/pbd/abstract_ui.h index b63b9b7c6b..7c0083459a 100644 --- a/libs/pbd/pbd/abstract_ui.h +++ b/libs/pbd/pbd/abstract_ui.h @@ -60,7 +60,7 @@ public: virtual ~AbstractUI(); void register_thread (pthread_t, std::string, uint32_t num_requests); - void call_slot (EventLoop::InvalidationRecord*, const boost::function&); + bool call_slot (EventLoop::InvalidationRecord*, const boost::function&); Glib::Threads::Mutex& slot_invalidation_mutex() { return request_buffer_map_lock; } Glib::Threads::Mutex request_buffer_map_lock; @@ -98,7 +98,7 @@ protected: RequestObject* get_request (RequestType); void handle_ui_requests (); - void send_request (RequestObject *); + void send_request (RequestObject*); virtual void do_request (RequestObject *) = 0; PBD::ScopedConnection new_thread_connection; diff --git a/libs/pbd/pbd/event_loop.h b/libs/pbd/pbd/event_loop.h index 44d2bca475..6a1504abc4 100644 --- a/libs/pbd/pbd/event_loop.h +++ b/libs/pbd/pbd/event_loop.h @@ -88,7 +88,7 @@ public: } }; - virtual void call_slot (InvalidationRecord*, const boost::function&) = 0; + virtual bool call_slot (InvalidationRecord*, const boost::function&) = 0; virtual Glib::Threads::Mutex& slot_invalidation_mutex() = 0; std::string event_loop_name() const { return _name; } diff --git a/luasession/luasession.cc b/luasession/luasession.cc index 50e1f34cb3..d4ad68d140 100644 --- a/luasession/luasession.cc +++ b/luasession/luasession.cc @@ -109,7 +109,7 @@ public: run_loop_thread = Glib::Threads::Thread::self (); } - void call_slot (InvalidationRecord* ir, const boost::function& f) + bool call_slot (InvalidationRecord* ir, const boost::function& f) { if (Glib::Threads::Thread::self () == run_loop_thread) { cout << string_compose ("%1/%2 direct dispatch of call slot via functor @ %3, invalidation %4\n", event_loop_name (), pthread_name (), &f, ir); @@ -119,6 +119,7 @@ public: assert (!ir); f (); // XXX TODO, queue and process during run () } + return true; } void run () diff --git a/session_utils/common.cc b/session_utils/common.cc index 1345cee063..6662406352 100644 --- a/session_utils/common.cc +++ b/session_utils/common.cc @@ -96,10 +96,11 @@ class MyEventLoop : public sigc::trackable, public EventLoop run_loop_thread = Glib::Threads::Thread::self(); } - void call_slot (InvalidationRecord*, const boost::function& f) { + bool call_slot (InvalidationRecord*, const boost::function& f) { if (Glib::Threads::Thread::self() == run_loop_thread) { f (); } + return true; } Glib::Threads::Mutex& slot_invalidation_mutex() { return request_buffer_map_lock; }