From ca6a94ac976a98e40d2dcfdf1315f09af79c1b96 Mon Sep 17 00:00:00 2001 From: rich_sposato Date: Tue, 20 Sep 2011 23:19:14 +0000 Subject: [PATCH] Back to revision 1109. Accidentally checked in more files than I intended. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1111 7ec92016-0320-0410-acc4-a06ded1c099a --- Loki.workspace | 46 ++--- include/loki/StrongPtr.h | 60 +++++-- include/loki/ThreadLocal.h | 26 ++- include/loki/flex/flex_string_shell.h | 8 +- src/StrongPtr.cpp | 42 +++++ test/LevelMutex/LevelMutex.cbp | 50 +++--- test/LevelMutex/MultiThreadTests.cpp | 77 +++------ test/LevelMutex/ThreadPool.cpp | 6 +- test/LevelMutex/main.cpp | 17 -- test/LockingPtr/LockingPtr.cbp | 50 +++--- test/SmartPtr/SmartPtr.cbp | 47 +++--- test/SmartPtr/base.h | 43 +---- test/SmartPtr/main.cpp | 231 ++++++++------------------ test/SmartPtr/strong.cpp | 36 ++++ test/ThreadLocal/ThreadLocal.cbp | 22 +-- test/ThreadLocal/main.cpp | 33 ++-- 16 files changed, 344 insertions(+), 450 deletions(-) diff --git a/Loki.workspace b/Loki.workspace index 52d4ab1..1a22fb4 100644 --- a/Loki.workspace +++ b/Loki.workspace @@ -2,46 +2,46 @@ - + - - - + + + - - - - + + + + - - - + + + - - - + + + - + - - + + - + - - + + - - - + + + diff --git a/include/loki/StrongPtr.h b/include/loki/StrongPtr.h index 4624272..37efb57 100644 --- a/include/loki/StrongPtr.h +++ b/include/loki/StrongPtr.h @@ -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,6 +235,45 @@ protected: 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 /// @@ -2032,27 +2068,19 @@ public: 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 ) { - PointerType p = GetPointer(); - KP::OnDereference( p ); + KP::OnDereference( GetPointer() ); DP::OnCheckRange( index ); + PointerType p = GetPointer(); 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 = GetPointer(); - KP::OnDereference( p ); + KP::OnDereference( GetPointer() ); DP::OnCheckRange( index ); + ConstPointerType p = GetPointer(); return p[ index ]; } diff --git a/include/loki/ThreadLocal.h b/include/loki/ThreadLocal.h index d9936d8..f03a87f 100644 --- a/include/loki/ThreadLocal.h +++ b/include/loki/ThreadLocal.h @@ -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 diff --git a/include/loki/flex/flex_string_shell.h b/include/loki/flex/flex_string_shell.h index 63c73b3..ecdfb7b 100644 --- a/include/loki/flex/flex_string_shell.h +++ b/include/loki/flex/flex_string_shell.h @@ -1339,17 +1339,17 @@ getline( typename flex_string::value_type delim) { size_t nread = 0; - typename std::basic_istream::value_type, + typename basic_istream::value_type, typename flex_string::traits_type>::sentry sentry(is, true); if (sentry) { - ::std::basic_streambuf::value_type, + basic_streambuf::value_type, typename flex_string::traits_type>* buf = is.rdbuf(); str.clear(); while (nread < str.max_size()) { int c1 = buf->sbumpc(); if (flex_string::traits_type::eq_int_type(c1, flex_string::traits_type::eof())) { - is.setstate(::std::ios_base::eofbit); + is.setstate(ios_base::eofbit); break; } else { @@ -1363,7 +1363,7 @@ getline( } } if (nread == 0 || nread >= str.max_size()) - is.setstate(::std::ios_base::failbit); + is.setstate(ios_base::failbit); return is; } diff --git a/src/StrongPtr.cpp b/src/StrongPtr.cpp index 1f3b5c5..cdabcb0 100644 --- a/src/StrongPtr.cpp +++ b/src/StrongPtr.cpp @@ -15,6 +15,9 @@ #include +#include +#include + #include #ifdef DO_EXTRA_LOKI_TESTS #include @@ -38,6 +41,45 @@ namespace Private // ---------------------------------------------------------------------------- +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 ) diff --git a/test/LevelMutex/LevelMutex.cbp b/test/LevelMutex/LevelMutex.cbp index a81ea37..a5c37a8 100644 --- a/test/LevelMutex/LevelMutex.cbp +++ b/test/LevelMutex/LevelMutex.cbp @@ -6,24 +6,24 @@