projects
/
ardour.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use hyphen for XML property names
[ardour.git]
/
libs
/
pbd
/
pbd
/
signals.h
diff --git
a/libs/pbd/pbd/signals.h
b/libs/pbd/pbd/signals.h
index e20a126163633a2eef05401e1ea143cc194a3baa..df4c9cef29331c5d3b0477143d932e0c7fc4df8e 100644
(file)
--- 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
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,60
+20,104
@@
#ifndef __pbd_signals_h__
#define __pbd_signals_h__
#ifndef __pbd_signals_h__
#define __pbd_signals_h__
+#include <csignal>
+
#include <list>
#include <list>
-#include <glibmm/thread.h>
+#include <map>
+
+#ifdef nil
+#undef nil
+#endif
+
+#include <glibmm/threads.h>
#include <boost/noncopyable.hpp>
#include <boost/bind.hpp>
#include <boost/bind/protect.hpp>
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include <boost/bind.hpp>
#include <boost/bind/protect.hpp>
#include <boost/function.hpp>
-#include <boost/thread/mutex.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/optional.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/optional.hpp>
+#include "pbd/libpbd_visibility.h"
#include "pbd/event_loop.h"
#include "pbd/event_loop.h"
+#ifndef NDEBUG
+#define DEBUG_PBD_SIGNAL_CONNECTIONS
+#endif
+
+#ifdef DEBUG_PBD_SIGNAL_CONNECTIONS
+#include "pbd/stacktrace.h"
+#include <iostream>
+#endif
+
namespace PBD {
namespace PBD {
-class Connection;
+class
LIBPBD_API
Connection;
-class SignalBase
+class
LIBPBD_API
SignalBase
{
public:
{
public:
+ SignalBase ()
+#ifdef DEBUG_PBD_SIGNAL_CONNECTIONS
+ : _debug_connection (false)
+#endif
+ {}
virtual ~SignalBase () {}
virtual void disconnect (boost::shared_ptr<Connection>) = 0;
virtual ~SignalBase () {}
virtual void disconnect (boost::shared_ptr<Connection>) = 0;
+#ifdef DEBUG_PBD_SIGNAL_CONNECTIONS
+ void set_debug_connection (bool yn) { _debug_connection = yn; }
+#endif
protected:
protected:
- boost::mutex _mutex;
+ mutable Glib::Threads::Mutex _mutex;
+#ifdef DEBUG_PBD_SIGNAL_CONNECTIONS
+ bool _debug_connection;
+#endif
};
};
-class Connection : public boost::enable_shared_from_this<Connection>
+class
LIBPBD_API
Connection : public boost::enable_shared_from_this<Connection>
{
public:
{
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 ()
{
void disconnect ()
{
-
boost::mutex::scoped_l
ock lm (_mutex);
+
Glib::Threads::Mutex::L
ock lm (_mutex);
if (_signal) {
_signal->disconnect (shared_from_this ());
_signal = 0;
}
}
if (_signal) {
_signal->disconnect (shared_from_this ());
_signal = 0;
}
}
+ void disconnected ()
+ {
+ if (_invalidation_record) {
+ _invalidation_record->unref ();
+ }
+ }
+
void signal_going_away ()
{
void signal_going_away ()
{
- boost::mutex::scoped_lock lm (_mutex);
+ Glib::Threads::Mutex::Lock lm (_mutex);
+ if (_invalidation_record) {
+ _invalidation_record->unref ();
+ }
_signal = 0;
}
private:
_signal = 0;
}
private:
-
boost::m
utex _mutex;
+
Glib::Threads::M
utex _mutex;
SignalBase* _signal;
SignalBase* _signal;
+ PBD::EventLoop::InvalidationRecord* _invalidation_record;
};
template<typename R>
};
template<typename R>
-class OptionalLastValue
+class
/*LIBPBD_API*/
OptionalLastValue
{
public:
typedef boost::optional<R> result_type;
{
public:
typedef boost::optional<R> result_type;
@@
-89,10
+133,10
@@
public:
return r;
}
};
return r;
}
};
-
+
typedef boost::shared_ptr<Connection> UnscopedConnection;
typedef boost::shared_ptr<Connection> UnscopedConnection;
-
-class ScopedConnection
+
+class
LIBPBD_API
ScopedConnection
{
public:
ScopedConnection () {}
{
public:
ScopedConnection () {}
@@
-110,6
+154,11
@@
public:
ScopedConnection& operator= (UnscopedConnection const & o)
{
ScopedConnection& operator= (UnscopedConnection const & o)
{
+ if (_c == o) {
+ return *this;
+ }
+
+ disconnect ();
_c = o;
return *this;
}
_c = o;
return *this;
}
@@
-117,13
+166,13
@@
public:
private:
UnscopedConnection _c;
};
private:
UnscopedConnection _c;
};
-
-class ScopedConnectionList : public boost::noncopyable
+
+class
LIBPBD_API
ScopedConnectionList : public boost::noncopyable
{
public:
ScopedConnectionList();
virtual ~ScopedConnectionList ();
{
public:
ScopedConnectionList();
virtual ~ScopedConnectionList ();
-
+
void add_connection (const UnscopedConnection& c);
void drop_connections ();
void add_connection (const UnscopedConnection& c);
void drop_connections ();
@@
-135,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
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?)
programming style?)
-
+
(2) where we are dropping connections in one thread and adding
one from another.
*/
(2) where we are dropping connections in one thread and adding
one from another.
*/
- Glib::Mutex _lock;
+ Glib::
Threads::
Mutex _lock;
typedef std::list<ScopedConnection*> ConnectionList;
ConnectionList _list;
};
typedef std::list<ScopedConnection*> ConnectionList;
ConnectionList _list;
};
-#include "pbd/signals_generated.h"
-
+#include "pbd/signals_generated.h"
+
} /* namespace */
#endif /* __pbd_signals_h__ */
} /* namespace */
#endif /* __pbd_signals_h__ */