From b63a9fd4ca4814a3eb642b6dceef0e507e1cdee3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 1 Nov 2009 17:25:38 +0000 Subject: [PATCH] Use shared_ptr::unique() instead of shared_ptr::use_count() == 1. use_count() can be slow (not constant time) depending on underlying implementation. Similar situation to std::list::size() == 0 an std::list::empty(), the former does a big traversal/computation only to check if the very first step went. I think the current boost implementation is just a reference count anyway, but hey. In theory. git-svn-id: svn://localhost/ardour2/branches/3.0@5996 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/pbd/pbd/rcu.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/pbd/pbd/rcu.h b/libs/pbd/pbd/rcu.h index 7c63acdb0d..82ba5ff325 100644 --- a/libs/pbd/pbd/rcu.h +++ b/libs/pbd/pbd/rcu.h @@ -96,7 +96,7 @@ class RCUManager The class maintains a lock-protected "dead wood" list of old value of *m_rcu_value (i.e. shared_ptr). The list is cleaned up every time we call write_copy(). If the list is the last instance of a shared_ptr 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 @@ -127,7 +127,7 @@ public: typename std::list >::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; @@ -222,7 +222,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