diff options
author | Thorsten Behrens <thb@openoffice.org> | 2006-03-28 22:22:28 +0000 |
---|---|---|
committer | Thorsten Behrens <thb@openoffice.org> | 2006-03-28 22:22:28 +0000 |
commit | e9d8ae097205882aad4c9655ba8d371db518edaa (patch) | |
tree | f8584339d56822caf6d0ec2f8cee867c12c90a81 /o3tl | |
parent | 0b3d216d7b1c3d95b9eddb7ef540b150687f115e (diff) |
#i63310# Simplified policy interface; added unique-case optimization to ThreadSafeRefCountPolicy
Diffstat (limited to 'o3tl')
-rw-r--r-- | o3tl/inc/o3tl/cow_wrapper.hxx | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/o3tl/inc/o3tl/cow_wrapper.hxx b/o3tl/inc/o3tl/cow_wrapper.hxx index f633fc57e438..ac2b88765549 100644 --- a/o3tl/inc/o3tl/cow_wrapper.hxx +++ b/o3tl/inc/o3tl/cow_wrapper.hxx @@ -4,9 +4,9 @@ * * $RCSfile: cow_wrapper.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: thb $ $Date: 2006-03-23 15:25:00 $ + * last change: $Author: thb $ $Date: 2006-03-28 23:22:28 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -54,8 +54,8 @@ namespace o3tl struct UnsafeRefCountingPolicy { typedef sal_uInt32 ref_count_t; - static ref_count_t incrementCount( ref_count_t& rCount ) { return ++rCount; } - static ref_count_t decrementCount( ref_count_t& rCount ) { return --rCount; } + static void incrementCount( ref_count_t& rCount ) { ++rCount; } + static bool decrementCount( ref_count_t& rCount ) { return --rCount != 0; } }; /** Thread-safe refcounting @@ -66,8 +66,14 @@ namespace o3tl struct ThreadSafeRefCountingPolicy { typedef oslInterlockedCount ref_count_t; - static ref_count_t incrementCount( ref_count_t& rCount ) { return osl_incrementInterlockedCount(&rCount); } - static ref_count_t decrementCount( ref_count_t& rCount ) { return osl_decrementInterlockedCount(&rCount); } + static void incrementCount( ref_count_t& rCount ) { osl_incrementInterlockedCount(&rCount); } + static bool decrementCount( ref_count_t& rCount ) + { + if( rCount == 1 ) // caller is already the only/last reference + return false; + else + return osl_decrementInterlockedCount(&rCount) != 0; + } }; /** Copy-on-write wrapper. @@ -197,7 +203,7 @@ void cow_wrapper_client::queryUnmodified() const void release() { - if( MTPolicy::decrementCount(m_pimpl->m_ref_count) == 0 ) + if( !MTPolicy::decrementCount(m_pimpl->m_ref_count) ) boost::checked_delete(m_pimpl), m_pimpl=0; } |