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
This commit is contained in:
David Robillard 2009-11-01 17:25:38 +00:00
parent 6bb5487852
commit b63a9fd4ca

View file

@ -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<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
@ -127,7 +127,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;
@ -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