X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fpbd%2Fsignals.h;h=9640008591a484a1c06a5bea566e5c5df1753329;hb=6b1b72a247bf04c81292fc41af4f69c9b7f90379;hp=140ea014e8040d3431c0f47aaa78dcb0ac4ff584;hpb=fa71d82dda08558caf4a9c5102016f2746883d10;p=ardour.git diff --git a/libs/pbd/pbd/signals.h b/libs/pbd/pbd/signals.h index 140ea014e8..9640008591 100644 --- a/libs/pbd/pbd/signals.h +++ b/libs/pbd/pbd/signals.h @@ -1,6 +1,6 @@ /* - Copyright (C) 2009-2012 Paul Davis - + Copyright (C) 2009-2012 Paul Davis + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -20,6 +20,8 @@ #ifndef __pbd_signals_h__ #define __pbd_signals_h__ +#include + #include #include @@ -36,26 +38,52 @@ #include #include +#include "pbd/libpbd_visibility.h" #include "pbd/event_loop.h" +#ifndef NDEBUG +#define DEBUG_PBD_SIGNAL_CONNECTIONS +#endif + +#ifdef DEBUG_PBD_SIGNAL_CONNECTIONS +#include "pbd/stacktrace.h" +#include +#endif + namespace PBD { -class Connection; +class LIBPBD_API Connection; -class SignalBase +class LIBPBD_API SignalBase { public: + SignalBase () +#ifdef DEBUG_PBD_SIGNAL_CONNECTIONS + : _debug_connection (false) +#endif + {} virtual ~SignalBase () {} virtual void disconnect (boost::shared_ptr) = 0; +#ifdef DEBUG_PBD_SIGNAL_CONNECTIONS + void set_debug_connection (bool yn) { _debug_connection = yn; } +#endif protected: - Glib::Threads::Mutex _mutex; + mutable Glib::Threads::Mutex _mutex; +#ifdef DEBUG_PBD_SIGNAL_CONNECTIONS + bool _debug_connection; +#endif }; -class Connection : public boost::enable_shared_from_this +class LIBPBD_API Connection : public boost::enable_shared_from_this { 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 () { @@ -66,19 +94,30 @@ 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 -class OptionalLastValue +class /*LIBPBD_API*/ OptionalLastValue { public: typedef boost::optional result_type; @@ -94,10 +133,10 @@ public: return r; } }; - + typedef boost::shared_ptr UnscopedConnection; - -class ScopedConnection + +class LIBPBD_API ScopedConnection { public: ScopedConnection () {} @@ -118,7 +157,7 @@ public: if (_c == o) { return *this; } - + disconnect (); _c = o; return *this; @@ -127,13 +166,13 @@ public: private: UnscopedConnection _c; }; - -class ScopedConnectionList : public boost::noncopyable + +class LIBPBD_API ScopedConnectionList : public boost::noncopyable { public: ScopedConnectionList(); virtual ~ScopedConnectionList (); - + void add_connection (const UnscopedConnection& c); void drop_connections (); @@ -145,21 +184,21 @@ class ScopedConnectionList : public boost::noncopyable scoped connections needs to be protected in 2 cases: (1) (unlikely) we make a connection involving a callback on the - same object from 2 threads. (wouldn't that just be appalling + same object from 2 threads. (wouldn't that just be appalling programming style?) - + (2) where we are dropping connections in one thread and adding one from another. */ - Glib::Threads::Mutex _lock; + Glib::Threads::Mutex _scoped_connection_lock; typedef std::list ConnectionList; - ConnectionList _list; + ConnectionList _scoped_connection_list; }; -#include "pbd/signals_generated.h" - +#include "pbd/signals_generated.h" + } /* namespace */ #endif /* __pbd_signals_h__ */