Make Bundle::connected_to() optionally check for exclusivity
[ardour.git] / libs / pbd / pbd / rcu.h
index 7c63acdb0d1dafd132d783d7d5b210b207ac8dea..eceec24cd5a3de7b0ab960be50bc5e8d626442dc 100644 (file)
 #define __pbd_rcu_h__
 
 #include "boost/shared_ptr.hpp"
-#include "glibmm/thread.h"
+#include "glibmm/threads.h"
 
 #include <list>
 
+#include "pbd/libpbd_visibility.h"
+
 /** @file Defines a set of classes to implement Read-Copy-Update.  We do not attempt to define RCU here - use google.
 
    The design consists of two parts: an RCUManager and an RCUWriter.
@@ -43,7 +45,7 @@
    and managed object.
 */
 template<class T>
-class RCUManager
+class /*LIBPBD_API*/ RCUManager
 {
   public:
 
@@ -53,7 +55,7 @@ class RCUManager
 
        virtual ~RCUManager() { delete x.m_rcu_value; }
 
-        boost::shared_ptr<T> reader () const { return *((boost::shared_ptr<T> *) g_atomic_pointer_get (&x.gptr)); }
+       boost::shared_ptr<T> reader () const { return *((boost::shared_ptr<T> *) g_atomic_pointer_get (&x.gptr)); }
 
        /* this is an abstract base class - how these are implemented depends on the assumptions
           that one can make about the users of the RCUManager. See SerializedRCUManager below
@@ -96,7 +98,7 @@ class RCUManager
    The class maintains a lock-protected "dead wood" list of old value of
    *m_rcu_value (i.e. shared_ptr<T>). The list is cleaned up every time we call
    write_copy(). If the list is the last instance of a shared_ptr<T> that
-   references the object (determined by inspecting its use_count()) then we
+   references the object (determined by shared_ptr::unique()) then we
    erase it from the list, thus deleting the object it points to.  This is lazy
    destruction - the SerializedRCUManager assumes that there will sufficient
    calls to write_copy() to ensure that we do not inadvertently leave objects
@@ -109,7 +111,7 @@ class RCUManager
    means that no actual objects will be deleted incorrectly if this is misused.
 */
 template<class T>
-class SerializedRCUManager : public RCUManager<T>
+class /*LIBPBD_API*/ SerializedRCUManager : public RCUManager<T>
 {
 public:
 
@@ -127,7 +129,7 @@ public:
                typename std::list<boost::shared_ptr<T> >::iterator i;
 
                for (i = m_dead_wood.begin(); i != m_dead_wood.end(); ) {
-                       if ((*i).use_count() == 1) {
+                       if ((*i).unique()) {
                                i = m_dead_wood.erase (i);
                        } else {
                                ++i;
@@ -187,12 +189,12 @@ public:
        }
 
        void flush () {
-               Glib::Mutex::Lock lm (m_lock);
+               Glib::Threads::Mutex::Lock lm (m_lock);
                m_dead_wood.clear ();
        }
 
 private:
-       Glib::Mutex                      m_lock;
+       Glib::Threads::Mutex                      m_lock;
        boost::shared_ptr<T>*            current_write_old;
        std::list<boost::shared_ptr<T> > m_dead_wood;
 };
@@ -212,7 +214,7 @@ private:
 
 */
 template<class T>
-class RCUWriter
+class /*LIBPBD_API*/ RCUWriter
 {
 public:
 
@@ -222,7 +224,7 @@ public:
        }
 
        ~RCUWriter() {
-               if (m_copy.use_count() == 1) {
+               if (m_copy.unique()) {
                        /* As intended, our copy is the only reference
                           to the object pointed to by m_copy. Update
                           the manager with the (presumed) modified