store InvalidationRecord in a Connection object and ref/unref it as appropriate
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 15 Dec 2016 16:36:39 +0000 (16:36 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 15 Dec 2016 16:36:50 +0000 (16:36 +0000)
libs/pbd/pbd/signals.h
libs/pbd/pbd/signals.py

index 42727b7adce6e9aef184d636de38dd336d5911f2..df4c9cef29331c5d3b0477143d932e0c7fc4df8e 100644 (file)
@@ -78,7 +78,12 @@ protected:
 class LIBPBD_API Connection : public boost::enable_shared_from_this<Connection>
 {
 public:
-       Connection (SignalBase* b) : _signal (b) {}
+       Connection (SignalBase* b, PBD::EventLoop::InvalidationRecord* ir) : _signal (b), _invalidation_record (ir)
+       {
+               if (_invalidation_record) {
+                       _invalidation_record->ref ();
+               }
+       }
 
        void disconnect ()
        {
@@ -89,15 +94,26 @@ public:
                }
        }
 
+       void disconnected ()
+       {
+               if (_invalidation_record) {
+                       _invalidation_record->unref ();
+               }
+       }
+
        void signal_going_away ()
        {
                Glib::Threads::Mutex::Lock lm (_mutex);
+               if (_invalidation_record) {
+                       _invalidation_record->unref ();
+               }
                _signal = 0;
        }
 
 private:
         Glib::Threads::Mutex _mutex;
        SignalBase* _signal;
+       PBD::EventLoop::InvalidationRecord* _invalidation_record;
 };
 
 template<typename R>
index fbcf1d4016406620ba8bb2750dc8aa6dd9500f25..67589a1f66281be998dbb612c9a3f42c5b356a07 100644 (file)
@@ -139,7 +139,7 @@ def signal(f, n, v):
        */
 
        void connect_same_thread (ScopedConnection& c, const slot_function_type& slot) {
-               c = _connect (slot);
+               c = _connect (0, slot);
        }
 
        /** Arrange for @a slot to be executed whenever this signal is emitted. 
@@ -150,7 +150,7 @@ def signal(f, n, v):
        */
        
        void connect_same_thread (ScopedConnectionList& clist, const slot_function_type& slot) {
-               clist.add_connection (_connect (slot));
+               clist.add_connection (_connect (0, slot));
        }
 
        /** Arrange for @a slot to be executed in the context of @a event_loop
@@ -196,7 +196,7 @@ def signal(f, n, v):
     else:
         p = ", %s" % comma_separated(u)
 
-    print("\t\tclist.add_connection (_connect (boost::bind (&compositor, slot, event_loop, ir%s)));" % p, file=f)
+    print("\t\tclist.add_connection (_connect (ir, boost::bind (&compositor, slot, event_loop, ir%s)));" % p, file=f)
 
     print("""
        }
@@ -215,7 +215,7 @@ def signal(f, n, v):
                        ir->event_loop = event_loop;
                }
 """, file=f)
-    print("\t\tc = _connect (boost::bind (&compositor, slot, event_loop, ir%s));" % p, file=f)
+    print("\t\tc = _connect (ir, boost::bind (&compositor, slot, event_loop, ir%s));" % p, file=f)
     print("\t}", file=f)
 
     print("""
@@ -290,9 +290,9 @@ def signal(f, n, v):
     print("\tfriend class Connection;", file=f)
 
     print("""
-       boost::shared_ptr<Connection> _connect (slot_function_type f)
+       boost::shared_ptr<Connection> _connect (PBD::EventLoop::InvalidationRecord* ir, slot_function_type f)
        {
-               boost::shared_ptr<Connection> c (new Connection (this));
+               boost::shared_ptr<Connection> c (new Connection (this, ir));
                Glib::Threads::Mutex::Lock lm (_mutex);
                _slots[c] = f;
 #ifdef DEBUG_PBD_SIGNAL_CONNECTIONS
@@ -307,13 +307,16 @@ def signal(f, n, v):
     print("""
        void disconnect (boost::shared_ptr<Connection> c)
        {
-               Glib::Threads::Mutex::Lock lm (_mutex);
-               _slots.erase (c);
+               {
+                       Glib::Threads::Mutex::Lock lm (_mutex);
+                       _slots.erase (c);
+               }
+               c->disconnected ();
 #ifdef DEBUG_PBD_SIGNAL_CONNECTIONS
-                if (_debug_connection) {
-                        std::cerr << "------- DISCCONNECT " << this << " size now " << _slots.size() << std::endl;
+                       if (_debug_connection) {
+                       std::cerr << "------- DISCCONNECT " << this << " size now " << _slots.size() << std::endl;
                         PBD::stacktrace (std::cerr, 10);
-                }
+               }
 #endif
        }
 };