From: <ric...@us...> - 2011-09-20 22:33:40
|
Revision: 1109 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1109&view=rev Author: rich_sposato Date: 2011-09-20 22:33:34 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Added array handling to SmartPtr. Modified Paths: -------------- trunk/include/loki/SmartPtr.h trunk/src/SmartPtr.cpp Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-20 18:38:13 UTC (rev 1108) +++ trunk/include/loki/SmartPtr.h 2011-09-20 22:33:34 UTC (rev 1109) @@ -355,7 +355,46 @@ inline typename LockedStorage<T>::StoredType& GetImplRef(LockedStorage<T>& sp) { return sp.pointee_; } + namespace Private + { + //////////////////////////////////////////////////////////////////////////////// + /// \class DeleteArrayBase + /// + /// \ingroup StrongPointerDeleteGroup + /// Base class used only by the DeleteArray policy class. This stores the + /// number of elements in an array of shared objects. + //////////////////////////////////////////////////////////////////////////////// + + class DeleteArrayBase + { + public: + + inline size_t GetArrayCount( void ) const { return m_itemCount; } + + protected: + + DeleteArrayBase( void ) : m_itemCount( 0 ) {} + + explicit DeleteArrayBase( size_t itemCount ) : m_itemCount( itemCount ) {} + + DeleteArrayBase( const DeleteArrayBase & that ) : m_itemCount( that.m_itemCount ) {} + + void Swap( DeleteArrayBase & rhs ); + + void OnInit( const void * p ) const; + + void OnCheckRange( size_t index ) const; + + private: + + size_t m_itemCount; + + }; + + } + + //////////////////////////////////////////////////////////////////////////////// /// \class ArrayStorage /// @@ -365,7 +404,7 @@ template <class T> - class ArrayStorage + class ArrayStorage : public ::Loki::Private::DeleteArrayBase { public: @@ -376,26 +415,30 @@ protected: - ArrayStorage() : pointee_(Default()) + ArrayStorage() : DeleteArrayBase(), pointee_(Default()) {} // The storage policy doesn't initialize the stored pointer // which will be initialized by the OwnershipPolicy's Clone fn - ArrayStorage(const ArrayStorage&) : pointee_(0) + ArrayStorage( const ArrayStorage & that ) : DeleteArrayBase( that ), pointee_( 0 ) {} template <class U> - ArrayStorage(const ArrayStorage<U>&) : pointee_(0) + ArrayStorage( const ArrayStorage< U >& that ) : DeleteArrayBase( that ), pointee_( 0 ) {} - explicit ArrayStorage(const StoredType& p) : pointee_(p) {} + ArrayStorage( const StoredType & p, size_t count ) : DeleteArrayBase( count ), + pointee_( p ) {} PointerType operator->() const { return pointee_; } ReferenceType operator*() const { return *pointee_; } - void Swap(ArrayStorage& rhs) - { std::swap(pointee_, rhs.pointee_); } + void Swap( ArrayStorage & rhs ) + { + DeleteArrayBase::Swap( rhs ); + ::std::swap( pointee_, rhs.pointee_ ); + } // Accessors template <class F> @@ -844,6 +887,8 @@ NoCheck() {} + NoCheck( const NoCheck & ) {} + template <class P1> NoCheck(const NoCheck<P1>&) {} @@ -878,6 +923,8 @@ AssertCheck() {} + AssertCheck( const AssertCheck & ) {} + template <class P1> AssertCheck(const AssertCheck<P1>&) {} @@ -916,6 +963,8 @@ AssertCheckStrict() {} + AssertCheckStrict( const AssertCheckStrict & ) {} + template <class U> AssertCheckStrict(const AssertCheckStrict<U>&) {} @@ -972,6 +1021,8 @@ RejectNullStatic() {} + RejectNullStatic( const RejectNullStatic & ) {} + template <class P1> RejectNullStatic(const RejectNullStatic<P1>&) {} @@ -1022,6 +1073,8 @@ RejectNull() {} + RejectNull( const RejectNull & ) {} + template <class P1> RejectNull(const RejectNull<P1>&) {} @@ -1058,6 +1111,8 @@ RejectNullStrict() {} + RejectNullStrict( const RejectNullStrict & ) {} + template <class P1> RejectNullStrict(const RejectNullStrict<P1>&) {} @@ -1245,6 +1300,16 @@ KP::OnInit(GetImpl(*this)); } + /** This constructor was designed to only work with the ArrayStorage policy. Using it with + any other Delete policies will cause compiler errors. Call it with this syntax: + "ThingyPtr sp2( new Thingy[ 4 ], 4 );" so SmartPtr can do range checking on the number of elements. + */ + SmartPtr( ImplicitArg p, size_t itemCount ) : SP( p, itemCount ) + { + KP::OnInit( GetImpl( *this ) ); + SP::OnInit( GetImpl( *this ) ); + } + SmartPtr(CopyArg& rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { KP::OnDereference( GetImpl( rhs ) ); @@ -1333,6 +1398,21 @@ return *this; } + /** This function is equivalent to an assignment operator for SmartPtr's that use the + DeleteArray policy where the programmer needs to write the equivalent of "sp = new P;". + With DeleteArray, the programmer should write "sp.Assign( new [5] Thingy, 5 );" so the + SmartPtr knows how many elements are in the array. + */ + SmartPtr & Assign( T * p, size_t itemCount ) + { + if ( GetImpl( *this ) != p ) + { + SmartPtr temp( p, itemCount ); + Swap( temp ); + } + return *this; + } + void Swap(SmartPtr& rhs) { OP::Swap(rhs); @@ -1465,6 +1545,30 @@ return SP::operator*(); } + /** operator[] returns a reference to an modifiable object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ + ReferenceType operator [] ( size_t index ) + { + PointerType p = SP::operator->(); + KP::OnDereference( p ); + SP::OnCheckRange( index ); + return p[ index ]; + } + + /** operator[] returns a reference to a const object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ + ConstReferenceType operator [] ( size_t index ) const + { + ConstPointerType p = SP::operator->(); + KP::OnDereference( p ); + SP::OnCheckRange( index ); + return p[ index ]; + } + bool operator!() const // Enables "if (!sp) ..." { return GetImpl(*this) == 0; } Modified: trunk/src/SmartPtr.cpp =================================================================== --- trunk/src/SmartPtr.cpp 2011-09-20 18:38:13 UTC (rev 1108) +++ trunk/src/SmartPtr.cpp 2011-09-20 22:33:34 UTC (rev 1109) @@ -21,6 +21,9 @@ #include <cassert> +#include <stdexcept> +#include <string> + //#define DO_EXTRA_LOKI_TESTS #ifdef DO_EXTRA_LOKI_TESTS #include <iostream> @@ -37,6 +40,45 @@ // ---------------------------------------------------------------------------- +void DeleteArrayBase::Swap( DeleteArrayBase & rhs ) +{ + assert( NULL != this ); + + const size_t temp = m_itemCount; + m_itemCount = rhs.m_itemCount; + rhs.m_itemCount = temp; +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnInit( const void * p ) const +{ + assert( NULL != this ); + if ( NULL == p ) + { + assert( 0 == m_itemCount ); + } + else + { + assert( 0 < m_itemCount ); + } +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnCheckRange( size_t index ) const +{ + assert( NULL != this ); + + if ( index < m_itemCount ) + return; + + const ::std::string message( "index out of range in ::Loki::DeleteArrayBase::OnCheckRange" ); + throw ::std::out_of_range( message ); +} + +// ---------------------------------------------------------------------------- + RefLinkedBase::RefLinkedBase( const RefLinkedBase & rhs ) : prev_( &rhs ), next_( rhs.next_ ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 22:34:32
|
Revision: 1110 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1110&view=rev Author: rich_sposato Date: 2011-09-20 22:34:24 +0000 (Tue, 20 Sep 2011) Log Message: ----------- A little cleanup. Moved class to SmartPtr.cpp and SmartPtr.h files. Modified Paths: -------------- trunk/Loki.workspace trunk/include/loki/StrongPtr.h trunk/include/loki/ThreadLocal.h trunk/include/loki/flex/flex_string_shell.h trunk/src/StrongPtr.cpp trunk/test/LevelMutex/LevelMutex.cbp trunk/test/LevelMutex/MultiThreadTests.cpp trunk/test/LevelMutex/ThreadPool.cpp trunk/test/LevelMutex/main.cpp trunk/test/LockingPtr/LockingPtr.cbp trunk/test/SmartPtr/SmartPtr.cbp trunk/test/SmartPtr/base.h trunk/test/SmartPtr/main.cpp trunk/test/SmartPtr/strong.cpp trunk/test/ThreadLocal/ThreadLocal.cbp trunk/test/ThreadLocal/main.cpp Modified: trunk/Loki.workspace =================================================================== --- trunk/Loki.workspace 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/Loki.workspace 2011-09-20 22:34:24 UTC (rev 1110) @@ -2,46 +2,46 @@ <CodeBlocks_workspace_file> <Workspace title="Workspace"> <Project filename="Loki.cbp" active="1" /> - <Project filename="test\CachedFactory\CachedFactory.cbp"> + <Project filename="test/CachedFactory/CachedFactory.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Checker\Checker.cbp" /> - <Project filename="test\CheckReturn\CheckReturn.cbp" /> - <Project filename="test\DeletableSingleton\DeletableSingleton.cbp"> + <Project filename="test/Checker/Checker.cbp" /> + <Project filename="test/CheckReturn/CheckReturn.cbp" /> + <Project filename="test/DeletableSingleton/DeletableSingleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Factory\Factory.cbp" /> - <Project filename="test\flex_string\flex_string.cbp" /> - <Project filename="test\Function\Function.cbp" /> - <Project filename="test\LevelMutex\LevelMutex.cbp"> + <Project filename="test/Factory/Factory.cbp" /> + <Project filename="test/flex_string/flex_string.cbp" /> + <Project filename="test/Function/Function.cbp" /> + <Project filename="test/LevelMutex/LevelMutex.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\LockingPtr\LockingPtr.cbp" /> - <Project filename="test\Longevity\Longevity.cbp" /> - <Project filename="test\OrderedStatic\OrderedStatic.cbp"> + <Project filename="test/LockingPtr/LockingPtr.cbp" /> + <Project filename="test/Longevity/Longevity.cbp" /> + <Project filename="test/OrderedStatic/OrderedStatic.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Pimpl\Pimpl.cbp" /> - <Project filename="test\Register\Register.cbp" /> - <Project filename="test\RegressionTest\RegressionTest.cbp"> + <Project filename="test/Pimpl/Pimpl.cbp" /> + <Project filename="test/Register/Register.cbp" /> + <Project filename="test/RegressionTest/RegressionTest.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\SafeFormat\SafeFormat.cbp"> + <Project filename="test/SafeFormat/SafeFormat.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\ScopeGuard\ScopeGuard.cbp" /> - <Project filename="test\Singleton\Singleton.cbp"> + <Project filename="test/ScopeGuard/ScopeGuard.cbp" /> + <Project filename="test/Singleton/Singleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\SmallObj\SmallObj.cbp"> + <Project filename="test/SmallObj/SmallObj.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\SmallObj\DefaultAlloc.cbp" /> - <Project filename="test\SmartPtr\SmartPtr.cbp"> + <Project filename="test/SmallObj/DefaultAlloc.cbp" /> + <Project filename="test/SmartPtr/SmartPtr.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Visitor\Visitor.cbp" /> - <Project filename="test\SafeBits\SafeBits.cbp" /> - <Project filename="test\ThreadLocal\ThreadLocal.cbp" /> + <Project filename="test/Visitor/Visitor.cbp" /> + <Project filename="test/SafeBits/SafeBits.cbp" /> + <Project filename="test/ThreadLocal/ThreadLocal.cbp" /> </Workspace> </CodeBlocks_workspace_file> Modified: trunk/include/loki/StrongPtr.h =================================================================== --- trunk/include/loki/StrongPtr.h 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/include/loki/StrongPtr.h 2011-09-20 22:34:24 UTC (rev 1110) @@ -85,7 +85,10 @@ /// If you write your own policy, you must implement these 3 functions: /// -# void static Delete( const P * p ) /// -# static P * Default( void ) -/// -# void Swap( YourResetPolicy & ) +/// -# Default constructor. +/// -# Copy constructor. +/// -# Templated copy constructor. +/// -# void Swap( YourDeletePolicy & ) /// /// \par ResetPolicy /// A reset policy tells the ReleaseAll and ResetAll functions whether they @@ -235,46 +238,7 @@ inline void Swap( DeleteSingle & ) {} }; -namespace Private -{ - //////////////////////////////////////////////////////////////////////////////// -/// \class DeleteArrayBase -/// -/// \ingroup StrongPointerDeleteGroup -/// Base class used only by the DeleteArray policy class. This stores the -/// number of elements in an array of shared objects. -//////////////////////////////////////////////////////////////////////////////// - -class DeleteArrayBase -{ -public: - - inline size_t GetArrayCount( void ) const { return m_itemCount; } - -protected: - - DeleteArrayBase( void ) : m_itemCount( 0 ) {} - - explicit DeleteArrayBase( size_t itemCount ) : m_itemCount( itemCount ) {} - - DeleteArrayBase( const DeleteArrayBase & that ) : m_itemCount( that.m_itemCount ) {} - - void Swap( DeleteArrayBase & rhs ); - - void OnInit( const void * p ) const; - - void OnCheckRange( size_t index ) const; - -private: - - size_t m_itemCount; - -}; - -} - -//////////////////////////////////////////////////////////////////////////////// /// \class DeleteArray /// /// \ingroup StrongPointerDeleteGroup @@ -2068,19 +2032,27 @@ return * GetPointer(); } + /** operator[] returns a reference to an modifiable object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ ReferenceType operator [] ( size_t index ) { - KP::OnDereference( GetPointer() ); - DP::OnCheckRange( index ); PointerType p = GetPointer(); + KP::OnDereference( p ); + DP::OnCheckRange( index ); return p[ index ]; } + /** operator[] returns a reference to a const object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ ConstReferenceType operator [] ( size_t index ) const { - KP::OnDereference( GetPointer() ); - DP::OnCheckRange( index ); ConstPointerType p = GetPointer(); + KP::OnDereference( p ); + DP::OnCheckRange( index ); return p[ index ]; } Modified: trunk/include/loki/ThreadLocal.h =================================================================== --- trunk/include/loki/ThreadLocal.h 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/include/loki/ThreadLocal.h 2011-09-20 22:34:24 UTC (rev 1110) @@ -28,21 +28,29 @@ // The __APPLE__ macro does not refer to a compiler, but to the Apple OSX operating system. #if defined( __APPLE__ ) #warning "GCC for Apple does not allow thread_local storage, so you can not use some parts of Loki." - #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #elif defined( __CYGWIN__ ) #if ( __GNUC__ <= 3 ) #warning "Older versions of GCC for Cygwin do not allow thread_local storage, so you can not use some parts of Loki." - #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #endif #elif ( __GNUC__ == 4 ) // GNU versions other than Cygwin. - #if ( __GNUC_MINOR__ == 4 ) - #warning "GCC version 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki." - #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #if ( __GNUC_MINOR__ < 4 ) + #warning "GCC versions before 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki." + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #else + #warning "Versions 4.4 through 4.6 of GCC implemented thread_local storage for some platforms, but not others. Run ThreadLocal test project." #endif #endif -#endif + +#elif defined( _MSC_VER ) + #if ( _MSC_VER < 1300 ) + #warning "Only Visual Studio versions 7.0 and after support thread local storage properly, so you can not use some parts of Loki." + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #endif +#endif #if defined( LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE ) && !defined( LOKI_THREAD_LOCAL ) @@ -57,11 +65,7 @@ you can't use some parts of Loki. */ #if defined( _MSC_VER ) - #if ( _MSC_VER >= 1300 ) - #define LOKI_THREAD_LOCAL __declspec( thread ) - #else - #error "Only Visual Studio versions 7.0 and after supported." - #endif + #define LOKI_THREAD_LOCAL __declspec( thread ) #elif ( __GNUC__ ) #define LOKI_THREAD_LOCAL __thread Modified: trunk/include/loki/flex/flex_string_shell.h =================================================================== --- trunk/include/loki/flex/flex_string_shell.h 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/include/loki/flex/flex_string_shell.h 2011-09-20 22:34:24 UTC (rev 1110) @@ -1339,17 +1339,17 @@ typename flex_string<E, T, A, S>::value_type delim) { size_t nread = 0; - typename basic_istream<typename flex_string<E, T, A, S>::value_type, + typename std::basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>::sentry sentry(is, true); if (sentry) { - basic_streambuf<typename flex_string<E, T, A, S>::value_type, + ::std::basic_streambuf<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>* buf = is.rdbuf(); str.clear(); while (nread < str.max_size()) { int c1 = buf->sbumpc(); if (flex_string<E, T, A, S>::traits_type::eq_int_type(c1, flex_string<E, T, A, S>::traits_type::eof())) { - is.setstate(ios_base::eofbit); + is.setstate(::std::ios_base::eofbit); break; } else { @@ -1363,7 +1363,7 @@ } } if (nread == 0 || nread >= str.max_size()) - is.setstate(ios_base::failbit); + is.setstate(::std::ios_base::failbit); return is; } Modified: trunk/src/StrongPtr.cpp =================================================================== --- trunk/src/StrongPtr.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/src/StrongPtr.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -15,9 +15,6 @@ #include <loki/StrongPtr.h> -#include <stdexcept> -#include <string> - #include <memory.h> #ifdef DO_EXTRA_LOKI_TESTS #include <cassert> @@ -41,45 +38,6 @@ // ---------------------------------------------------------------------------- -void DeleteArrayBase::Swap( DeleteArrayBase & rhs ) -{ - assert( NULL != this ); - - const size_t temp = m_itemCount; - m_itemCount = rhs.m_itemCount; - rhs.m_itemCount = temp; -} - -// ---------------------------------------------------------------------------- - -void DeleteArrayBase::OnInit( const void * p ) const -{ - assert( NULL != this ); - if ( NULL == p ) - { - assert( 0 == m_itemCount ); - } - else - { - assert( 0 < m_itemCount ); - } -} - -// ---------------------------------------------------------------------------- - -void DeleteArrayBase::OnCheckRange( size_t index ) const -{ - assert( NULL != this ); - - if ( index < m_itemCount ) - return; - - const ::std::string message( "index out of range in ::Loki::DeleteArrayBase::OnCheckRange" ); - throw ::std::out_of_range( message ); -} - -// ---------------------------------------------------------------------------- - OneOwnerRefCountInfo::OneOwnerRefCountInfo( SingleOwnerRefCount * ptr ) : m_pointer( NULL ) , m_strongPtr( ptr ) Modified: trunk/test/LevelMutex/LevelMutex.cbp =================================================================== --- trunk/test/LevelMutex/LevelMutex.cbp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LevelMutex/LevelMutex.cbp 2011-09-20 22:34:24 UTC (rev 1110) @@ -6,24 +6,24 @@ <Option compiler="cygwin" /> <Build> <Target title="Debug_GCC"> - <Option output="obj\Debug_GCC\LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="obj/Debug_GCC/LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> + <Add option="-g" /> <Add option="-W" /> - <Add option="-g" /> - <Add directory="..\..\include" /> - <Add directory="..\..\include\loki" /> + <Add directory="../../include" /> + <Add directory="../../include/loki" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki_D.a" /> - <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> + <Add library="../../lib/GCC/Loki_D.a" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj\Release_GCC\LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="obj/Release_GCC/LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -31,33 +31,33 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include" /> - <Add directory="..\..\include\loki" /> + <Add directory="../../include" /> + <Add directory="../../include/loki" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki.a" /> - <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> + <Add library="../../lib/GCC/Loki.a" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="obj\Debug_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_Cygwin\" /> + <Option output="obj/Debug_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="..\..\include" /> - <Add directory="..\..\include\loki" /> + <Add directory="../../include" /> + <Add directory="../../include/loki" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki_D.a" /> - <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> + <Add library="../../lib/Cygwin/Loki_D.a" /> + <Add library="../../../PThreads/lib/pthreadVC2.lib" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="obj\Release_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_Cygwin\" /> + <Option output="obj/Release_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> @@ -65,12 +65,12 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include" /> - <Add directory="..\..\include\loki" /> + <Add directory="../../include" /> + <Add directory="../../include/loki" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki.a" /> - <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> + <Add library="../../lib/Cygwin/Loki.a" /> + <Add library="../../../PThreads/lib/pthreadVC2.lib" /> </Linker> </Target> </Build> Modified: trunk/test/LevelMutex/MultiThreadTests.cpp =================================================================== --- trunk/test/LevelMutex/MultiThreadTests.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LevelMutex/MultiThreadTests.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -4,9 +4,9 @@ // Copyright (c) 2008, 2009 Richard 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 @@ -22,7 +22,7 @@ #include "MultiThreadTests.hpp" #include <assert.h> -#include <process.h> +//#include <process.h> #include <stdlib.h> #include <time.h> @@ -239,6 +239,8 @@ void MultiThreadSimpleTest( void ) { + cout << "Starting MultiThreadSimpleTest." << endl; + Thing::Init( 0 ); const unsigned int threadCount = 5; ThreadPool pool( threadCount ); @@ -262,6 +264,8 @@ pool.JoinAll(); Thing::Destroy(); + + cout << "Finished MultiThreadSimpleTest." << endl; } // ---------------------------------------------------------------------------- @@ -299,13 +303,17 @@ void MultiThreadTryLockTest( void ) { + cout << "Starting MultiThreadTryLockTest." << endl; + static const unsigned int threadCount = 3; Thing::Init( 0 ); volatile Thing & thing = Thing::GetIt(); volatile SleepMutex & mutex = thing.GetMutex(); cout << endl << "Doing multi-threaded TryLock test. This test should not deadlock." << endl; - ::system( "pause" ); + cout << "Press enter key to continue." << endl; + char theKey = 0; + cin.get( theKey ); // First step is to lock the mutex in the main thread so no child thread // can ever lock it, change the value, or anything like that. MutexErrors::Type result = mutex.Lock(); @@ -313,36 +321,46 @@ bool okay = mutex.IsLockedByCurrentThread(); assert( okay ); thing.SetValue( threadCount ); - ThreadPool pool( threadCount ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + { - void * p = reinterpret_cast< void * >( ii ); - pool.Start( TryLockThread, p ); + ThreadPool pool( threadCount ); + for ( unsigned int ii = 0; ii < threadCount; ++ii ) + { + void * p = reinterpret_cast< void * >( ii ); + pool.Start( TryLockThread, p ); + } + pool.JoinAll(); } - pool.JoinAll(); - const unsigned int value = thing.GetValue(); - assert( value == threadCount ); - result = mutex.Unlock(); - assert( MutexErrors::Success == result ); - okay = !mutex.IsLockedByCurrentThread(); - assert( okay ); - okay = !mutex.IsLocked(); - assert( okay ); + const unsigned int value = thing.GetValue(); + assert( value == threadCount ); + result = mutex.Unlock(); + assert( MutexErrors::Success == result ); + okay = !mutex.IsLockedByCurrentThread(); + assert( okay ); + okay = !mutex.IsLocked(); + assert( okay ); + Thing::Destroy(); + + cout << "Finished MultiThreadTryLockTest." << endl; } // ---------------------------------------------------------------------------- void MultiThreadReentrantTest( void ) { + cout << "Starting MultiThreadReentrantTest." << endl; + Thing::Init( 0 ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); ThreadPool pool( threadCount ); cout << endl << "Doing thread-safe value test. This test should pass and not deadlock." << endl; - ::system( "pause" ); + cout << "Press enter key to continue." << endl; + char theKey = 0; + cin.get( theKey ); for ( unsigned int ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); @@ -352,7 +370,8 @@ TestResults::GetIt()->OutputResults(); cout << endl << "Doing thread-unsafe value test. This test may fail." << endl; - ::system( "pause" ); + cout << "Press enter key to continue." << endl; + cin.get( theKey ); for ( unsigned int ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); @@ -363,6 +382,8 @@ TestResults::Destroy(); Thing::Destroy(); + + cout << "Finished MultiThreadReentrantTest." << endl; } // ---------------------------------------------------------------------------- @@ -646,6 +667,8 @@ void MultiThreadMultiLockTest( void ) { + cout << "Starting MultiThreadMultiLockTest." << endl; + Thing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -674,6 +697,8 @@ TestResults::Destroy(); Thing::DestroyPool(); + + cout << "Finished MultiThreadMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -808,6 +833,8 @@ void MultiThreadRandomMultiLockTest( void ) { + cout << "Starting MultiThreadRandomMultiLockTest." << endl; + Thing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -836,6 +863,8 @@ TestResults::Destroy(); Thing::DestroyPool(); + + cout << "Finished MultiThreadRandomMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -936,6 +965,8 @@ void MultiThreadHierarchySingleLockTest( void ) { + cout << "Starting MultiThreadHierarchySingleLockTest." << endl; + LevelThing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -964,6 +995,8 @@ TestResults::Destroy(); LevelThing::DestroyPool(); + + cout << "Finished MultiThreadHierarchySingleLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -1065,6 +1098,8 @@ void MultiThreadHierarchyMultiLockTest( void ) { + cout << "Starting MultiThreadHierarchyMultiLockTest." << endl; + MultiLevelPool::MakePool( 10, thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -1093,6 +1128,8 @@ TestResults::Destroy(); MultiLevelPool::DestroyPool(); + + cout << "Finished MultiThreadHierarchyMultiLockTest." << endl; } // ---------------------------------------------------------------------------- Modified: trunk/test/LevelMutex/ThreadPool.cpp =================================================================== --- trunk/test/LevelMutex/ThreadPool.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LevelMutex/ThreadPool.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -20,7 +20,7 @@ #include <assert.h> -#include <process.h> +//#include <process.h> #if !defined( _MSC_VER ) #include <unistd.h> // needed for the usleep function. #endif @@ -86,11 +86,13 @@ bool Thread::WaitForThread( void ) volatile { assert( IsValid( m_owner ) ); + const volatile Thread * current = Thread::GetCurrentThread(); if ( this == current ) return false; if ( m_status == Thread::Dead ) return false; + while ( this->m_status == Thread::Active ) { // Call the wait policy. @@ -100,6 +102,8 @@ ::usleep( 1000 ); #endif } + + m_status = Thread::Idle; return true; } Modified: trunk/test/LevelMutex/main.cpp =================================================================== --- trunk/test/LevelMutex/main.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LevelMutex/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -48,6 +48,8 @@ void SingleThreadSimpleTest( void ) { + cout << "Starting SingleThreadSimpleTest." << endl; + const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -171,6 +173,8 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); + + cout << "Finished SingleThreadSimpleTest." << endl; } // ---------------------------------------------------------------------------- @@ -178,6 +182,8 @@ void SingleThreadReentrantTest( void ) { + cout << "Starting SingleThreadReentrantTest." << endl; + const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -283,6 +289,8 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); + + cout << "Finished SingleThreadReentrantTest." << endl; } // ---------------------------------------------------------------------------- @@ -290,6 +298,8 @@ void SingleThreadSimpleMultiLockTest( void ) { + cout << "Starting SingleThreadSimpleMultiLockTest." << endl; + const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -481,6 +491,8 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); + + cout << "Finished SingleThreadSimpleMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -488,6 +500,8 @@ void SingleThreadExceptionTest( void ) { + cout << "Starting SingleThreadExceptionTest." << endl; + const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -636,6 +650,8 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); + + cout << "Finished SingleThreadExceptionTest." << endl; } // ---------------------------------------------------------------------------- @@ -660,6 +676,7 @@ MultiThreadSimpleTest(); MultiThreadTryLockTest(); + cout << "main 679" << endl; MultiThreadReentrantTest(); MultiThreadMultiLockTest(); MultiThreadRandomMultiLockTest(); Modified: trunk/test/LockingPtr/LockingPtr.cbp =================================================================== --- trunk/test/LockingPtr/LockingPtr.cbp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LockingPtr/LockingPtr.cbp 2011-09-20 22:34:24 UTC (rev 1110) @@ -3,26 +3,27 @@ <FileVersion major="1" minor="6" /> <Project> <Option title="LockingPtr" /> - <Option compiler="cygwin" /> + <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="obj\Debug_GCC\LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="obj/Debug_GCC/LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> + <Add option="-g" /> <Add option="-W" /> - <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki_D.a" /> + <Add library="../../lib/GCC/Loki_D.a" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj\Release_GCC\LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="obj/Release_GCC/LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -30,43 +31,44 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki.a" /> + <Add library="../../lib/GCC/Loki.a" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="obj\Debug_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_Cygwin\" /> + <Option output="obj/Debug_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_Cygwin/" /> <Option type="1" /> - <Option compiler="cygwin" /> + <Option compiler="gcc" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki_D.a" /> + <Add library="../../lib/Cygwin/Loki_D.a" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="obj\Release_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_Cygwin\" /> + <Option output="obj/Release_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_Cygwin/" /> <Option type="1" /> - <Option compiler="cygwin" /> + <Option compiler="gcc" /> <Compiler> <Add option="-fexpensive-optimizations" /> <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki.a" /> + <Add library="../../lib/Cygwin/Loki.a" /> </Linker> </Target> </Build> Modified: trunk/test/SmartPtr/SmartPtr.cbp =================================================================== --- trunk/test/SmartPtr/SmartPtr.cbp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/SmartPtr/SmartPtr.cbp 2011-09-20 22:34:24 UTC (rev 1110) @@ -6,23 +6,25 @@ <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="bin\Debug_GCC\SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="bin/Debug_GCC/SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> + <Add option="-g" /> <Add option="-W" /> - <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki_D.a" /> + <Add library="../../lib/GCC/Loki_D.a" /> + <Add library="/usr/lib/libpthread.so" /> + <Add library="/usr/lib/libc.so" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="bin\Release_GCC\SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="bin/Release_GCC/SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -30,31 +32,33 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki.a" /> + <Add library="../../lib/GCC/Loki.a" /> + <Add library="/usr/lib/libpthread.so" /> + <Add library="/usr/lib/libc.so" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="bin\Debug_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_Cygwin\" /> + <Option output="bin/Debug_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki_D.a" /> + <Add library="../../lib/Cygwin/Loki_D.a" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="bin\Release_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_Cygwin\" /> + <Option output="bin/Release_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> @@ -62,11 +66,11 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki.a" /> + <Add library="../../lib/Cygwin/Loki.a" /> </Linker> </Target> </Build> @@ -74,6 +78,7 @@ <Unit filename="base.h"> <Option target="<{~None~}>" /> </Unit> + <Unit filename="colvin_gibbons_trick.cpp" /> <Unit filename="main.cpp" /> <Unit filename="strong.cpp" /> <Extensions> Modified: trunk/test/SmartPtr/base.h =================================================================== --- trunk/test/SmartPtr/base.h 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/SmartPtr/base.h 2011-09-20 22:34:24 UTC (rev 1110) @@ -73,10 +73,11 @@ return s_destructions; } +protected: + BaseClass( const BaseClass & that ) : m_refCount( that.m_refCount ) {} + private: /// Not implemented. - BaseClass( const BaseClass & ); - /// Not implemented. BaseClass & operator = ( const BaseClass & ); static unsigned int s_constructions; @@ -110,7 +111,45 @@ } }; +// ---------------------------------------------------------------------------- +/** @class Feline - The feline family of classes are to test dynamic_cast. Also used to test + pointers to arrays of objects. + */ +class Feline : public BaseClass +{ +public: + virtual ~Feline() {} + virtual Feline * Clone( void ) const = 0; +}; + +class Lion : public Feline +{ +public: + virtual ~Lion() {} + virtual Lion * Clone( void ) const { return new Lion( *this ); } +}; + +class Tiger : public Feline +{ +public: + Tiger( void ) : m_stripes( 100 ) {} + virtual ~Tiger() {} + virtual Tiger * Clone( void ) const { return new Tiger( *this ); } + unsigned int GetStripes( void ) const { return m_stripes; } + void SetStripes( unsigned int s ) { m_stripes = s; } +private: + unsigned int m_stripes; +}; + +class Dog +{ +public: + virtual ~Dog() {} + virtual Dog * Clone( void ) const { return new Dog( *this ); } +}; + + // ---------------------------------------------------------------------------- /** @class MimicCOM Acts like a COM object by having an intrusive ref count. Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/SmartPtr/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -1205,75 +1205,6 @@ // ---------------------------------------------------------------------------- -namespace -{ - - class Feline - { - public: - - static inline bool AllDestroyed( void ) - { - return ( s_constructions == s_destructions ); - } - - static inline bool ExtraConstructions( void ) - { - return ( s_constructions > s_destructions ); - } - - static inline bool ExtraDestructions( void ) - { - return ( s_constructions < s_destructions ); - } - - static inline unsigned int GetCtorCount( void ) - { - return s_constructions; - } - - static inline unsigned int GetDtorCount( void ) - { - return s_destructions; - } - - Feline( void ) { s_constructions++; } - virtual ~Feline() { s_destructions++; } - virtual Feline * Clone( void ) const = 0; - - private: - static unsigned int s_constructions; - static unsigned int s_destructions; - }; - - unsigned int Feline::s_constructions = 0; - unsigned int Feline::s_destructions = 0; - - class Tiger : public Feline - { - public: - virtual ~Tiger() {} - virtual Tiger * Clone( void ) const { return new Tiger( *this ); } - }; - - class Lion : public Feline - { - public: - virtual ~Lion() {} - virtual Lion * Clone( void ) const { return new Lion( *this ); } - }; - - class Dog - { - public: - virtual ~Dog() {} - virtual Dog * Clone( void ) const { return new Dog( *this ); } - }; - -} - -// ---------------------------------------------------------------------------- - void DoSmartPtrDynamicCastTests( void ) { cout << "Starting DoSmartPtrDynamicCastTests." << endl; @@ -1359,9 +1290,9 @@ assert( !pDog ); } - assert( Feline::AllDestroyed() ); - assert( !Feline::ExtraConstructions() ); - assert( !Feline::ExtraDestructions() ); + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); cout << "Finished DoSmartPtrDynamicCastTests." << endl; } @@ -1518,6 +1449,161 @@ // ---------------------------------------------------------------------------- +/// Use these typedefs to test DeleteArray policy. + +typedef Loki::SmartPtr< Tiger, RefCounted, DisallowConversion, + AssertCheck, ArrayStorage, DontPropagateConst > + TigerArray_RefCounted_ptr; + +typedef Loki::SmartPtr< Tiger, RefLinked, DisallowConversion, + AssertCheck, ArrayStorage, DontPropagateConst > + TigerArray_2RefLinks_ptr; + +// ---------------------------------------------------------------------------- + +void DoSmartArrayTests( void ) +{ + cout << "Starting DoSmartArrayTests." << endl; + + { + // test default construction. + TigerArray_RefCounted_ptr sp1; + assert( !sp1 ); + assert( 0 == sp1.GetArrayCount() ); + + // test assignment. + sp1.Assign( new Tiger[ 8 ], 8 ); + assert( sp1 ); + assert( 8 == sp1.GetArrayCount() ); + sp1[ 0 ].SetStripes( 8 ); + sp1[ 1 ].SetStripes( 16 ); + sp1[ 2 ].SetStripes( 24 ); + sp1[ 3 ].SetStripes( 32 ); + sp1[ 4 ].SetStripes( 40); + sp1[ 5 ].SetStripes( 48 ); + sp1[ 6 ].SetStripes( 56 ); + sp1[ 7 ].SetStripes( 64 ); + + // test initialization construction. + TigerArray_RefCounted_ptr sp2( new Tiger[ 4 ], 4 ); + assert( sp2 ); + assert( 4 == sp2.GetArrayCount() ); + sp2[ 0 ].SetStripes( 5 ); + sp2[ 1 ].SetStripes( 10 ); + sp2[ 2 ].SetStripes( 15 ); + sp2[ 3 ].SetStripes( 20 ); + + // test range checking. + try + { + Tiger & p4 = sp2[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + // test range checking. + try + { + Tiger & p8 = sp1[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + // test swap. + sp2.Swap( sp1 ); + assert( sp1 ); + assert( sp2 ); + // test checking of item count. + assert( 4 == sp1.GetArrayCount() ); + assert( 8 == sp2.GetArrayCount() ); + + // test that operator[] returns reference to + assert( 5 == sp1[ 0 ].GetStripes() ); + assert( 10 == sp1[ 1 ].GetStripes() ); + assert( 15 == sp1[ 2 ].GetStripes() ); + assert( 20 == sp1[ 3 ].GetStripes() ); + assert( 8 == sp2[ 0 ].GetStripes() ); + assert( 16 == sp2[ 1 ].GetStripes() ); + assert( 24 == sp2[ 2 ].GetStripes() ); + assert( 32 == sp2[ 3 ].GetStripes() ); + assert( 40 == sp2[ 4 ].GetStripes() ); + assert( 48 == sp2[ 5 ].GetStripes() ); + assert( 56 == sp2[ 6 ].GetStripes() ); + assert( 64 == sp2[ 7 ].GetStripes() ); + + try + { + Tiger & p4 = sp1[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + try + { + Tiger & p8 = sp2[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + const TigerArray_RefCounted_ptr sp3( sp1 ); + assert( sp3 == sp1 ); + assert( sp3.GetArrayCount() == sp1.GetArrayCount() ); + try + { + const Tiger & p4 = sp3[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + const TigerArray_RefCounted_ptr sp5( sp2 ); + assert( sp5 == sp2 ); + assert( sp5.GetArrayCount() == sp2.GetArrayCount() ); + try + { + const Tiger & p8 = sp5[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + sp2 = sp1; + assert( sp1 == sp2 ); + assert( sp3 == sp2 ); + assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); + assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); + assert( sp1 != sp5 ); + assert( sp2 != sp5 ); + assert( sp3 != sp5 ); + assert( sp1.GetArrayCount() != sp5.GetArrayCount() ); + assert( sp2.GetArrayCount() != sp5.GetArrayCount() ); + assert( sp3.GetArrayCount() != sp5.GetArrayCount() ); + } + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoSmartArrayTests." << endl; +} + +// ---------------------------------------------------------------------------- + int main( int argc, const char * argv[] ) { bool doThreadTest = false; @@ -1556,6 +1642,7 @@ DoSmartPtrDynamicCastTests(); DoStrongPtrDynamicCastTests(); DoStrongArrayTests(); + DoSmartArrayTests(); #if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING) if ( doThreadTest ) Modified: trunk/test/SmartPtr/strong.cpp =================================================================== --- trunk/test/SmartPtr/strong.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/SmartPtr/strong.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -1778,42 +1778,6 @@ // ---------------------------------------------------------------------------- -namespace -{ - - class Feline : public BaseClass - { - public: - virtual ~Feline() {} - }; - - class Lion : public Feline - { - public: - virtual ~Lion() {} - }; - - class Tiger : public Feline - { - public: - Tiger( void ) : m_stripes( 100 ) {} - virtual ~Tiger() {} - unsigned int GetStripes( void ) const { return m_stripes; } - void SetStripes( unsigned int s ) { m_stripes = s; } - private: - unsigned int m_stripes; - }; - - class Dog - { - public: - virtual ~Dog() {} - }; - -} - -// ---------------------------------------------------------------------------- - void DoStrongPtrDynamicCastTests( void ) { typedef ::Loki::StrongPtr< Feline, true, ::Loki::TwoRefCounts > FelineCountPtr; Modified: trunk/test/ThreadLocal/ThreadLocal.cbp =================================================================== --- trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-20 22:34:24 UTC (rev 1110) @@ -7,28 +7,37 @@ <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="obj\Debug_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="obj/Debug_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> <Add option="-Wmain" /> <Add option="-pedantic" /> + <Add option="-g" /> <Add option="-W" /> - <Add option="-g" /> - <Add directory="..\..\include" /> + <Add directory="../../include" /> </Compiler> + <Linker> + <Add library="/usr/lib/libpthread.so" /> + <Add library="/usr/lib/libc.so" /> + </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj\Release_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="obj/Release_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> <Add option="-O2" /> + <Add option="-Wmain" /> + <Add option="-pedantic" /> + <Add option="-W" /> + <Add directory="../../include" /> </Compiler> <Linker> <Add option="-s" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> </Build> @@ -41,6 +50,7 @@ <code_completion /> <debugger /> <lib_finder disable_auto="1" /> + <envvars /> </Extensions> </Project> </CodeBlocks_project_file> Modified: trunk/test/ThreadLocal/main.cpp =================================================================== --- trunk/test/ThreadLocal/main.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/ThreadLocal/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -26,19 +26,8 @@ #include <sstream> #include <iostream> +#include <stdlib.h> -using namespace ::std; - -#if !defined( NULL ) - #define NULL 0 -#endif - -// define nullptr even though new compilers will have this keyword just so we -// have a consistent and easy way of identifying which uses of 0 mean null. -#if !defined( nullptr ) - #define nullptr NULL -#endif - #if defined(_WIN32) #include <process.h> @@ -56,6 +45,8 @@ #else + #include <pthread.h> + #define LOKI_pthread_t \ pthread_t #define LOKI_pthread_create(handle,attr,func,arg) \ @@ -65,6 +56,19 @@ #endif + +using namespace ::std; + +#if !defined( NULL ) + #define NULL 0 +#endif + +// define nullptr even though new compilers will have this keyword just so we +// have a consistent and easy way of identifying which uses of 0 mean null. +#if !defined( nullptr ) + #define nullptr NULL +#endif + // ---------------------------------------------------------------------------- class Thread @@ -364,7 +368,10 @@ // ---------------------------------------------------------------------------- int main( int argc, const char * const argv[] ) -{ +{ + (void)argc; + (void)argv; + bool okay = true; cout << "Starting ThreadLocal tests." << endl; cout << "If any tests fail, or any assertions fail," << endl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 23:19:21
|
Revision: 1111 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1111&view=rev Author: rich_sposato Date: 2011-09-20 23:19:14 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Back to revision 1109. Accidentally checked in more files than I intended. Revision Links: -------------- http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1109&view=rev Modified Paths: -------------- trunk/Loki.workspace trunk/include/loki/StrongPtr.h trunk/include/loki/ThreadLocal.h trunk/include/loki/flex/flex_string_shell.h trunk/src/StrongPtr.cpp trunk/test/LevelMutex/LevelMutex.cbp trunk/test/LevelMutex/MultiThreadTests.cpp trunk/test/LevelMutex/ThreadPool.cpp trunk/test/LevelMutex/main.cpp trunk/test/LockingPtr/LockingPtr.cbp trunk/test/SmartPtr/SmartPtr.cbp trunk/test/SmartPtr/base.h trunk/test/SmartPtr/main.cpp trunk/test/SmartPtr/strong.cpp trunk/test/ThreadLocal/ThreadLocal.cbp trunk/test/ThreadLocal/main.cpp Modified: trunk/Loki.workspace =================================================================== --- trunk/Loki.workspace 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/Loki.workspace 2011-09-20 23:19:14 UTC (rev 1111) @@ -2,46 +2,46 @@ <CodeBlocks_workspace_file> <Workspace title="Workspace"> <Project filename="Loki.cbp" active="1" /> - <Project filename="test/CachedFactory/CachedFactory.cbp"> + <Project filename="test\CachedFactory\CachedFactory.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/Checker/Checker.cbp" /> - <Project filename="test/CheckReturn/CheckReturn.cbp" /> - <Project filename="test/DeletableSingleton/DeletableSingleton.cbp"> + <Project filename="test\Checker\Checker.cbp" /> + <Project filename="test\CheckReturn\CheckReturn.cbp" /> + <Project filename="test\DeletableSingleton\DeletableSingleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/Factory/Factory.cbp" /> - <Project filename="test/flex_string/flex_string.cbp" /> - <Project filename="test/Function/Function.cbp" /> - <Project filename="test/LevelMutex/LevelMutex.cbp"> + <Project filename="test\Factory\Factory.cbp" /> + <Project filename="test\flex_string\flex_string.cbp" /> + <Project filename="test\Function\Function.cbp" /> + <Project filename="test\LevelMutex\LevelMutex.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/LockingPtr/LockingPtr.cbp" /> - <Project filename="test/Longevity/Longevity.cbp" /> - <Project filename="test/OrderedStatic/OrderedStatic.cbp"> + <Project filename="test\LockingPtr\LockingPtr.cbp" /> + <Project filename="test\Longevity\Longevity.cbp" /> + <Project filename="test\OrderedStatic\OrderedStatic.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/Pimpl/Pimpl.cbp" /> - <Project filename="test/Register/Register.cbp" /> - <Project filename="test/RegressionTest/RegressionTest.cbp"> + <Project filename="test\Pimpl\Pimpl.cbp" /> + <Project filename="test\Register\Register.cbp" /> + <Project filename="test\RegressionTest\RegressionTest.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/SafeFormat/SafeFormat.cbp"> + <Project filename="test\SafeFormat\SafeFormat.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/ScopeGuard/ScopeGuard.cbp" /> - <Project filename="test/Singleton/Singleton.cbp"> + <Project filename="test\ScopeGuard\ScopeGuard.cbp" /> + <Project filename="test\Singleton\Singleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/SmallObj/SmallObj.cbp"> + <Project filename="test\SmallObj\SmallObj.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/SmallObj/DefaultAlloc.cbp" /> - <Project filename="test/SmartPtr/SmartPtr.cbp"> + <Project filename="test\SmallObj\DefaultAlloc.cbp" /> + <Project filename="test\SmartPtr\SmartPtr.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/Visitor/Visitor.cbp" /> - <Project filename="test/SafeBits/SafeBits.cbp" /> - <Project filename="test/ThreadLocal/ThreadLocal.cbp" /> + <Project filename="test\Visitor\Visitor.cbp" /> + <Project filename="test\SafeBits\SafeBits.cbp" /> + <Project filename="test\ThreadLocal\ThreadLocal.cbp" /> </Workspace> </CodeBlocks_workspace_file> Modified: trunk/include/loki/StrongPtr.h =================================================================== --- trunk/include/loki/StrongPtr.h 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/include/loki/StrongPtr.h 2011-09-20 23:19:14 UTC (rev 1111) @@ -85,10 +85,7 @@ /// If you write your own policy, you must implement these 3 functions: /// -# void static Delete( const P * p ) /// -# static P * Default( void ) -/// -# Default constructor. -/// -# Copy constructor. -/// -# Templated copy constructor. -/// -# void Swap( YourDeletePolicy & ) +/// -# void Swap( YourResetPolicy & ) /// /// \par ResetPolicy /// A reset policy tells the ReleaseAll and ResetAll functions whether they @@ -238,7 +235,46 @@ inline void Swap( DeleteSingle & ) {} }; +namespace Private +{ + //////////////////////////////////////////////////////////////////////////////// +/// \class DeleteArrayBase +/// +/// \ingroup StrongPointerDeleteGroup +/// Base class used only by the DeleteArray policy class. This stores the +/// number of elements in an array of shared objects. +//////////////////////////////////////////////////////////////////////////////// + +class DeleteArrayBase +{ +public: + + inline size_t GetArrayCount( void ) const { return m_itemCount; } + +protected: + + DeleteArrayBase( void ) : m_itemCount( 0 ) {} + + explicit DeleteArrayBase( size_t itemCount ) : m_itemCount( itemCount ) {} + + DeleteArrayBase( const DeleteArrayBase & that ) : m_itemCount( that.m_itemCount ) {} + + void Swap( DeleteArrayBase & rhs ); + + void OnInit( const void * p ) const; + + void OnCheckRange( size_t index ) const; + +private: + + size_t m_itemCount; + +}; + +} + +//////////////////////////////////////////////////////////////////////////////// /// \class DeleteArray /// /// \ingroup StrongPointerDeleteGroup @@ -2032,27 +2068,19 @@ return * GetPointer(); } - /** operator[] returns a reference to an modifiable object. If the index is greater than or - equal to the number of elements, the function will throw a std::out_of_range exception. - This only works with DeleteArray policy. Any other policy will cause a compiler error. - */ ReferenceType operator [] ( size_t index ) { + KP::OnDereference( GetPointer() ); + DP::OnCheckRange( index ); PointerType p = GetPointer(); - KP::OnDereference( p ); - DP::OnCheckRange( index ); return p[ index ]; } - /** operator[] returns a reference to a const object. If the index is greater than or - equal to the number of elements, the function will throw a std::out_of_range exception. - This only works with DeleteArray policy. Any other policy will cause a compiler error. - */ ConstReferenceType operator [] ( size_t index ) const { + KP::OnDereference( GetPointer() ); + DP::OnCheckRange( index ); ConstPointerType p = GetPointer(); - KP::OnDereference( p ); - DP::OnCheckRange( index ); return p[ index ]; } Modified: trunk/include/loki/ThreadLocal.h =================================================================== --- trunk/include/loki/ThreadLocal.h 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/include/loki/ThreadLocal.h 2011-09-20 23:19:14 UTC (rev 1111) @@ -28,29 +28,21 @@ // The __APPLE__ macro does not refer to a compiler, but to the Apple OSX operating system. #if defined( __APPLE__ ) #warning "GCC for Apple does not allow thread_local storage, so you can not use some parts of Loki." - #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #elif defined( __CYGWIN__ ) #if ( __GNUC__ <= 3 ) #warning "Older versions of GCC for Cygwin do not allow thread_local storage, so you can not use some parts of Loki." - #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #endif #elif ( __GNUC__ == 4 ) // GNU versions other than Cygwin. - #if ( __GNUC_MINOR__ < 4 ) - #warning "GCC versions before 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki." - #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE - #else - #warning "Versions 4.4 through 4.6 of GCC implemented thread_local storage for some platforms, but not others. Run ThreadLocal test project." + #if ( __GNUC_MINOR__ == 4 ) + #warning "GCC version 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki." + #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #endif #endif - -#elif defined( _MSC_VER ) - #if ( _MSC_VER < 1300 ) - #warning "Only Visual Studio versions 7.0 and after support thread local storage properly, so you can not use some parts of Loki." - #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE - #endif -#endif +#endif #if defined( LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE ) && !defined( LOKI_THREAD_LOCAL ) @@ -65,7 +57,11 @@ you can't use some parts of Loki. */ #if defined( _MSC_VER ) - #define LOKI_THREAD_LOCAL __declspec( thread ) + #if ( _MSC_VER >= 1300 ) + #define LOKI_THREAD_LOCAL __declspec( thread ) + #else + #error "Only Visual Studio versions 7.0 and after supported." + #endif #elif ( __GNUC__ ) #define LOKI_THREAD_LOCAL __thread Modified: trunk/include/loki/flex/flex_string_shell.h =================================================================== --- trunk/include/loki/flex/flex_string_shell.h 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/include/loki/flex/flex_string_shell.h 2011-09-20 23:19:14 UTC (rev 1111) @@ -1339,17 +1339,17 @@ typename flex_string<E, T, A, S>::value_type delim) { size_t nread = 0; - typename std::basic_istream<typename flex_string<E, T, A, S>::value_type, + typename basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>::sentry sentry(is, true); if (sentry) { - ::std::basic_streambuf<typename flex_string<E, T, A, S>::value_type, + basic_streambuf<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>* buf = is.rdbuf(); str.clear(); while (nread < str.max_size()) { int c1 = buf->sbumpc(); if (flex_string<E, T, A, S>::traits_type::eq_int_type(c1, flex_string<E, T, A, S>::traits_type::eof())) { - is.setstate(::std::ios_base::eofbit); + is.setstate(ios_base::eofbit); break; } else { @@ -1363,7 +1363,7 @@ } } if (nread == 0 || nread >= str.max_size()) - is.setstate(::std::ios_base::failbit); + is.setstate(ios_base::failbit); return is; } Modified: trunk/src/StrongPtr.cpp =================================================================== --- trunk/src/StrongPtr.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/src/StrongPtr.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -15,6 +15,9 @@ #include <loki/StrongPtr.h> +#include <stdexcept> +#include <string> + #include <memory.h> #ifdef DO_EXTRA_LOKI_TESTS #include <cassert> @@ -38,6 +41,45 @@ // ---------------------------------------------------------------------------- +void DeleteArrayBase::Swap( DeleteArrayBase & rhs ) +{ + assert( NULL != this ); + + const size_t temp = m_itemCount; + m_itemCount = rhs.m_itemCount; + rhs.m_itemCount = temp; +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnInit( const void * p ) const +{ + assert( NULL != this ); + if ( NULL == p ) + { + assert( 0 == m_itemCount ); + } + else + { + assert( 0 < m_itemCount ); + } +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnCheckRange( size_t index ) const +{ + assert( NULL != this ); + + if ( index < m_itemCount ) + return; + + const ::std::string message( "index out of range in ::Loki::DeleteArrayBase::OnCheckRange" ); + throw ::std::out_of_range( message ); +} + +// ---------------------------------------------------------------------------- + OneOwnerRefCountInfo::OneOwnerRefCountInfo( SingleOwnerRefCount * ptr ) : m_pointer( NULL ) , m_strongPtr( ptr ) Modified: trunk/test/LevelMutex/LevelMutex.cbp =================================================================== --- trunk/test/LevelMutex/LevelMutex.cbp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LevelMutex/LevelMutex.cbp 2011-09-20 23:19:14 UTC (rev 1111) @@ -6,24 +6,24 @@ <Option compiler="cygwin" /> <Build> <Target title="Debug_GCC"> - <Option output="obj/Debug_GCC/LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_GCC/" /> + <Option output="obj\Debug_GCC\LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> + <Add option="-W" /> <Add option="-g" /> - <Add option="-W" /> - <Add directory="../../include" /> - <Add directory="../../include/loki" /> + <Add directory="..\..\include" /> + <Add directory="..\..\include\loki" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki_D.a" /> - <Add library="/usr/lib/libpthread.so" /> + <Add library="..\..\lib\GCC\Loki_D.a" /> + <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj/Release_GCC/LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_GCC/" /> + <Option output="obj\Release_GCC\LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -31,33 +31,33 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include" /> - <Add directory="../../include/loki" /> + <Add directory="..\..\include" /> + <Add directory="..\..\include\loki" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki.a" /> - <Add library="/usr/lib/libpthread.so" /> + <Add library="..\..\lib\GCC\Loki.a" /> + <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="obj/Debug_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_Cygwin/" /> + <Option output="obj\Debug_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_Cygwin\" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="../../include" /> - <Add directory="../../include/loki" /> + <Add directory="..\..\include" /> + <Add directory="..\..\include\loki" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki_D.a" /> - <Add library="../../../PThreads/lib/pthreadVC2.lib" /> + <Add library="..\..\lib\Cygwin\Loki_D.a" /> + <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="obj/Release_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_Cygwin/" /> + <Option output="obj\Release_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_Cygwin\" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> @@ -65,12 +65,12 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include" /> - <Add directory="../../include/loki" /> + <Add directory="..\..\include" /> + <Add directory="..\..\include\loki" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki.a" /> - <Add library="../../../PThreads/lib/pthreadVC2.lib" /> + <Add library="..\..\lib\Cygwin\Loki.a" /> + <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> </Linker> </Target> </Build> Modified: trunk/test/LevelMutex/MultiThreadTests.cpp =================================================================== --- trunk/test/LevelMutex/MultiThreadTests.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LevelMutex/MultiThreadTests.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -4,9 +4,9 @@ // Copyright (c) 2008, 2009 Richard 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 @@ -22,7 +22,7 @@ #include "MultiThreadTests.hpp" #include <assert.h> -//#include <process.h> +#include <process.h> #include <stdlib.h> #include <time.h> @@ -239,8 +239,6 @@ void MultiThreadSimpleTest( void ) { - cout << "Starting MultiThreadSimpleTest." << endl; - Thing::Init( 0 ); const unsigned int threadCount = 5; ThreadPool pool( threadCount ); @@ -264,8 +262,6 @@ pool.JoinAll(); Thing::Destroy(); - - cout << "Finished MultiThreadSimpleTest." << endl; } // ---------------------------------------------------------------------------- @@ -303,17 +299,13 @@ void MultiThreadTryLockTest( void ) { - cout << "Starting MultiThreadTryLockTest." << endl; - static const unsigned int threadCount = 3; Thing::Init( 0 ); volatile Thing & thing = Thing::GetIt(); volatile SleepMutex & mutex = thing.GetMutex(); cout << endl << "Doing multi-threaded TryLock test. This test should not deadlock." << endl; - cout << "Press enter key to continue." << endl; - char theKey = 0; - cin.get( theKey ); + ::system( "pause" ); // First step is to lock the mutex in the main thread so no child thread // can ever lock it, change the value, or anything like that. MutexErrors::Type result = mutex.Lock(); @@ -321,46 +313,36 @@ bool okay = mutex.IsLockedByCurrentThread(); assert( okay ); thing.SetValue( threadCount ); - + ThreadPool pool( threadCount ); + for ( unsigned int ii = 0; ii < threadCount; ++ii ) { - ThreadPool pool( threadCount ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) - { - void * p = reinterpret_cast< void * >( ii ); - pool.Start( TryLockThread, p ); - } - pool.JoinAll(); + void * p = reinterpret_cast< void * >( ii ); + pool.Start( TryLockThread, p ); } + pool.JoinAll(); + const unsigned int value = thing.GetValue(); + assert( value == threadCount ); + result = mutex.Unlock(); + assert( MutexErrors::Success == result ); + okay = !mutex.IsLockedByCurrentThread(); + assert( okay ); + okay = !mutex.IsLocked(); + assert( okay ); - const unsigned int value = thing.GetValue(); - assert( value == threadCount ); - result = mutex.Unlock(); - assert( MutexErrors::Success == result ); - okay = !mutex.IsLockedByCurrentThread(); - assert( okay ); - okay = !mutex.IsLocked(); - assert( okay ); - Thing::Destroy(); - - cout << "Finished MultiThreadTryLockTest." << endl; } // ---------------------------------------------------------------------------- void MultiThreadReentrantTest( void ) { - cout << "Starting MultiThreadReentrantTest." << endl; - Thing::Init( 0 ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); ThreadPool pool( threadCount ); cout << endl << "Doing thread-safe value test. This test should pass and not deadlock." << endl; - cout << "Press enter key to continue." << endl; - char theKey = 0; - cin.get( theKey ); + ::system( "pause" ); for ( unsigned int ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); @@ -370,8 +352,7 @@ TestResults::GetIt()->OutputResults(); cout << endl << "Doing thread-unsafe value test. This test may fail." << endl; - cout << "Press enter key to continue." << endl; - cin.get( theKey ); + ::system( "pause" ); for ( unsigned int ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); @@ -382,8 +363,6 @@ TestResults::Destroy(); Thing::Destroy(); - - cout << "Finished MultiThreadReentrantTest." << endl; } // ---------------------------------------------------------------------------- @@ -667,8 +646,6 @@ void MultiThreadMultiLockTest( void ) { - cout << "Starting MultiThreadMultiLockTest." << endl; - Thing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -697,8 +674,6 @@ TestResults::Destroy(); Thing::DestroyPool(); - - cout << "Finished MultiThreadMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -833,8 +808,6 @@ void MultiThreadRandomMultiLockTest( void ) { - cout << "Starting MultiThreadRandomMultiLockTest." << endl; - Thing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -863,8 +836,6 @@ TestResults::Destroy(); Thing::DestroyPool(); - - cout << "Finished MultiThreadRandomMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -965,8 +936,6 @@ void MultiThreadHierarchySingleLockTest( void ) { - cout << "Starting MultiThreadHierarchySingleLockTest." << endl; - LevelThing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -995,8 +964,6 @@ TestResults::Destroy(); LevelThing::DestroyPool(); - - cout << "Finished MultiThreadHierarchySingleLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -1098,8 +1065,6 @@ void MultiThreadHierarchyMultiLockTest( void ) { - cout << "Starting MultiThreadHierarchyMultiLockTest." << endl; - MultiLevelPool::MakePool( 10, thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -1128,8 +1093,6 @@ TestResults::Destroy(); MultiLevelPool::DestroyPool(); - - cout << "Finished MultiThreadHierarchyMultiLockTest." << endl; } // ---------------------------------------------------------------------------- Modified: trunk/test/LevelMutex/ThreadPool.cpp =================================================================== --- trunk/test/LevelMutex/ThreadPool.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LevelMutex/ThreadPool.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -20,7 +20,7 @@ #include <assert.h> -//#include <process.h> +#include <process.h> #if !defined( _MSC_VER ) #include <unistd.h> // needed for the usleep function. #endif @@ -86,13 +86,11 @@ bool Thread::WaitForThread( void ) volatile { assert( IsValid( m_owner ) ); - const volatile Thread * current = Thread::GetCurrentThread(); if ( this == current ) return false; if ( m_status == Thread::Dead ) return false; - while ( this->m_status == Thread::Active ) { // Call the wait policy. @@ -102,8 +100,6 @@ ::usleep( 1000 ); #endif } - - m_status = Thread::Idle; return true; } Modified: trunk/test/LevelMutex/main.cpp =================================================================== --- trunk/test/LevelMutex/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LevelMutex/main.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -48,8 +48,6 @@ void SingleThreadSimpleTest( void ) { - cout << "Starting SingleThreadSimpleTest." << endl; - const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -173,8 +171,6 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); - - cout << "Finished SingleThreadSimpleTest." << endl; } // ---------------------------------------------------------------------------- @@ -182,8 +178,6 @@ void SingleThreadReentrantTest( void ) { - cout << "Starting SingleThreadReentrantTest." << endl; - const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -289,8 +283,6 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); - - cout << "Finished SingleThreadReentrantTest." << endl; } // ---------------------------------------------------------------------------- @@ -298,8 +290,6 @@ void SingleThreadSimpleMultiLockTest( void ) { - cout << "Starting SingleThreadSimpleMultiLockTest." << endl; - const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -491,8 +481,6 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); - - cout << "Finished SingleThreadSimpleMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -500,8 +488,6 @@ void SingleThreadExceptionTest( void ) { - cout << "Starting SingleThreadExceptionTest." << endl; - const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -650,8 +636,6 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); - - cout << "Finished SingleThreadExceptionTest." << endl; } // ---------------------------------------------------------------------------- @@ -676,7 +660,6 @@ MultiThreadSimpleTest(); MultiThreadTryLockTest(); - cout << "main 679" << endl; MultiThreadReentrantTest(); MultiThreadMultiLockTest(); MultiThreadRandomMultiLockTest(); Modified: trunk/test/LockingPtr/LockingPtr.cbp =================================================================== --- trunk/test/LockingPtr/LockingPtr.cbp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LockingPtr/LockingPtr.cbp 2011-09-20 23:19:14 UTC (rev 1111) @@ -3,27 +3,26 @@ <FileVersion major="1" minor="6" /> <Project> <Option title="LockingPtr" /> - <Option compiler="gcc" /> + <Option compiler="cygwin" /> <Build> <Target title="Debug_GCC"> - <Option output="obj/Debug_GCC/LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_GCC/" /> + <Option output="obj\Debug_GCC\LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> - <Add option="-g" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add option="-g" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki_D.a" /> - <Add library="/usr/lib/libpthread.so" /> + <Add library="..\..\lib\GCC\Loki_D.a" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj/Release_GCC/LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_GCC/" /> + <Option output="obj\Release_GCC\LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -31,44 +30,43 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki.a" /> - <Add library="/usr/lib/libpthread.so" /> + <Add library="..\..\lib\GCC\Loki.a" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="obj/Debug_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_Cygwin/" /> + <Option output="obj\Debug_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_Cygwin\" /> <Option type="1" /> - <Option compiler="gcc" /> + <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki_D.a" /> + <Add library="..\..\lib\Cygwin\Loki_D.a" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="obj/Release_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_Cygwin/" /> + <Option output="obj\Release_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_Cygwin\" /> <Option type="1" /> - <Option compiler="gcc" /> + <Option compiler="cygwin" /> <Compiler> <Add option="-fexpensive-optimizations" /> <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki.a" /> + <Add library="..\..\lib\Cygwin\Loki.a" /> </Linker> </Target> </Build> Modified: trunk/test/SmartPtr/SmartPtr.cbp =================================================================== --- trunk/test/SmartPtr/SmartPtr.cbp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/SmartPtr/SmartPtr.cbp 2011-09-20 23:19:14 UTC (rev 1111) @@ -6,25 +6,23 @@ <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="bin/Debug_GCC/SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_GCC/" /> + <Option output="bin\Debug_GCC\SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> - <Add option="-g" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add option="-g" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki_D.a" /> - <Add library="/usr/lib/libpthread.so" /> - <Add library="/usr/lib/libc.so" /> + <Add library="..\..\lib\GCC\Loki_D.a" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="bin/Release_GCC/SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_GCC/" /> + <Option output="bin\Release_GCC\SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -32,33 +30,31 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki.a" /> - <Add library="/usr/lib/libpthread.so" /> - <Add library="/usr/lib/libc.so" /> + <Add library="..\..\lib\GCC\Loki.a" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="bin/Debug_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_Cygwin/" /> + <Option output="bin\Debug_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_Cygwin\" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki_D.a" /> + <Add library="..\..\lib\Cygwin\Loki_D.a" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="bin/Release_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_Cygwin/" /> + <Option output="bin\Release_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_Cygwin\" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> @@ -66,11 +62,11 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki.a" /> + <Add library="..\..\lib\Cygwin\Loki.a" /> </Linker> </Target> </Build> @@ -78,7 +74,6 @@ <Unit filename="base.h"> <Option target="<{~None~}>" /> </Unit> - <Unit filename="colvin_gibbons_trick.cpp" /> <Unit filename="main.cpp" /> <Unit filename="strong.cpp" /> <Extensions> Modified: trunk/test/SmartPtr/base.h =================================================================== --- trunk/test/SmartPtr/base.h 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/SmartPtr/base.h 2011-09-20 23:19:14 UTC (rev 1111) @@ -73,11 +73,10 @@ return s_destructions; } -protected: - BaseClass( const BaseClass & that ) : m_refCount( that.m_refCount ) {} - private: /// Not implemented. + BaseClass( const BaseClass & ); + /// Not implemented. BaseClass & operator = ( const BaseClass & ); static unsigned int s_constructions; @@ -111,45 +110,7 @@ } }; -// ---------------------------------------------------------------------------- -/** @class Feline - The feline family of classes are to test dynamic_cast. Also used to test - pointers to arrays of objects. - */ -class Feline : public BaseClass -{ -public: - virtual ~Feline() {} - virtual Feline * Clone( void ) const = 0; -}; - -class Lion : public Feline -{ -public: - virtual ~Lion() {} - virtual Lion * Clone( void ) const { return new Lion( *this ); } -}; - -class Tiger : public Feline -{ -public: - Tiger( void ) : m_stripes( 100 ) {} - virtual ~Tiger() {} - virtual Tiger * Clone( void ) const { return new Tiger( *this ); } - unsigned int GetStripes( void ) const { return m_stripes; } - void SetStripes( unsigned int s ) { m_stripes = s; } -private: - unsigned int m_stripes; -}; - -class Dog -{ -public: - virtual ~Dog() {} - virtual Dog * Clone( void ) const { return new Dog( *this ); } -}; - - // ---------------------------------------------------------------------------- /** @class MimicCOM Acts like a COM object by having an intrusive ref count. Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/SmartPtr/main.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -1205,6 +1205,75 @@ // ---------------------------------------------------------------------------- +namespace +{ + + class Feline + { + public: + + static inline bool AllDestroyed( void ) + { + return ( s_constructions == s_destructions ); + } + + static inline bool ExtraConstructions( void ) + { + return ( s_constructions > s_destructions ); + } + + static inline bool ExtraDestructions( void ) + { + return ( s_constructions < s_destructions ); + } + + static inline unsigned int GetCtorCount( void ) + { + return s_constructions; + } + + static inline unsigned int GetDtorCount( void ) + { + return s_destructions; + } + + Feline( void ) { s_constructions++; } + virtual ~Feline() { s_destructions++; } + virtual Feline * Clone( void ) const = 0; + + private: + static unsigned int s_constructions; + static unsigned int s_destructions; + }; + + unsigned int Feline::s_constructions = 0; + unsigned int Feline::s_destructions = 0; + + class Tiger : public Feline + { + public: + virtual ~Tiger() {} + virtual Tiger * Clone( void ) const { return new Tiger( *this ); } + }; + + class Lion : public Feline + { + public: + virtual ~Lion() {} + virtual Lion * Clone( void ) const { return new Lion( *this ); } + }; + + class Dog + { + public: + virtual ~Dog() {} + virtual Dog * Clone( void ) const { return new Dog( *this ); } + }; + +} + +// ---------------------------------------------------------------------------- + void DoSmartPtrDynamicCastTests( void ) { cout << "Starting DoSmartPtrDynamicCastTests." << endl; @@ -1290,9 +1359,9 @@ assert( !pDog ); } - assert( BaseClass::AllDestroyed() ); - assert( !BaseClass::ExtraConstructions() ); - assert( !BaseClass::ExtraDestructions() ); + assert( Feline::AllDestroyed() ); + assert( !Feline::ExtraConstructions() ); + assert( !Feline::ExtraDestructions() ); cout << "Finished DoSmartPtrDynamicCastTests." << endl; } @@ -1449,161 +1518,6 @@ // ---------------------------------------------------------------------------- -/// Use these typedefs to test DeleteArray policy. - -typedef Loki::SmartPtr< Tiger, RefCounted, DisallowConversion, - AssertCheck, ArrayStorage, DontPropagateConst > - TigerArray_RefCounted_ptr; - -typedef Loki::SmartPtr< Tiger, RefLinked, DisallowConversion, - AssertCheck, ArrayStorage, DontPropagateConst > - TigerArray_2RefLinks_ptr; - -// ---------------------------------------------------------------------------- - -void DoSmartArrayTests( void ) -{ - cout << "Starting DoSmartArrayTests." << endl; - - { - // test default construction. - TigerArray_RefCounted_ptr sp1; - assert( !sp1 ); - assert( 0 == sp1.GetArrayCount() ); - - // test assignment. - sp1.Assign( new Tiger[ 8 ], 8 ); - assert( sp1 ); - assert( 8 == sp1.GetArrayCount() ); - sp1[ 0 ].SetStripes( 8 ); - sp1[ 1 ].SetStripes( 16 ); - sp1[ 2 ].SetStripes( 24 ); - sp1[ 3 ].SetStripes( 32 ); - sp1[ 4 ].SetStripes( 40); - sp1[ 5 ].SetStripes( 48 ); - sp1[ 6 ].SetStripes( 56 ); - sp1[ 7 ].SetStripes( 64 ); - - // test initialization construction. - TigerArray_RefCounted_ptr sp2( new Tiger[ 4 ], 4 ); - assert( sp2 ); - assert( 4 == sp2.GetArrayCount() ); - sp2[ 0 ].SetStripes( 5 ); - sp2[ 1 ].SetStripes( 10 ); - sp2[ 2 ].SetStripes( 15 ); - sp2[ 3 ].SetStripes( 20 ); - - // test range checking. - try - { - Tiger & p4 = sp2[ 4 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - // test range checking. - try - { - Tiger & p8 = sp1[ 8 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - // test swap. - sp2.Swap( sp1 ); - assert( sp1 ); - assert( sp2 ); - // test checking of item count. - assert( 4 == sp1.GetArrayCount() ); - assert( 8 == sp2.GetArrayCount() ); - - // test that operator[] returns reference to - assert( 5 == sp1[ 0 ].GetStripes() ); - assert( 10 == sp1[ 1 ].GetStripes() ); - assert( 15 == sp1[ 2 ].GetStripes() ); - assert( 20 == sp1[ 3 ].GetStripes() ); - assert( 8 == sp2[ 0 ].GetStripes() ); - assert( 16 == sp2[ 1 ].GetStripes() ); - assert( 24 == sp2[ 2 ].GetStripes() ); - assert( 32 == sp2[ 3 ].GetStripes() ); - assert( 40 == sp2[ 4 ].GetStripes() ); - assert( 48 == sp2[ 5 ].GetStripes() ); - assert( 56 == sp2[ 6 ].GetStripes() ); - assert( 64 == sp2[ 7 ].GetStripes() ); - - try - { - Tiger & p4 = sp1[ 4 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - try - { - Tiger & p8 = sp2[ 8 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - const TigerArray_RefCounted_ptr sp3( sp1 ); - assert( sp3 == sp1 ); - assert( sp3.GetArrayCount() == sp1.GetArrayCount() ); - try - { - const Tiger & p4 = sp3[ 4 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - const TigerArray_RefCounted_ptr sp5( sp2 ); - assert( sp5 == sp2 ); - assert( sp5.GetArrayCount() == sp2.GetArrayCount() ); - try - { - const Tiger & p8 = sp5[ 8 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - sp2 = sp1; - assert( sp1 == sp2 ); - assert( sp3 == sp2 ); - assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); - assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); - assert( sp1 != sp5 ); - assert( sp2 != sp5 ); - assert( sp3 != sp5 ); - assert( sp1.GetArrayCount() != sp5.GetArrayCount() ); - assert( sp2.GetArrayCount() != sp5.GetArrayCount() ); - assert( sp3.GetArrayCount() != sp5.GetArrayCount() ); - } - - assert( BaseClass::AllDestroyed() ); - assert( !BaseClass::ExtraConstructions() ); - assert( !BaseClass::ExtraDestructions() ); - cout << "Finished DoSmartArrayTests." << endl; -} - -// ---------------------------------------------------------------------------- - int main( int argc, const char * argv[] ) { bool doThreadTest = false; @@ -1642,7 +1556,6 @@ DoSmartPtrDynamicCastTests(); DoStrongPtrDynamicCastTests(); DoStrongArrayTests(); - DoSmartArrayTests(); #if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING) if ( doThreadTest ) Modified: trunk/test/SmartPtr/strong.cpp =================================================================== --- trunk/test/SmartPtr/strong.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/SmartPtr/strong.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -1778,6 +1778,42 @@ // ---------------------------------------------------------------------------- +namespace +{ + + class Feline : public BaseClass + { + public: + virtual ~Feline() {} + }; + + class Lion : public Feline + { + public: + virtual ~Lion() {} + }; + + class Tiger : public Feline + { + public: + Tiger( void ) : m_stripes( 100 ) {} + virtual ~Tiger() {} + unsigned int GetStripes( void ) const { return m_stripes; } + void SetStripes( unsigned int s ) { m_stripes = s; } + private: + unsigned int m_stripes; + }; + + class Dog + { + public: + virtual ~Dog() {} + }; + +} + +// ---------------------------------------------------------------------------- + void DoStrongPtrDynamicCastTests( void ) { typedef ::Loki::StrongPtr< Feline, true, ::Loki::TwoRefCounts > FelineCountPtr; Modified: trunk/test/ThreadLocal/ThreadLocal.cbp =================================================================== --- trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-20 23:19:14 UTC (rev 1111) @@ -7,37 +7,28 @@ <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="obj/Debug_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_GCC/" /> + <Option output="obj\Debug_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> <Add option="-Wmain" /> <Add option="-pedantic" /> - <Add option="-g" /> <Add option="-W" /> - <Add directory="../../include" /> + <Add option="-g" /> + <Add directory="..\..\include" /> </Compiler> - <Linker> - <Add library="/usr/lib/libpthread.so" /> - <Add library="/usr/lib/libc.so" /> - </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj/Release_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_GCC/" /> + <Option output="obj\Release_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> <Add option="-O2" /> - <Add option="-Wmain" /> - <Add option="-pedantic" /> - <Add option="-W" /> - <Add directory="../../include" /> </Compiler> <Linker> <Add option="-s" /> - <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> </Build> @@ -50,7 +41,6 @@ <code_completion /> <debugger /> <lib_finder disable_auto="1" /> - <envvars /> </Extensions> </Project> </CodeBlocks_project_file> Modified: trunk/test/ThreadLocal/main.cpp =================================================================== --- trunk/test/ThreadLocal/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/ThreadLocal/main.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -26,8 +26,19 @@ #include <sstream> #include <iostream> -#include <stdlib.h> +using namespace ::std; + +#if !defined( NULL ) + #define NULL 0 +#endif + +// define nullptr even though new compilers will have this keyword just so we +// have a consistent and easy way of identifying which uses of 0 mean null. +#if !defined( nullptr ) + #define nullptr NULL +#endif + #if defined(_WIN32) #include <process.h> @@ -45,8 +56,6 @@ #else - #include <pthread.h> - #define LOKI_pthread_t \ pthread_t #define LOKI_pthread_create(handle,attr,func,arg) \ @@ -56,19 +65,6 @@ #endif - -using namespace ::std; - -#if !defined( NULL ) - #define NULL 0 -#endif - -// define nullptr even though new compilers will have this keyword just so we -// have a consistent and easy way of identifying which uses of 0 mean null. -#if !defined( nullptr ) - #define nullptr NULL -#endif - // ---------------------------------------------------------------------------- class Thread @@ -368,10 +364,7 @@ // ---------------------------------------------------------------------------- int main( int argc, const char * const argv[] ) -{ - (void)argc; - (void)argv; - +{ bool okay = true; cout << "Starting ThreadLocal tests." << endl; cout << "If any tests fail, or any assertions fail," << endl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-04 23:42:54
|
Revision: 1138 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1138&view=rev Author: rich_sposato Date: 2011-10-04 23:42:48 +0000 (Tue, 04 Oct 2011) Log Message: ----------- Fixed bug 2694067. Modified Paths: -------------- trunk/include/loki/SafeFormat.h trunk/src/SafeFormat.cpp Modified: trunk/include/loki/SafeFormat.h =================================================================== --- trunk/include/loki/SafeFormat.h 2011-10-04 20:48:36 UTC (rev 1137) +++ trunk/include/loki/SafeFormat.h 2011-10-04 23:42:48 UTC (rev 1138) @@ -100,6 +100,21 @@ template <class Device, class Char> struct PrintfState { + + /** This constructor exists only to convert a PrintfState for one device type into a + PrintfState for another device type. It is not for public use. + */ + template < class Device2 > + PrintfState( Device2 & dev, const Char * format, size_t width, size_t prec, + unsigned int flags, LOKI_SAFEFORMAT_SIGNED_LONG result ) + : device_( dev ) + , format_( format ) + , width_( width ) + , prec_( prec ) + , flags_( flags ) + , result_( result ) { + } + PrintfState(Device dev, const Char * format) : device_(dev) , format_(format) @@ -113,6 +128,15 @@ ~PrintfState() { } + /** This function converts a PrintfState for one device type into a PrintfState for + another device type. It is not for public use. + */ + template < class Device2 > + PrintfState< Device2, Char > ChangeDevice( Device2 & device ) const + { + return PrintfState< Device2, Char >( device, format_, width_, prec_, flags_, result_ ); + } + #define LOKI_PRINTF_STATE_FORWARD(type) \ PrintfState& operator()(type par) {\ return (*this)(static_cast< LOKI_SAFEFORMAT_UNSIGNED_LONG >(par)); \ Modified: trunk/src/SafeFormat.cpp =================================================================== --- trunk/src/SafeFormat.cpp 2011-10-04 20:48:36 UTC (rev 1137) +++ trunk/src/SafeFormat.cpp 2011-10-04 23:42:48 UTC (rev 1138) @@ -66,27 +66,51 @@ PrintfState<std::FILE*, char> Printf(const char* format) { - return PrintfState<std::FILE*, char>(stdout, format); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format ); + ::std::fwrite( buffer.c_str(), 1, buffer.size(), stdout ); + PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( stdout ); + return printState2; } PrintfState<std::FILE*, char> Printf(const std::string& format) { - return PrintfState<std::FILE*, char>(stdout, format.c_str()); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format.c_str() ); + ::std::fwrite( buffer.c_str(), 1, buffer.size(), stdout ); + PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( stdout ); + return printState2; } PrintfState<std::FILE*, char> FPrintf(std::FILE* f, const char* format) { - return PrintfState<std::FILE*, char>(f, format); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format ); + ::std::fwrite( buffer.c_str(), 1, buffer.size(), f ); + PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( f ); + return printState2; } PrintfState<std::FILE*, char> FPrintf(std::FILE* f, const std::string& format) { - return PrintfState<std::FILE*, char>(f, format.c_str()); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format.c_str() ); + ::std::fwrite( buffer.c_str(), 1, buffer.size(), f ); + PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( f ); + return printState2; } PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const char* format) { - return PrintfState<std::ostream&, char>(f, format); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format ); + f.write( buffer.c_str(), buffer.size() ); + PrintfState< ::std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( f ); + return printState2; } PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const std::string& format) { - return PrintfState<std::ostream&, char>(f, format.c_str()); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format.c_str() ); + f.write( buffer.c_str(), buffer.size() ); + PrintfState< std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( f ); + return printState2; } PrintfState<std::string&, char> SPrintf(std::string& s, const char* format) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-21 23:09:55
|
Revision: 1160 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1160&view=rev Author: rich_sposato Date: 2011-10-21 23:09:48 +0000 (Fri, 21 Oct 2011) Log Message: ----------- Added functions that print directly to cout. Modified Paths: -------------- trunk/include/loki/SafeFormat.h trunk/src/SafeFormat.cpp Modified: trunk/include/loki/SafeFormat.h =================================================================== --- trunk/include/loki/SafeFormat.h 2011-10-20 07:25:44 UTC (rev 1159) +++ trunk/include/loki/SafeFormat.h 2011-10-21 23:09:48 UTC (rev 1160) @@ -605,7 +605,15 @@ LOKI_EXPORT PrintfState<std::FILE*, char> FPrintf(std::FILE* f, const std::string& format); + /// Prints to cout. LOKI_EXPORT + PrintfState<std::ostream&, char> FPrintf( const char * format ); + + /// Prints to cout. + LOKI_EXPORT + PrintfState<std::ostream&, char> FPrintf( const std::string & format ); + + LOKI_EXPORT PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const char* format); LOKI_EXPORT Modified: trunk/src/SafeFormat.cpp =================================================================== --- trunk/src/SafeFormat.cpp 2011-10-20 07:25:44 UTC (rev 1159) +++ trunk/src/SafeFormat.cpp 2011-10-21 23:09:48 UTC (rev 1160) @@ -99,6 +99,22 @@ return printState2; } + PrintfState< std::ostream &, char > FPrintf( const char * format ) { + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format ); + ::std::cout << buffer.c_str(); + PrintfState< ::std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( ::std::cout ); + return printState2; + } + + PrintfState< std::ostream &, char > FPrintf( const std::string & format ) { + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format.c_str() ); + ::std::cout << buffer.c_str(); + PrintfState< std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( ::std::cout ); + return printState2; + } + PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const char* format) { ::std::string buffer; const PrintfState< ::std::string &, char > state1( buffer, format ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2012-04-02 06:05:11
|
Revision: 1180 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1180&view=rev Author: rich_sposato Date: 2012-04-02 06:05:04 +0000 (Mon, 02 Apr 2012) Log Message: ----------- Overloaded functions for volatile to make better use of Memento and Loki::Checker. Modified Paths: -------------- trunk/include/loki/LevelMutex.h trunk/src/LevelMutex.cpp Modified: trunk/include/loki/LevelMutex.h =================================================================== --- trunk/include/loki/LevelMutex.h 2012-04-02 06:01:51 UTC (rev 1179) +++ trunk/include/loki/LevelMutex.h 2012-04-02 06:05:04 UTC (rev 1180) @@ -272,11 +272,15 @@ { public: - explicit Memento( const volatile LevelMutexInfo & mutex ); + explicit Memento( const LevelMutexInfo & mutex ); - bool operator == ( const volatile LevelMutexInfo & mutex ) const; + bool operator == ( const LevelMutexInfo & mutex ) const; private: + + /// Copy-assignment operator is not implemented. + Memento & operator = ( const Memento & ); + /// Level of this mutex. const unsigned int m_level; @@ -295,7 +299,7 @@ exception. The checkers only get used in debug builds, and get optimized away in release builds. */ - typedef ::Loki::CheckFor< volatile LevelMutexInfo, Memento > CheckFor; + typedef ::Loki::CheckFor< const LevelMutexInfo, Memento > CheckFor; /** @class MutexUndoer Undoes actions by MultiLock if an exception occurs. It keeps track of @@ -362,13 +366,13 @@ /** Returns true if no class invariant broken, otherwise asserts. This function only gets called in debug builds. */ - bool IsValid( void ) const; + bool IsValid2( void ) const; /// Returns true if all pre-conditions for PostLock function are valid. - bool PostLockValidator( void ) const volatile; + bool PostLockValidator( void ) const; /// Returns true if all pre-conditions for PreUnlock function are valid. - bool PreUnlockValidator( void ) const volatile; + bool PreUnlockValidator( void ) const; private: @@ -395,16 +399,22 @@ /// Called only by MultiUnlock to unlock each particular mutex within a container. virtual MutexErrors::Type UnlockThis( void ) volatile = 0; + void PostLock( void ); + /** The actual implementation of IsLockedByCurrentThread. This does not do any invariant checking because the functions which call it already have. */ bool IsLockedByCurrentThreadImpl( void ) const volatile; + bool IsLockedByCurrentThreadImpl( void ) const; + /** Does just the opposite of IsLockedByCurrentThread. Called as a post-condition check by another function. */ bool IsNotLockedByCurrentThread( void ) const volatile; + bool IsNotLockedByCurrentThread( void ) const; + /// Pointer to singly-linked list of mutexes locked by the current thread. static LOKI_THREAD_LOCAL volatile LevelMutexInfo * s_currentMutex; Modified: trunk/src/LevelMutex.cpp =================================================================== --- trunk/src/LevelMutex.cpp 2012-04-02 06:01:51 UTC (rev 1179) +++ trunk/src/LevelMutex.cpp 2012-04-02 06:05:04 UTC (rev 1180) @@ -232,7 +232,7 @@ // ---------------------------------------------------------------------------- -LevelMutexInfo::Memento::Memento( const volatile LevelMutexInfo & mutex ) : +LevelMutexInfo::Memento::Memento( const LevelMutexInfo & mutex ) : m_level( mutex.m_level ), m_count( mutex.m_count ), m_previous( mutex.m_previous ), @@ -243,7 +243,7 @@ // ---------------------------------------------------------------------------- -bool LevelMutexInfo::Memento::operator == ( const volatile LevelMutexInfo & mutex ) const +bool LevelMutexInfo::Memento::operator == ( const LevelMutexInfo & mutex ) const { assert( this != nullptr ); @@ -594,6 +594,14 @@ bool LevelMutexInfo::IsValid( void ) const volatile { + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); + return pThis->IsValid2(); +} + +// ---------------------------------------------------------------------------- + +bool LevelMutexInfo::IsValid2( void ) const +{ assert( nullptr != this ); assert( LevelMutexInfo::UnlockedLevel != m_level ); assert( m_previous != this ); @@ -604,14 +612,6 @@ // ---------------------------------------------------------------------------- -bool LevelMutexInfo::IsValid( void ) const -{ - const volatile LevelMutexInfo * pThis = const_cast< const volatile LevelMutexInfo * >( this ); - return pThis->IsValid(); -} - -// ---------------------------------------------------------------------------- - void LevelMutexInfo::IncrementCount( void ) volatile { assert( IsValid() ); @@ -636,7 +636,8 @@ // gets called by various functions that are called to clean up after an exception // is thrown LOKI_MUTEX_DEBUG_CODE( - CheckFor::NoChange checker( this, &LevelMutexInfo::IsValid ); + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); + CheckFor::NoChange checker( pThis, &LevelMutexInfo::IsValid2 ); (void)checker; ) return IsLockedByCurrentThreadImpl(); @@ -646,6 +647,14 @@ bool LevelMutexInfo::IsLockedByCurrentThreadImpl( void ) const volatile { + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); + return pThis->IsLockedByCurrentThreadImpl(); +} + +// ---------------------------------------------------------------------------- + +bool LevelMutexInfo::IsLockedByCurrentThreadImpl( void ) const +{ if ( !IsLocked() ) return false; const volatile LevelMutexInfo * mutex = s_currentMutex; @@ -681,7 +690,8 @@ bool LevelMutexInfo::IsRecentLock( void ) const volatile { LOKI_MUTEX_DEBUG_CODE( - CheckFor::NoThrowOrChange checker( this, &LevelMutexInfo::IsValid ); + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); + CheckFor::NoThrowOrChange checker( pThis, &LevelMutexInfo::IsValid2 ); (void)checker; ) @@ -705,7 +715,8 @@ bool LevelMutexInfo::IsRecentLock( std::size_t count ) const volatile { LOKI_MUTEX_DEBUG_CODE( - CheckFor::NoThrowOrChange checker( this, &LevelMutexInfo::IsValid ); + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); + CheckFor::NoThrowOrChange checker( pThis, &LevelMutexInfo::IsValid2 ); (void)checker; ) @@ -728,7 +739,8 @@ bool LevelMutexInfo::IsLockedByAnotherThread( void ) const volatile { LOKI_MUTEX_DEBUG_CODE( - CheckFor::NoThrowOrChange checker( this, &LevelMutexInfo::IsValid ); + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); + CheckFor::NoThrowOrChange checker( pThis, &LevelMutexInfo::IsValid2 ); (void)checker; ) @@ -743,7 +755,7 @@ // ---------------------------------------------------------------------------- -bool LevelMutexInfo::PostLockValidator( void ) const volatile +bool LevelMutexInfo::PostLockValidator( void ) const { assert( 0 == m_count ); assert( nullptr == m_previous ); @@ -757,8 +769,17 @@ void LevelMutexInfo::PostLock( void ) volatile { + LevelMutexInfo * pThis = const_cast< LevelMutexInfo * >( this ); + pThis->PostLock(); +} + +// ---------------------------------------------------------------------------- + +void LevelMutexInfo::PostLock( void ) +{ LOKI_MUTEX_DEBUG_CODE( - CheckFor::NoThrow checker( this, &LevelMutexInfo::IsValid, + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); + CheckFor::NoThrow checker( pThis, &LevelMutexInfo::IsValid2, &LevelMutexInfo::PostLockValidator, &LevelMutexInfo::IsLockedByCurrentThreadImpl ); (void)checker; ) @@ -775,7 +796,7 @@ // ---------------------------------------------------------------------------- -bool LevelMutexInfo::PreUnlockValidator( void ) const volatile +bool LevelMutexInfo::PreUnlockValidator( void ) const { assert( 1 == m_count ); assert( nullptr != s_currentMutex ); @@ -790,9 +811,10 @@ void LevelMutexInfo::PreUnlock( void ) volatile { LOKI_MUTEX_DEBUG_CODE( + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); // This must use CheckFor::Invariants instead of CheckFor::NoThrow because the // function gets called when MultiLock has to clean up after an exception. - CheckFor::Invariants checker( this, &LevelMutexInfo::IsValid, + CheckFor::Invariants checker( pThis, &LevelMutexInfo::IsValid2, &LevelMutexInfo::PreUnlockValidator, &LevelMutexInfo::IsNotLockedByCurrentThread ); (void)checker; ) @@ -812,7 +834,8 @@ MutexErrors::Type LevelMutexInfo::PreLockCheck( bool forTryLock ) volatile { LOKI_MUTEX_DEBUG_CODE( - CheckFor::NoThrow checker( this, &LevelMutexInfo::IsValid ); + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); + CheckFor::NoThrow checker( pThis, &LevelMutexInfo::IsValid2 ); (void)checker; ) @@ -849,7 +872,8 @@ MutexErrors::Type LevelMutexInfo::PreUnlockCheck( void ) volatile { LOKI_MUTEX_DEBUG_CODE( - CheckFor::NoThrow checker( this, &LevelMutexInfo::IsValid ); + const LevelMutexInfo * pThis = const_cast< const LevelMutexInfo * >( this ); + CheckFor::NoThrow checker( pThis, &LevelMutexInfo::IsValid2 ); (void)checker; ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2013-06-24 06:10:53
|
Revision: 1190 http://sourceforge.net/p/loki-lib/code/1190 Author: rich_sposato Date: 2013-06-24 06:10:50 +0000 (Mon, 24 Jun 2013) Log Message: ----------- Minor changes to remove compiler warnings. Modified Paths: -------------- trunk/include/loki/SmartAssert.hpp trunk/src/SmartAssert.cpp Modified: trunk/include/loki/SmartAssert.hpp =================================================================== --- trunk/include/loki/SmartAssert.hpp 2013-06-24 06:09:34 UTC (rev 1189) +++ trunk/include/loki/SmartAssert.hpp 2013-06-24 06:10:50 UTC (rev 1190) @@ -236,7 +236,7 @@ VoidPtr, Float, Double, - LongDouble, + LongDouble }; static const char * GetName( DataTypeTag tag ); Modified: trunk/src/SmartAssert.cpp =================================================================== --- trunk/src/SmartAssert.cpp 2013-06-24 06:09:34 UTC (rev 1189) +++ trunk/src/SmartAssert.cpp 2013-06-24 06:10:50 UTC (rev 1190) @@ -524,4 +524,4 @@ #pragma warning( pop ) #endif -}; // end namespace +} // end namespace This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |