From: <ric...@us...> - 2008-11-10 06:00:03
|
Revision: 904 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=904&view=rev Author: rich_sposato Date: 2008-11-10 05:59:59 +0000 (Mon, 10 Nov 2008) Log Message: ----------- Fixed variation of bug 2022935 by changing when functions check if strong-count is zero. Modified Paths: -------------- trunk/include/loki/StrongPtr.h Modified: trunk/include/loki/StrongPtr.h =================================================================== --- trunk/include/loki/StrongPtr.h 2008-11-10 05:55:12 UTC (rev 903) +++ trunk/include/loki/StrongPtr.h 2008-11-10 05:59:59 UTC (rev 904) @@ -3,12 +3,12 @@ // Copyright (c) 2006 Rich Sposato // The copyright on this file is protected under the terms of the MIT license. // -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. -// The author makes no representations about the -// suitability of this software for any purpose. It is provided "as is" +// The author makes no representations about the +// suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_STRONG_PTR_INC_ @@ -117,7 +117,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class DeleteUsingFree /// -/// \ingroup StrongPointerDeleteGroup +/// \ingroup StrongPointerDeleteGroup /// Implementation of the DeletePolicy used by StrongPtr. Uses explicit call /// to T's destructor followed by call to free. This policy is useful for /// managing the lifetime of pointers to structs returned by C functions. @@ -148,7 +148,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class DeleteNothing /// -/// \ingroup StrongPointerDeleteGroup +/// \ingroup StrongPointerDeleteGroup /// Implementation of the DeletePolicy used by StrongPtr. This will never /// delete anything. You can use this policy with pointers to an undefined /// type or a pure interface class with a protected destructor. @@ -174,7 +174,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class DeleteSingle /// -/// \ingroup StrongPointerDeleteGroup +/// \ingroup StrongPointerDeleteGroup /// Implementation of the DeletePolicy used by StrongPtr. This deletes just /// one shared object. This is the default class for the DeletePolicy. //////////////////////////////////////////////////////////////////////////////// @@ -205,7 +205,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class DeleteArray /// -/// \ingroup StrongPointerDeleteGroup +/// \ingroup StrongPointerDeleteGroup /// Implementation of the DeletePolicy used by StrongPtr. This deletes an /// array of shared objects. //////////////////////////////////////////////////////////////////////////////// @@ -236,7 +236,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class CantResetWithStrong /// -/// \ingroup StrongPointerResetGroup +/// \ingroup StrongPointerResetGroup /// Implementation of the ResetPolicy used by StrongPtr. This is the default /// ResetPolicy for StrongPtr. It forbids reset and release only if a strong /// copointer exists. @@ -259,7 +259,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class AllowReset /// -/// \ingroup StrongPointerResetGroup +/// \ingroup StrongPointerResetGroup /// Implementation of the ResetPolicy used by StrongPtr. It allows reset and /// release under any circumstance. //////////////////////////////////////////////////////////////////////////////// @@ -280,7 +280,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class NeverReset /// -/// \ingroup StrongPointerResetGroup +/// \ingroup StrongPointerResetGroup /// Implementation of the ResetPolicy used by StrongPtr. It forbids reset and /// release under any circumstance. //////////////////////////////////////////////////////////////////////////////// @@ -359,10 +359,12 @@ ++m_weakCount; } - inline void DecStrongCount( void ) + inline bool DecStrongCount( void ) { assert( 0 < m_strongCount ); --m_strongCount; + const bool isZero = ( 0 == m_strongCount ); + return isZero; } inline void DecWeakCount( void ) @@ -483,11 +485,12 @@ m_Mutex.Unlock(); } - inline void DecStrongCount( void ) + inline bool DecStrongCount( void ) { m_Mutex.Lock(); - TwoRefCountInfo::DecStrongCount(); + const bool isZero = TwoRefCountInfo::DecStrongCount(); m_Mutex.Unlock(); + return isZero; } inline void DecWeakCount( void ) @@ -572,10 +575,6 @@ return Decrement( strong ); } - void Increment( bool strong ); - - bool Decrement( bool strong ); - bool HasStrongPointer( void ) const { return m_counts->HasStrongPointer(); @@ -604,6 +603,10 @@ TwoRefCounts( void ); TwoRefCounts & operator = ( const TwoRefCounts & ); + void Increment( bool strong ); + + bool Decrement( bool strong ); + /// Pointer to all shared data. Loki::Private::TwoRefCountInfo * m_counts; }; @@ -696,15 +699,17 @@ bool Decrement( bool strong ) { + bool noStrongPointers = false; if ( strong ) { - m_counts->DecStrongCount(); + noStrongPointers = m_counts->DecStrongCount(); } else { m_counts->DecWeakCount(); + noStrongPointers = !m_counts->HasStrongPointer(); } - return !m_counts->HasStrongPointer(); + return noStrongPointers; } bool HasStrongPointer( void ) const @@ -832,7 +837,7 @@ //////////////////////////////////////////////////////////////////////////////// /// \class StrongPtr /// -/// \ingroup SmartPointerGroup +/// \ingroup SmartPointerGroup /// /// \param Strong default = true, /// \param OwnershipPolicy default = TwoRefCounts, @@ -855,7 +860,7 @@ template < class > class ConstnessPolicy = LOKI_DEFAULT_CONSTNESS > class StrongPtr - : public OwnershipPolicy + : protected OwnershipPolicy , public ConversionPolicy , public CheckingPolicy< T * > , public ResetPolicy< T > @@ -1059,7 +1064,7 @@ } #else - + template < typename T1, @@ -1073,8 +1078,8 @@ > friend bool ReleaseAll( StrongPtr< T1, S1, OP1, CP1, KP1, RP1, DP1, CNP1 > & sp, typename StrongPtr< T1, S1, OP1, CP1, KP1, RP1, DP1, CNP1 >::StoredType & p ); - + template < typename T1, @@ -1320,7 +1325,7 @@ Tester(int) {} void dummy() {} }; - + typedef void (Tester::*unspecified_boolean_type_)(); typedef typename Select< CP::allow, Tester, unspecified_boolean_type_ >::Result @@ -1339,11 +1344,11 @@ { Insipid(PointerType) {} }; - + typedef typename Select< CP::allow, PointerType, Insipid >::Result AutomaticConversionResult; -public: +public: operator AutomaticConversionResult() const { return GetPointer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |