store InvalidationRecord in a Connection object and ref/unref it as appropriate
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user