13
0

Remove the need for a shared_ptr for Signal; signal

tells its connections that it's going away, instead.


git-svn-id: svn://localhost/ardour2/branches/3.0@12277 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2012-05-15 00:05:25 +00:00
parent 42267ff78c
commit 0c3f6d9819

View File

@ -9,10 +9,7 @@ if len(sys.argv) < 2:
f = open(sys.argv[1], 'w')
print >>f,"""
/** THIS FILE IS AUTOGENERATED: DO NOT EDIT.
*
* This file is generated by signals.h.py.
*/
/** THIS FILE IS AUTOGENERATED by signals.h.py: CHANGES WILL BE LOST */
#include <list>
#include <boost/function.hpp>
@ -26,7 +23,7 @@ namespace PBD {
class Connection;
class SignalBase : public boost::enable_shared_from_this<SignalBase>
class SignalBase
{
public:
virtual ~SignalBase () {}
@ -39,17 +36,25 @@ protected:
class Connection : public boost::enable_shared_from_this<Connection>
{
public:
Connection (boost::shared_ptr<SignalBase> b) : _signal (b) {}
Connection (SignalBase* b) : _signal (b) {}
void disconnect ()
{
boost::mutex::scoped_lock lm (_mutex);
if (_signal) {
_signal->disconnect (shared_from_this ());
}
}
void signal_going_away ()
{
boost::mutex::scoped_lock lm (_mutex);
_signal = 0;
}
private:
boost::shared_ptr<SignalBase> _signal;
boost::mutex _mutex;
SignalBase* _signal;
};
template<typename R>
@ -112,10 +117,23 @@ def simple_signal(f, n, v):
print >>f,"public:"
print >>f,""
print >>f,"\t~SimpleSignal%d ()" % n
print >>f,"""
{
boost::mutex::scoped_lock lm (_mutex);
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 6))
for (typename Slots::iterator i = _slots.begin(); i != _slots.end(); ++i) {
#else
for (Slots::iterator i = _slots.begin(); i != _slots.end(); ++i) {
#endif
i->first->signal_going_away ();
}
}
boost::shared_ptr<Connection> connect (slot_function_type f)
{
boost::shared_ptr<Connection> c (new Connection (shared_from_this ()));
boost::shared_ptr<Connection> c (new Connection (this));
boost::mutex::scoped_lock lm (_mutex);
_slots[c] = f;
return c;