From 86c837b0ebbba40715f9d40c0b1475ddbf74e8a5 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 14 Apr 2025 10:05:24 -0600 Subject: [PATCH] provide deeper debugging of PBD::Signal emission process --- libs/pbd/pbd/signals.h | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/libs/pbd/pbd/signals.h b/libs/pbd/pbd/signals.h index 97e5c70b0a..4bcd19e1f9 100644 --- a/libs/pbd/pbd/signals.h +++ b/libs/pbd/pbd/signals.h @@ -43,6 +43,7 @@ #ifndef NDEBUG #define DEBUG_PBD_SIGNAL_CONNECTIONS +#define DEBUG_PBD_SIGNAL_EMISSION #endif #ifdef DEBUG_PBD_SIGNAL_CONNECTIONS @@ -67,6 +68,9 @@ public: : _in_dtor (false) #ifdef DEBUG_PBD_SIGNAL_CONNECTIONS , _debug_connection (false) +#endif +#ifdef DEBUG_PBD_SIGNAL_EMISSION + , _debug_emission (false) #endif {} virtual ~SignalBase () { } @@ -74,6 +78,9 @@ public: #ifdef DEBUG_PBD_SIGNAL_CONNECTIONS void set_debug_connection (bool yn) { _debug_connection = yn; } #endif +#ifdef DEBUG_PBD_SIGNAL_EMISSION + void set_debug_emission (bool yn) { _debug_emission = yn; } +#endif protected: mutable Glib::Threads::Mutex _mutex; @@ -81,6 +88,9 @@ protected: #ifdef DEBUG_PBD_SIGNAL_CONNECTIONS bool _debug_connection; #endif +#ifdef DEBUG_PBD_SIGNAL_EMISSION + bool _debug_emission; +#endif }; template @@ -276,6 +286,8 @@ class LIBPBD_API ScopedConnectionList void add_connection (const UnscopedConnection& c); void drop_connections (); + std::list::size_type size() const { Glib::Threads::Mutex::Lock lm (_scoped_connection_lock); return _scoped_connection_list.size(); } + private: /* Even though our signals code is thread-safe, this additional list of scoped connections needs to be protected in 2 cases: @@ -288,9 +300,10 @@ class LIBPBD_API ScopedConnectionList one from another. */ - Glib::Threads::Mutex _scoped_connection_lock; + mutable Glib::Threads::Mutex _scoped_connection_lock; typedef std::list ConnectionList; + public: ConnectionList _scoped_connection_list; }; @@ -416,7 +429,12 @@ typename std::conditional_t, R, typename Combiner::result_type SignalWithCombiner::operator() (A... a) { /* First, take a copy of our list of slots as it is now */ - +#ifdef DEBUG_PBD_SIGNAL_EMISSION + if (_debug_emission) { + std::cerr << "------ Signal @ " << this << " emission process begins\n"; + PBD::stacktrace (std::cerr, 19); + } +#endif Slots s; { Glib::Threads::Mutex::Lock lm (_mutex); @@ -438,6 +456,11 @@ SignalWithCombiner::operator() (A... a) } if (still_there) { +#ifdef DEBUG_PBD_SIGNAL_EMISSION + if (_debug_emission) { + std::cerr << "signal @ " << this << " calling slot for connection @ " << i->first << " of " << _slots.size() << std::endl; + } +#endif (i->second)(a...); } } @@ -457,6 +480,11 @@ SignalWithCombiner::operator() (A... a) } if (still_there) { +#ifdef DEBUG_PBD_SIGNAL_EMISSION + if (_debug_emission) { + std::cerr << "signal @ " << this << " calling non-void slot for connection @ " << i->first << " of " << _slots.size() << std::endl; + } +#endif r.push_back ((i->second)(a...)); } } @@ -465,6 +493,11 @@ SignalWithCombiner::operator() (A... a) Combiner c; return c (r.begin(), r.end()); } +#ifdef DEBUG_PBD_SIGNAL_EMISSION + if (_debug_emission) { + std::cerr << "------ Signal @ " << this << " emission process ends\n"; + } +#endif } template @@ -477,7 +510,7 @@ SignalWithCombiner::_connect (PBD::EventLoop::InvalidationRec _slots[c] = f; #ifdef DEBUG_PBD_SIGNAL_CONNECTIONS if (_debug_connection) { - std::cerr << "+++++++ CONNECT " << this << " size now " << _slots.size() << std::endl; + std::cerr << "+++++++ CONNECT " << this << " via connection @ " << c << " size now " << _slots.size() << std::endl; stacktrace (std::cerr, 10); } #endif