X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fpbd%2Fsignals.h;h=69c52f57cf9b330cf9ca76edf5e29c46ebeba720;hb=b6afce39a40f5a6f06de665c242d96934b7e3f8e;hp=e40b0bd2a47d868f4d74a1329bbcced0a8e35658;hpb=14a86aaccc8eadb2f2c8dc5f7251fb1f9c602f30;p=ardour.git diff --git a/libs/pbd/pbd/signals.h b/libs/pbd/pbd/signals.h index e40b0bd2a4..69c52f57cf 100644 --- a/libs/pbd/pbd/signals.h +++ b/libs/pbd/pbd/signals.h @@ -1,6 +1,6 @@ /* 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 @@ -21,13 +21,13 @@ #define __pbd_signals_h__ #include -#include +#include +#include #include #include #include #include -#include #include #include @@ -44,7 +44,7 @@ public: virtual void disconnect (boost::shared_ptr) = 0; protected: - boost::mutex _mutex; + Glib::Threads::Mutex _mutex; }; class Connection : public boost::enable_shared_from_this @@ -54,20 +54,21 @@ public: void disconnect () { - boost::mutex::scoped_lock lm (_mutex); + Glib::Threads::Mutex::Lock lm (_mutex); if (_signal) { _signal->disconnect (shared_from_this ()); - } + _signal = 0; + } } void signal_going_away () { - boost::mutex::scoped_lock lm (_mutex); + Glib::Threads::Mutex::Lock lm (_mutex); _signal = 0; } private: - boost::mutex _mutex; + Glib::Threads::Mutex _mutex; SignalBase* _signal; }; @@ -109,6 +110,11 @@ public: ScopedConnection& operator= (UnscopedConnection const & o) { + if (_c == o) { + return *this; + } + + disconnect (); _c = o; return *this; } @@ -130,12 +136,7 @@ class ScopedConnectionList : public boost::noncopyable /* this class is not copyable */ ScopedConnectionList(const ScopedConnectionList&); - /* this lock is shared by all instances of a ScopedConnectionList. - We do not want one mutex per list, and since we only need the lock - when adding or dropping connections, which are generally occuring - in object creation and UI operations, the contention on this - lock is low and not of significant consequence. Even though - boost::signals2 is thread-safe, this additional list of + /* Even though our signals code is thread-safe, this additional list of scoped connections needs to be protected in 2 cases: (1) (unlikely) we make a connection involving a callback on the @@ -146,7 +147,7 @@ class ScopedConnectionList : public boost::noncopyable one from another. */ - static Glib::StaticMutex _lock; + Glib::Threads::Mutex _lock; typedef std::list ConnectionList; ConnectionList _list;