diff --git a/include/o3tl/cow_wrapper.hxx b/include/o3tl/cow_wrapper.hxx index cc823f60ec57..3c5de8eedf3d 100644 --- a/include/o3tl/cow_wrapper.hxx +++ b/include/o3tl/cow_wrapper.hxx @@ -20,8 +20,7 @@ #ifndef INCLUDED_O3TL_COW_WRAPPER_HXX #define INCLUDED_O3TL_COW_WRAPPER_HXX -#include - +#include #include #include @@ -38,6 +37,7 @@ namespace o3tl typedef std::size_t ref_count_t; static void incrementCount( ref_count_t& rCount ) { ++rCount; } static bool decrementCount( ref_count_t& rCount ) { return --rCount != 0; } + static std::size_t getCount( ref_count_t& rCount) { return rCount; } }; /** Thread-safe refcounting @@ -47,12 +47,13 @@ namespace o3tl */ struct ThreadSafeRefCountingPolicy { - typedef oslInterlockedCount ref_count_t; - static void incrementCount( ref_count_t& rCount ) { osl_atomic_increment(&rCount); } + typedef std::atomic ref_count_t; + static void incrementCount( ref_count_t& rCount ) { rCount++; } static bool decrementCount( ref_count_t& rCount ) { - return osl_atomic_decrement(&rCount) != 0; + return (--rCount) != 0; } + static std::size_t getCount( ref_count_t& rCount) { return rCount; } }; /** Copy-on-write wrapper. @@ -315,9 +316,9 @@ int cow_wrapper_client::queryUnmodified() const } /// return number of shared instances (1 for unique object) - typename MTPolicy::ref_count_t use_count() const // nothrow + size_t use_count() const // nothrow { - return m_pimpl ? m_pimpl->m_ref_count : 0; + return m_pimpl ? MTPolicy::getCount(m_pimpl->m_ref_count) : 0; } void swap(cow_wrapper& r) // never throws diff --git a/o3tl/qa/cow_wrapper_clients.cxx b/o3tl/qa/cow_wrapper_clients.cxx index 913165c83c56..a72e8a50275f 100644 --- a/o3tl/qa/cow_wrapper_clients.cxx +++ b/o3tl/qa/cow_wrapper_clients.cxx @@ -93,7 +93,7 @@ bool cow_wrapper_client2::is_unique() const { return maImpl.is_unique(); } -oslInterlockedCount cow_wrapper_client2::use_count() const +int cow_wrapper_client2::use_count() const { return maImpl.use_count(); } @@ -171,7 +171,7 @@ bool cow_wrapper_client3::is_unique() const { return maImpl.is_unique(); } -oslInterlockedCount cow_wrapper_client3::use_count() const +int cow_wrapper_client3::use_count() const { return maImpl.use_count(); } diff --git a/o3tl/qa/cow_wrapper_clients.hxx b/o3tl/qa/cow_wrapper_clients.hxx index d0e416c96318..dac1a3da0311 100644 --- a/o3tl/qa/cow_wrapper_clients.hxx +++ b/o3tl/qa/cow_wrapper_clients.hxx @@ -20,6 +20,7 @@ #ifndef INCLUDED_O3TL_QA_COW_WRAPPER_CLIENTS_HXX #define INCLUDED_O3TL_QA_COW_WRAPPER_CLIENTS_HXX +#include #include #include #include @@ -45,7 +46,7 @@ public: void makeUnique() { maImpl.make_unique(); } bool is_unique() const { return maImpl.is_unique(); } - oslInterlockedCount use_count() const { return maImpl.use_count(); } + int use_count() const { return maImpl.use_count(); } void swap( cow_wrapper_client1& r ) { o3tl::swap(maImpl, r.maImpl); } bool operator==( const cow_wrapper_client1& rRHS ) const { return maImpl == rRHS.maImpl; } @@ -79,7 +80,7 @@ public: void makeUnique(); bool is_unique() const; - oslInterlockedCount use_count() const; + int use_count() const; void swap( cow_wrapper_client2& r ); bool operator==( const cow_wrapper_client2& rRHS ) const; @@ -110,7 +111,7 @@ public: void makeUnique(); bool is_unique() const; - oslInterlockedCount use_count() const; + int use_count() const; void swap( cow_wrapper_client3& r ); bool operator==( const cow_wrapper_client3& rRHS ) const; @@ -172,6 +173,7 @@ struct BogusRefCountPolicy } return rCount != 0; } + static std::size_t getCount( ref_count_t& rCount) { return rCount; } }; class cow_wrapper_client5