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
This commit is contained in:
parent
16094ffe39
commit
ca6a94ac97
16 changed files with 344 additions and 450 deletions
|
@ -2,46 +2,46 @@
|
||||||
<CodeBlocks_workspace_file>
|
<CodeBlocks_workspace_file>
|
||||||
<Workspace title="Workspace">
|
<Workspace title="Workspace">
|
||||||
<Project filename="Loki.cbp" active="1" />
|
<Project filename="Loki.cbp" active="1" />
|
||||||
<Project filename="test/CachedFactory/CachedFactory.cbp">
|
<Project filename="test\CachedFactory\CachedFactory.cbp">
|
||||||
<Depends filename="Loki.cbp" />
|
<Depends filename="Loki.cbp" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project filename="test/Checker/Checker.cbp" />
|
<Project filename="test\Checker\Checker.cbp" />
|
||||||
<Project filename="test/CheckReturn/CheckReturn.cbp" />
|
<Project filename="test\CheckReturn\CheckReturn.cbp" />
|
||||||
<Project filename="test/DeletableSingleton/DeletableSingleton.cbp">
|
<Project filename="test\DeletableSingleton\DeletableSingleton.cbp">
|
||||||
<Depends filename="Loki.cbp" />
|
<Depends filename="Loki.cbp" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project filename="test/Factory/Factory.cbp" />
|
<Project filename="test\Factory\Factory.cbp" />
|
||||||
<Project filename="test/flex_string/flex_string.cbp" />
|
<Project filename="test\flex_string\flex_string.cbp" />
|
||||||
<Project filename="test/Function/Function.cbp" />
|
<Project filename="test\Function\Function.cbp" />
|
||||||
<Project filename="test/LevelMutex/LevelMutex.cbp">
|
<Project filename="test\LevelMutex\LevelMutex.cbp">
|
||||||
<Depends filename="Loki.cbp" />
|
<Depends filename="Loki.cbp" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project filename="test/LockingPtr/LockingPtr.cbp" />
|
<Project filename="test\LockingPtr\LockingPtr.cbp" />
|
||||||
<Project filename="test/Longevity/Longevity.cbp" />
|
<Project filename="test\Longevity\Longevity.cbp" />
|
||||||
<Project filename="test/OrderedStatic/OrderedStatic.cbp">
|
<Project filename="test\OrderedStatic\OrderedStatic.cbp">
|
||||||
<Depends filename="Loki.cbp" />
|
<Depends filename="Loki.cbp" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project filename="test/Pimpl/Pimpl.cbp" />
|
<Project filename="test\Pimpl\Pimpl.cbp" />
|
||||||
<Project filename="test/Register/Register.cbp" />
|
<Project filename="test\Register\Register.cbp" />
|
||||||
<Project filename="test/RegressionTest/RegressionTest.cbp">
|
<Project filename="test\RegressionTest\RegressionTest.cbp">
|
||||||
<Depends filename="Loki.cbp" />
|
<Depends filename="Loki.cbp" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project filename="test/SafeFormat/SafeFormat.cbp">
|
<Project filename="test\SafeFormat\SafeFormat.cbp">
|
||||||
<Depends filename="Loki.cbp" />
|
<Depends filename="Loki.cbp" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project filename="test/ScopeGuard/ScopeGuard.cbp" />
|
<Project filename="test\ScopeGuard\ScopeGuard.cbp" />
|
||||||
<Project filename="test/Singleton/Singleton.cbp">
|
<Project filename="test\Singleton\Singleton.cbp">
|
||||||
<Depends filename="Loki.cbp" />
|
<Depends filename="Loki.cbp" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project filename="test/SmallObj/SmallObj.cbp">
|
<Project filename="test\SmallObj\SmallObj.cbp">
|
||||||
<Depends filename="Loki.cbp" />
|
<Depends filename="Loki.cbp" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project filename="test/SmallObj/DefaultAlloc.cbp" />
|
<Project filename="test\SmallObj\DefaultAlloc.cbp" />
|
||||||
<Project filename="test/SmartPtr/SmartPtr.cbp">
|
<Project filename="test\SmartPtr\SmartPtr.cbp">
|
||||||
<Depends filename="Loki.cbp" />
|
<Depends filename="Loki.cbp" />
|
||||||
</Project>
|
</Project>
|
||||||
<Project filename="test/Visitor/Visitor.cbp" />
|
<Project filename="test\Visitor\Visitor.cbp" />
|
||||||
<Project filename="test/SafeBits/SafeBits.cbp" />
|
<Project filename="test\SafeBits\SafeBits.cbp" />
|
||||||
<Project filename="test/ThreadLocal/ThreadLocal.cbp" />
|
<Project filename="test\ThreadLocal\ThreadLocal.cbp" />
|
||||||
</Workspace>
|
</Workspace>
|
||||||
</CodeBlocks_workspace_file>
|
</CodeBlocks_workspace_file>
|
||||||
|
|
|
@ -85,10 +85,7 @@
|
||||||
/// If you write your own policy, you must implement these 3 functions:
|
/// If you write your own policy, you must implement these 3 functions:
|
||||||
/// -# void static Delete( const P * p )
|
/// -# void static Delete( const P * p )
|
||||||
/// -# static P * Default( void )
|
/// -# static P * Default( void )
|
||||||
/// -# Default constructor.
|
/// -# void Swap( YourResetPolicy & )
|
||||||
/// -# Copy constructor.
|
|
||||||
/// -# Templated copy constructor.
|
|
||||||
/// -# void Swap( YourDeletePolicy & )
|
|
||||||
///
|
///
|
||||||
/// \par ResetPolicy
|
/// \par ResetPolicy
|
||||||
/// A reset policy tells the ReleaseAll and ResetAll functions whether they
|
/// A reset policy tells the ReleaseAll and ResetAll functions whether they
|
||||||
|
@ -238,6 +235,45 @@ protected:
|
||||||
inline void Swap( DeleteSingle & ) {}
|
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
|
/// \class DeleteArray
|
||||||
///
|
///
|
||||||
|
@ -2032,27 +2068,19 @@ public:
|
||||||
return * GetPointer();
|
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 )
|
ReferenceType operator [] ( size_t index )
|
||||||
{
|
{
|
||||||
PointerType p = GetPointer();
|
KP::OnDereference( GetPointer() );
|
||||||
KP::OnDereference( p );
|
|
||||||
DP::OnCheckRange( index );
|
DP::OnCheckRange( index );
|
||||||
|
PointerType p = GetPointer();
|
||||||
return p[ 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
|
ConstReferenceType operator [] ( size_t index ) const
|
||||||
{
|
{
|
||||||
ConstPointerType p = GetPointer();
|
KP::OnDereference( GetPointer() );
|
||||||
KP::OnDereference( p );
|
|
||||||
DP::OnCheckRange( index );
|
DP::OnCheckRange( index );
|
||||||
|
ConstPointerType p = GetPointer();
|
||||||
return p[ index ];
|
return p[ index ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,28 +28,20 @@
|
||||||
// The __APPLE__ macro does not refer to a compiler, but to the Apple OSX operating system.
|
// The __APPLE__ macro does not refer to a compiler, but to the Apple OSX operating system.
|
||||||
#if defined( __APPLE__ )
|
#if defined( __APPLE__ )
|
||||||
#warning "GCC for Apple does not allow thread_local storage, so you can not use some parts of Loki."
|
#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__ )
|
#elif defined( __CYGWIN__ )
|
||||||
#if ( __GNUC__ <= 3 )
|
#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."
|
#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
|
#endif
|
||||||
|
|
||||||
#elif ( __GNUC__ == 4 ) // GNU versions other than Cygwin.
|
#elif ( __GNUC__ == 4 ) // GNU versions other than Cygwin.
|
||||||
#if ( __GNUC_MINOR__ < 4 )
|
#if ( __GNUC_MINOR__ == 4 )
|
||||||
#warning "GCC versions before 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki."
|
#warning "GCC version 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki."
|
||||||
#undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE
|
#undef 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
|
#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 )
|
#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.
|
you can't use some parts of Loki.
|
||||||
*/
|
*/
|
||||||
#if defined( _MSC_VER )
|
#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__ )
|
#elif ( __GNUC__ )
|
||||||
#define LOKI_THREAD_LOCAL __thread
|
#define LOKI_THREAD_LOCAL __thread
|
||||||
|
|
|
@ -1339,17 +1339,17 @@ getline(
|
||||||
typename flex_string<E, T, A, S>::value_type delim)
|
typename flex_string<E, T, A, S>::value_type delim)
|
||||||
{
|
{
|
||||||
size_t nread = 0;
|
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);
|
typename flex_string<E, T, A, S>::traits_type>::sentry sentry(is, true);
|
||||||
if (sentry) {
|
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();
|
typename flex_string<E, T, A, S>::traits_type>* buf = is.rdbuf();
|
||||||
str.clear();
|
str.clear();
|
||||||
|
|
||||||
while (nread < str.max_size()) {
|
while (nread < str.max_size()) {
|
||||||
int c1 = buf->sbumpc();
|
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())) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1363,7 +1363,7 @@ getline(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nread == 0 || nread >= str.max_size())
|
if (nread == 0 || nread >= str.max_size())
|
||||||
is.setstate(::std::ios_base::failbit);
|
is.setstate(ios_base::failbit);
|
||||||
|
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
|
|
||||||
#include <loki/StrongPtr.h>
|
#include <loki/StrongPtr.h>
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#ifdef DO_EXTRA_LOKI_TESTS
|
#ifdef DO_EXTRA_LOKI_TESTS
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
@ -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 )
|
OneOwnerRefCountInfo::OneOwnerRefCountInfo( SingleOwnerRefCount * ptr )
|
||||||
: m_pointer( NULL )
|
: m_pointer( NULL )
|
||||||
, m_strongPtr( ptr )
|
, m_strongPtr( ptr )
|
||||||
|
|
|
@ -6,24 +6,24 @@
|
||||||
<Option compiler="cygwin" />
|
<Option compiler="cygwin" />
|
||||||
<Build>
|
<Build>
|
||||||
<Target title="Debug_GCC">
|
<Target title="Debug_GCC">
|
||||||
<Option output="obj/Debug_GCC/LevelMutex" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Debug_GCC\LevelMutex" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Debug_GCC/" />
|
<Option object_output="obj\Debug_GCC\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-g" />
|
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include" />
|
<Add option="-g" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include" />
|
||||||
|
<Add directory="..\..\include\loki" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/GCC/Loki_D.a" />
|
<Add library="..\..\lib\GCC\Loki_D.a" />
|
||||||
<Add library="/usr/lib/libpthread.so" />
|
<Add library="..\..\..\PThreads\lib\pthreadVC2.lib" />
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release_GCC">
|
<Target title="Release_GCC">
|
||||||
<Option output="obj/Release_GCC/LevelMutex" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Release_GCC\LevelMutex" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Release_GCC/" />
|
<Option object_output="obj\Release_GCC\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
|
@ -31,33 +31,33 @@
|
||||||
<Add option="-Os" />
|
<Add option="-Os" />
|
||||||
<Add option="-O3" />
|
<Add option="-O3" />
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include\loki" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/GCC/Loki.a" />
|
<Add library="..\..\lib\GCC\Loki.a" />
|
||||||
<Add library="/usr/lib/libpthread.so" />
|
<Add library="..\..\..\PThreads\lib\pthreadVC2.lib" />
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Debug_Cygwin">
|
<Target title="Debug_Cygwin">
|
||||||
<Option output="obj/Debug_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Debug_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Debug_Cygwin/" />
|
<Option object_output="obj\Debug_Cygwin\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="cygwin" />
|
<Option compiler="cygwin" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add option="-g" />
|
<Add option="-g" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include\loki" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/Cygwin/Loki_D.a" />
|
<Add library="..\..\lib\Cygwin\Loki_D.a" />
|
||||||
<Add library="../../../PThreads/lib/pthreadVC2.lib" />
|
<Add library="..\..\..\PThreads\lib\pthreadVC2.lib" />
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release_Cygwin">
|
<Target title="Release_Cygwin">
|
||||||
<Option output="obj/Release_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Release_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Release_Cygwin/" />
|
<Option object_output="obj\Release_Cygwin\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="cygwin" />
|
<Option compiler="cygwin" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
|
@ -65,12 +65,12 @@
|
||||||
<Add option="-Os" />
|
<Add option="-Os" />
|
||||||
<Add option="-O3" />
|
<Add option="-O3" />
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include\loki" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/Cygwin/Loki.a" />
|
<Add library="..\..\lib\Cygwin\Loki.a" />
|
||||||
<Add library="../../../PThreads/lib/pthreadVC2.lib" />
|
<Add library="..\..\..\PThreads\lib\pthreadVC2.lib" />
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
</Build>
|
</Build>
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "MultiThreadTests.hpp"
|
#include "MultiThreadTests.hpp"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
//#include <process.h>
|
#include <process.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
@ -239,8 +239,6 @@ void * ValueUnsafeThread( void * p )
|
||||||
|
|
||||||
void MultiThreadSimpleTest( void )
|
void MultiThreadSimpleTest( void )
|
||||||
{
|
{
|
||||||
cout << "Starting MultiThreadSimpleTest." << endl;
|
|
||||||
|
|
||||||
Thing::Init( 0 );
|
Thing::Init( 0 );
|
||||||
const unsigned int threadCount = 5;
|
const unsigned int threadCount = 5;
|
||||||
ThreadPool pool( threadCount );
|
ThreadPool pool( threadCount );
|
||||||
|
@ -264,8 +262,6 @@ void MultiThreadSimpleTest( void )
|
||||||
pool.JoinAll();
|
pool.JoinAll();
|
||||||
|
|
||||||
Thing::Destroy();
|
Thing::Destroy();
|
||||||
|
|
||||||
cout << "Finished MultiThreadSimpleTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -303,17 +299,13 @@ void * TryLockThread( void * p )
|
||||||
|
|
||||||
void MultiThreadTryLockTest( void )
|
void MultiThreadTryLockTest( void )
|
||||||
{
|
{
|
||||||
cout << "Starting MultiThreadTryLockTest." << endl;
|
|
||||||
|
|
||||||
static const unsigned int threadCount = 3;
|
static const unsigned int threadCount = 3;
|
||||||
Thing::Init( 0 );
|
Thing::Init( 0 );
|
||||||
volatile Thing & thing = Thing::GetIt();
|
volatile Thing & thing = Thing::GetIt();
|
||||||
volatile SleepMutex & mutex = thing.GetMutex();
|
volatile SleepMutex & mutex = thing.GetMutex();
|
||||||
|
|
||||||
cout << endl << "Doing multi-threaded TryLock test. This test should not deadlock." << endl;
|
cout << endl << "Doing multi-threaded TryLock test. This test should not deadlock." << endl;
|
||||||
cout << "Press enter key to continue." << endl;
|
::system( "pause" );
|
||||||
char theKey = 0;
|
|
||||||
cin.get( theKey );
|
|
||||||
// First step is to lock the mutex in the main thread so no child thread
|
// 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.
|
// can ever lock it, change the value, or anything like that.
|
||||||
MutexErrors::Type result = mutex.Lock();
|
MutexErrors::Type result = mutex.Lock();
|
||||||
|
@ -321,46 +313,36 @@ void MultiThreadTryLockTest( void )
|
||||||
bool okay = mutex.IsLockedByCurrentThread();
|
bool okay = mutex.IsLockedByCurrentThread();
|
||||||
assert( okay );
|
assert( okay );
|
||||||
thing.SetValue( threadCount );
|
thing.SetValue( threadCount );
|
||||||
|
ThreadPool pool( threadCount );
|
||||||
|
for ( unsigned int ii = 0; ii < threadCount; ++ii )
|
||||||
{
|
{
|
||||||
ThreadPool pool( threadCount );
|
void * p = reinterpret_cast< void * >( ii );
|
||||||
for ( unsigned int ii = 0; ii < threadCount; ++ii )
|
pool.Start( TryLockThread, p );
|
||||||
{
|
|
||||||
void * p = reinterpret_cast< void * >( ii );
|
|
||||||
pool.Start( TryLockThread, p );
|
|
||||||
}
|
|
||||||
pool.JoinAll();
|
|
||||||
}
|
}
|
||||||
|
pool.JoinAll();
|
||||||
const unsigned int value = thing.GetValue();
|
const unsigned int value = thing.GetValue();
|
||||||
assert( value == threadCount );
|
assert( value == threadCount );
|
||||||
result = mutex.Unlock();
|
result = mutex.Unlock();
|
||||||
assert( MutexErrors::Success == result );
|
assert( MutexErrors::Success == result );
|
||||||
okay = !mutex.IsLockedByCurrentThread();
|
okay = !mutex.IsLockedByCurrentThread();
|
||||||
assert( okay );
|
assert( okay );
|
||||||
okay = !mutex.IsLocked();
|
okay = !mutex.IsLocked();
|
||||||
assert( okay );
|
assert( okay );
|
||||||
|
|
||||||
Thing::Destroy();
|
Thing::Destroy();
|
||||||
|
|
||||||
cout << "Finished MultiThreadTryLockTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void MultiThreadReentrantTest( void )
|
void MultiThreadReentrantTest( void )
|
||||||
{
|
{
|
||||||
cout << "Starting MultiThreadReentrantTest." << endl;
|
|
||||||
|
|
||||||
Thing::Init( 0 );
|
Thing::Init( 0 );
|
||||||
const unsigned int threadCount = 8;
|
const unsigned int threadCount = 8;
|
||||||
TestResults::Create( threadCount );
|
TestResults::Create( threadCount );
|
||||||
ThreadPool pool( threadCount );
|
ThreadPool pool( threadCount );
|
||||||
|
|
||||||
cout << endl << "Doing thread-safe value test. This test should pass and not deadlock." << endl;
|
cout << endl << "Doing thread-safe value test. This test should pass and not deadlock." << endl;
|
||||||
cout << "Press enter key to continue." << endl;
|
::system( "pause" );
|
||||||
char theKey = 0;
|
|
||||||
cin.get( theKey );
|
|
||||||
for ( unsigned int ii = 0; ii < threadCount; ++ii )
|
for ( unsigned int ii = 0; ii < threadCount; ++ii )
|
||||||
{
|
{
|
||||||
void * p = reinterpret_cast< void * >( ii );
|
void * p = reinterpret_cast< void * >( ii );
|
||||||
|
@ -370,8 +352,7 @@ void MultiThreadReentrantTest( void )
|
||||||
TestResults::GetIt()->OutputResults();
|
TestResults::GetIt()->OutputResults();
|
||||||
|
|
||||||
cout << endl << "Doing thread-unsafe value test. This test may fail." << endl;
|
cout << endl << "Doing thread-unsafe value test. This test may fail." << endl;
|
||||||
cout << "Press enter key to continue." << endl;
|
::system( "pause" );
|
||||||
cin.get( theKey );
|
|
||||||
for ( unsigned int ii = 0; ii < threadCount; ++ii )
|
for ( unsigned int ii = 0; ii < threadCount; ++ii )
|
||||||
{
|
{
|
||||||
void * p = reinterpret_cast< void * >( ii );
|
void * p = reinterpret_cast< void * >( ii );
|
||||||
|
@ -382,8 +363,6 @@ void MultiThreadReentrantTest( void )
|
||||||
|
|
||||||
TestResults::Destroy();
|
TestResults::Destroy();
|
||||||
Thing::Destroy();
|
Thing::Destroy();
|
||||||
|
|
||||||
cout << "Finished MultiThreadReentrantTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -667,8 +646,6 @@ void * MultiLockUnsafeThread( void * p )
|
||||||
|
|
||||||
void MultiThreadMultiLockTest( void )
|
void MultiThreadMultiLockTest( void )
|
||||||
{
|
{
|
||||||
cout << "Starting MultiThreadMultiLockTest." << endl;
|
|
||||||
|
|
||||||
Thing::MakePool( thingCount );
|
Thing::MakePool( thingCount );
|
||||||
const unsigned int threadCount = 8;
|
const unsigned int threadCount = 8;
|
||||||
TestResults::Create( threadCount );
|
TestResults::Create( threadCount );
|
||||||
|
@ -697,8 +674,6 @@ void MultiThreadMultiLockTest( void )
|
||||||
|
|
||||||
TestResults::Destroy();
|
TestResults::Destroy();
|
||||||
Thing::DestroyPool();
|
Thing::DestroyPool();
|
||||||
|
|
||||||
cout << "Finished MultiThreadMultiLockTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -833,8 +808,6 @@ void * MultiLockRandomUnsafeThread( void * p )
|
||||||
|
|
||||||
void MultiThreadRandomMultiLockTest( void )
|
void MultiThreadRandomMultiLockTest( void )
|
||||||
{
|
{
|
||||||
cout << "Starting MultiThreadRandomMultiLockTest." << endl;
|
|
||||||
|
|
||||||
Thing::MakePool( thingCount );
|
Thing::MakePool( thingCount );
|
||||||
const unsigned int threadCount = 8;
|
const unsigned int threadCount = 8;
|
||||||
TestResults::Create( threadCount );
|
TestResults::Create( threadCount );
|
||||||
|
@ -863,8 +836,6 @@ void MultiThreadRandomMultiLockTest( void )
|
||||||
|
|
||||||
TestResults::Destroy();
|
TestResults::Destroy();
|
||||||
Thing::DestroyPool();
|
Thing::DestroyPool();
|
||||||
|
|
||||||
cout << "Finished MultiThreadRandomMultiLockTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -965,8 +936,6 @@ void * UnsafeHierarchyTest( void * p )
|
||||||
|
|
||||||
void MultiThreadHierarchySingleLockTest( void )
|
void MultiThreadHierarchySingleLockTest( void )
|
||||||
{
|
{
|
||||||
cout << "Starting MultiThreadHierarchySingleLockTest." << endl;
|
|
||||||
|
|
||||||
LevelThing::MakePool( thingCount );
|
LevelThing::MakePool( thingCount );
|
||||||
const unsigned int threadCount = 8;
|
const unsigned int threadCount = 8;
|
||||||
TestResults::Create( threadCount );
|
TestResults::Create( threadCount );
|
||||||
|
@ -995,8 +964,6 @@ void MultiThreadHierarchySingleLockTest( void )
|
||||||
|
|
||||||
TestResults::Destroy();
|
TestResults::Destroy();
|
||||||
LevelThing::DestroyPool();
|
LevelThing::DestroyPool();
|
||||||
|
|
||||||
cout << "Finished MultiThreadHierarchySingleLockTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -1098,8 +1065,6 @@ void * UnsafeHierarchyMultiLockTest( void * p )
|
||||||
void MultiThreadHierarchyMultiLockTest( void )
|
void MultiThreadHierarchyMultiLockTest( void )
|
||||||
{
|
{
|
||||||
|
|
||||||
cout << "Starting MultiThreadHierarchyMultiLockTest." << endl;
|
|
||||||
|
|
||||||
MultiLevelPool::MakePool( 10, thingCount );
|
MultiLevelPool::MakePool( 10, thingCount );
|
||||||
const unsigned int threadCount = 8;
|
const unsigned int threadCount = 8;
|
||||||
TestResults::Create( threadCount );
|
TestResults::Create( threadCount );
|
||||||
|
@ -1128,8 +1093,6 @@ void MultiThreadHierarchyMultiLockTest( void )
|
||||||
|
|
||||||
TestResults::Destroy();
|
TestResults::Destroy();
|
||||||
MultiLevelPool::DestroyPool();
|
MultiLevelPool::DestroyPool();
|
||||||
|
|
||||||
cout << "Finished MultiThreadHierarchyMultiLockTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
//#include <process.h>
|
#include <process.h>
|
||||||
#if !defined( _MSC_VER )
|
#if !defined( _MSC_VER )
|
||||||
#include <unistd.h> // needed for the usleep function.
|
#include <unistd.h> // needed for the usleep function.
|
||||||
#endif
|
#endif
|
||||||
|
@ -86,13 +86,11 @@ Thread::~Thread( void )
|
||||||
bool Thread::WaitForThread( void ) volatile
|
bool Thread::WaitForThread( void ) volatile
|
||||||
{
|
{
|
||||||
assert( IsValid( m_owner ) );
|
assert( IsValid( m_owner ) );
|
||||||
|
|
||||||
const volatile Thread * current = Thread::GetCurrentThread();
|
const volatile Thread * current = Thread::GetCurrentThread();
|
||||||
if ( this == current )
|
if ( this == current )
|
||||||
return false;
|
return false;
|
||||||
if ( m_status == Thread::Dead )
|
if ( m_status == Thread::Dead )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while ( this->m_status == Thread::Active )
|
while ( this->m_status == Thread::Active )
|
||||||
{
|
{
|
||||||
// Call the wait policy.
|
// Call the wait policy.
|
||||||
|
@ -102,8 +100,6 @@ bool Thread::WaitForThread( void ) volatile
|
||||||
::usleep( 1000 );
|
::usleep( 1000 );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
m_status = Thread::Idle;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,6 @@ typedef ::Loki::LevelMutex< ::Loki::SpinLevelMutex, 1,
|
||||||
void SingleThreadSimpleTest( void )
|
void SingleThreadSimpleTest( void )
|
||||||
{
|
{
|
||||||
|
|
||||||
cout << "Starting SingleThreadSimpleTest." << endl;
|
|
||||||
|
|
||||||
const unsigned int priorLevel = GetCurrentThreadsLevel();
|
const unsigned int priorLevel = GetCurrentThreadsLevel();
|
||||||
const unsigned int priorLockCount = CountLocksInCurrentThread();
|
const unsigned int priorLockCount = CountLocksInCurrentThread();
|
||||||
const unsigned int priorMutexCount = CountMutexesInCurrentThread();
|
const unsigned int priorMutexCount = CountMutexesInCurrentThread();
|
||||||
|
@ -173,8 +171,6 @@ void SingleThreadSimpleTest( void )
|
||||||
assert( okay );
|
assert( okay );
|
||||||
okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount );
|
okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount );
|
||||||
assert( okay );
|
assert( okay );
|
||||||
|
|
||||||
cout << "Finished SingleThreadSimpleTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -182,8 +178,6 @@ void SingleThreadSimpleTest( void )
|
||||||
void SingleThreadReentrantTest( void )
|
void SingleThreadReentrantTest( void )
|
||||||
{
|
{
|
||||||
|
|
||||||
cout << "Starting SingleThreadReentrantTest." << endl;
|
|
||||||
|
|
||||||
const unsigned int priorLevel = GetCurrentThreadsLevel();
|
const unsigned int priorLevel = GetCurrentThreadsLevel();
|
||||||
const unsigned int priorLockCount = CountLocksInCurrentThread();
|
const unsigned int priorLockCount = CountLocksInCurrentThread();
|
||||||
const unsigned int priorMutexCount = CountMutexesInCurrentThread();
|
const unsigned int priorMutexCount = CountMutexesInCurrentThread();
|
||||||
|
@ -289,8 +283,6 @@ void SingleThreadReentrantTest( void )
|
||||||
assert( okay );
|
assert( okay );
|
||||||
okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount );
|
okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount );
|
||||||
assert( okay );
|
assert( okay );
|
||||||
|
|
||||||
cout << "Finished SingleThreadReentrantTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -298,8 +290,6 @@ void SingleThreadReentrantTest( void )
|
||||||
void SingleThreadSimpleMultiLockTest( void )
|
void SingleThreadSimpleMultiLockTest( void )
|
||||||
{
|
{
|
||||||
|
|
||||||
cout << "Starting SingleThreadSimpleMultiLockTest." << endl;
|
|
||||||
|
|
||||||
const unsigned int priorLevel = GetCurrentThreadsLevel();
|
const unsigned int priorLevel = GetCurrentThreadsLevel();
|
||||||
const unsigned int priorLockCount = CountLocksInCurrentThread();
|
const unsigned int priorLockCount = CountLocksInCurrentThread();
|
||||||
const unsigned int priorMutexCount = CountMutexesInCurrentThread();
|
const unsigned int priorMutexCount = CountMutexesInCurrentThread();
|
||||||
|
@ -491,8 +481,6 @@ void SingleThreadSimpleMultiLockTest( void )
|
||||||
assert( okay );
|
assert( okay );
|
||||||
okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount );
|
okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount );
|
||||||
assert( okay );
|
assert( okay );
|
||||||
|
|
||||||
cout << "Finished SingleThreadSimpleMultiLockTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -500,8 +488,6 @@ void SingleThreadSimpleMultiLockTest( void )
|
||||||
void SingleThreadExceptionTest( void )
|
void SingleThreadExceptionTest( void )
|
||||||
{
|
{
|
||||||
|
|
||||||
cout << "Starting SingleThreadExceptionTest." << endl;
|
|
||||||
|
|
||||||
const unsigned int priorLevel = GetCurrentThreadsLevel();
|
const unsigned int priorLevel = GetCurrentThreadsLevel();
|
||||||
const unsigned int priorLockCount = CountLocksInCurrentThread();
|
const unsigned int priorLockCount = CountLocksInCurrentThread();
|
||||||
const unsigned int priorMutexCount = CountMutexesInCurrentThread();
|
const unsigned int priorMutexCount = CountMutexesInCurrentThread();
|
||||||
|
@ -650,8 +636,6 @@ void SingleThreadExceptionTest( void )
|
||||||
assert( okay );
|
assert( okay );
|
||||||
okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount );
|
okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount );
|
||||||
assert( okay );
|
assert( okay );
|
||||||
|
|
||||||
cout << "Finished SingleThreadExceptionTest." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -676,7 +660,6 @@ int main( int argc, const char * const argv[] )
|
||||||
|
|
||||||
MultiThreadSimpleTest();
|
MultiThreadSimpleTest();
|
||||||
MultiThreadTryLockTest();
|
MultiThreadTryLockTest();
|
||||||
cout << "main 679" << endl;
|
|
||||||
MultiThreadReentrantTest();
|
MultiThreadReentrantTest();
|
||||||
MultiThreadMultiLockTest();
|
MultiThreadMultiLockTest();
|
||||||
MultiThreadRandomMultiLockTest();
|
MultiThreadRandomMultiLockTest();
|
||||||
|
|
|
@ -3,27 +3,26 @@
|
||||||
<FileVersion major="1" minor="6" />
|
<FileVersion major="1" minor="6" />
|
||||||
<Project>
|
<Project>
|
||||||
<Option title="LockingPtr" />
|
<Option title="LockingPtr" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="cygwin" />
|
||||||
<Build>
|
<Build>
|
||||||
<Target title="Debug_GCC">
|
<Target title="Debug_GCC">
|
||||||
<Option output="obj/Debug_GCC/LockingPtr" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Debug_GCC\LockingPtr" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Debug_GCC/" />
|
<Option object_output="obj\Debug_GCC\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-g" />
|
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include/loki" />
|
<Add option="-g" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include\loki" />
|
||||||
|
<Add directory="..\..\include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/GCC/Loki_D.a" />
|
<Add library="..\..\lib\GCC\Loki_D.a" />
|
||||||
<Add library="/usr/lib/libpthread.so" />
|
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release_GCC">
|
<Target title="Release_GCC">
|
||||||
<Option output="obj/Release_GCC/LockingPtr" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Release_GCC\LockingPtr" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Release_GCC/" />
|
<Option object_output="obj\Release_GCC\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
|
@ -31,44 +30,43 @@
|
||||||
<Add option="-Os" />
|
<Add option="-Os" />
|
||||||
<Add option="-O3" />
|
<Add option="-O3" />
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include\loki" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/GCC/Loki.a" />
|
<Add library="..\..\lib\GCC\Loki.a" />
|
||||||
<Add library="/usr/lib/libpthread.so" />
|
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Debug_Cygwin">
|
<Target title="Debug_Cygwin">
|
||||||
<Option output="obj/Debug_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Debug_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Debug_Cygwin/" />
|
<Option object_output="obj\Debug_Cygwin\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="cygwin" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add option="-g" />
|
<Add option="-g" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include\loki" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/Cygwin/Loki_D.a" />
|
<Add library="..\..\lib\Cygwin\Loki_D.a" />
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release_Cygwin">
|
<Target title="Release_Cygwin">
|
||||||
<Option output="obj/Release_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Release_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Release_Cygwin/" />
|
<Option object_output="obj\Release_Cygwin\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="cygwin" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-fexpensive-optimizations" />
|
<Add option="-fexpensive-optimizations" />
|
||||||
<Add option="-Os" />
|
<Add option="-Os" />
|
||||||
<Add option="-O3" />
|
<Add option="-O3" />
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include\loki" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/Cygwin/Loki.a" />
|
<Add library="..\..\lib\Cygwin\Loki.a" />
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
</Build>
|
</Build>
|
||||||
|
|
|
@ -6,25 +6,23 @@
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Build>
|
<Build>
|
||||||
<Target title="Debug_GCC">
|
<Target title="Debug_GCC">
|
||||||
<Option output="bin/Debug_GCC/SmartPtr" prefix_auto="1" extension_auto="1" />
|
<Option output="bin\Debug_GCC\SmartPtr" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Debug_GCC/" />
|
<Option object_output="obj\Debug_GCC\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-g" />
|
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include/loki" />
|
<Add option="-g" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include\loki" />
|
||||||
|
<Add directory="..\..\include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<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>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release_GCC">
|
<Target title="Release_GCC">
|
||||||
<Option output="bin/Release_GCC/SmartPtr" prefix_auto="1" extension_auto="1" />
|
<Option output="bin\Release_GCC\SmartPtr" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Release_GCC/" />
|
<Option object_output="obj\Release_GCC\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
|
@ -32,33 +30,31 @@
|
||||||
<Add option="-Os" />
|
<Add option="-Os" />
|
||||||
<Add option="-O3" />
|
<Add option="-O3" />
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include\loki" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<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>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Debug_Cygwin">
|
<Target title="Debug_Cygwin">
|
||||||
<Option output="bin/Debug_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" />
|
<Option output="bin\Debug_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Debug_Cygwin/" />
|
<Option object_output="obj\Debug_Cygwin\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="cygwin" />
|
<Option compiler="cygwin" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add option="-g" />
|
<Add option="-g" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include\loki" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/Cygwin/Loki_D.a" />
|
<Add library="..\..\lib\Cygwin\Loki_D.a" />
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release_Cygwin">
|
<Target title="Release_Cygwin">
|
||||||
<Option output="bin/Release_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" />
|
<Option output="bin\Release_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Release_Cygwin/" />
|
<Option object_output="obj\Release_Cygwin\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="cygwin" />
|
<Option compiler="cygwin" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
|
@ -66,11 +62,11 @@
|
||||||
<Add option="-Os" />
|
<Add option="-Os" />
|
||||||
<Add option="-O3" />
|
<Add option="-O3" />
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include/loki" />
|
<Add directory="..\..\include\loki" />
|
||||||
<Add directory="../../include" />
|
<Add directory="..\..\include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add library="../../lib/Cygwin/Loki.a" />
|
<Add library="..\..\lib\Cygwin\Loki.a" />
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
</Build>
|
</Build>
|
||||||
|
@ -78,7 +74,6 @@
|
||||||
<Unit filename="base.h">
|
<Unit filename="base.h">
|
||||||
<Option target="<{~None~}>" />
|
<Option target="<{~None~}>" />
|
||||||
</Unit>
|
</Unit>
|
||||||
<Unit filename="colvin_gibbons_trick.cpp" />
|
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
<Unit filename="strong.cpp" />
|
<Unit filename="strong.cpp" />
|
||||||
<Extensions>
|
<Extensions>
|
||||||
|
|
|
@ -73,10 +73,9 @@ public:
|
||||||
return s_destructions;
|
return s_destructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
BaseClass( const BaseClass & that ) : m_refCount( that.m_refCount ) {}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// Not implemented.
|
||||||
|
BaseClass( const BaseClass & );
|
||||||
/// Not implemented.
|
/// Not implemented.
|
||||||
BaseClass & operator = ( const BaseClass & );
|
BaseClass & operator = ( const BaseClass & );
|
||||||
|
|
||||||
|
@ -111,44 +110,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/** @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 ); }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -1205,6 +1205,75 @@ void DoForwardReferenceTest( void )
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
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 )
|
void DoSmartPtrDynamicCastTests( void )
|
||||||
{
|
{
|
||||||
cout << "Starting DoSmartPtrDynamicCastTests." << endl;
|
cout << "Starting DoSmartPtrDynamicCastTests." << endl;
|
||||||
|
@ -1290,9 +1359,9 @@ void DoSmartPtrDynamicCastTests( void )
|
||||||
assert( !pDog );
|
assert( !pDog );
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( BaseClass::AllDestroyed() );
|
assert( Feline::AllDestroyed() );
|
||||||
assert( !BaseClass::ExtraConstructions() );
|
assert( !Feline::ExtraConstructions() );
|
||||||
assert( !BaseClass::ExtraDestructions() );
|
assert( !Feline::ExtraDestructions() );
|
||||||
cout << "Finished DoSmartPtrDynamicCastTests." << endl;
|
cout << "Finished DoSmartPtrDynamicCastTests." << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1449,161 +1518,6 @@ void DoDestructiveCopyTest( void )
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// 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[] )
|
int main( int argc, const char * argv[] )
|
||||||
{
|
{
|
||||||
bool doThreadTest = false;
|
bool doThreadTest = false;
|
||||||
|
@ -1642,7 +1556,6 @@ int main( int argc, const char * argv[] )
|
||||||
DoSmartPtrDynamicCastTests();
|
DoSmartPtrDynamicCastTests();
|
||||||
DoStrongPtrDynamicCastTests();
|
DoStrongPtrDynamicCastTests();
|
||||||
DoStrongArrayTests();
|
DoStrongArrayTests();
|
||||||
DoSmartArrayTests();
|
|
||||||
|
|
||||||
#if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING)
|
#if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING)
|
||||||
if ( doThreadTest )
|
if ( doThreadTest )
|
||||||
|
|
|
@ -1778,6 +1778,42 @@ void DoStrongCompareTests( void )
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
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 )
|
void DoStrongPtrDynamicCastTests( void )
|
||||||
{
|
{
|
||||||
typedef ::Loki::StrongPtr< Feline, true, ::Loki::TwoRefCounts > FelineCountPtr;
|
typedef ::Loki::StrongPtr< Feline, true, ::Loki::TwoRefCounts > FelineCountPtr;
|
||||||
|
|
|
@ -7,37 +7,28 @@
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Build>
|
<Build>
|
||||||
<Target title="Debug_GCC">
|
<Target title="Debug_GCC">
|
||||||
<Option output="obj/Debug_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Debug_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Debug_GCC/" />
|
<Option object_output="obj\Debug_GCC\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-Wmain" />
|
<Add option="-Wmain" />
|
||||||
<Add option="-pedantic" />
|
<Add option="-pedantic" />
|
||||||
<Add option="-g" />
|
|
||||||
<Add option="-W" />
|
<Add option="-W" />
|
||||||
<Add directory="../../include" />
|
<Add option="-g" />
|
||||||
|
<Add directory="..\..\include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
|
||||||
<Add library="/usr/lib/libpthread.so" />
|
|
||||||
<Add library="/usr/lib/libc.so" />
|
|
||||||
</Linker>
|
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release_GCC">
|
<Target title="Release_GCC">
|
||||||
<Option output="obj/Release_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" />
|
<Option output="obj\Release_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" />
|
||||||
<Option object_output="obj/Release_GCC/" />
|
<Option object_output="obj\Release_GCC\" />
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-O2" />
|
<Add option="-O2" />
|
||||||
<Add option="-Wmain" />
|
|
||||||
<Add option="-pedantic" />
|
|
||||||
<Add option="-W" />
|
|
||||||
<Add directory="../../include" />
|
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add option="-s" />
|
<Add option="-s" />
|
||||||
<Add library="/usr/lib/libpthread.so" />
|
|
||||||
</Linker>
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
</Build>
|
</Build>
|
||||||
|
@ -50,7 +41,6 @@
|
||||||
<code_completion />
|
<code_completion />
|
||||||
<debugger />
|
<debugger />
|
||||||
<lib_finder disable_auto="1" />
|
<lib_finder disable_auto="1" />
|
||||||
<envvars />
|
|
||||||
</Extensions>
|
</Extensions>
|
||||||
</Project>
|
</Project>
|
||||||
</CodeBlocks_project_file>
|
</CodeBlocks_project_file>
|
||||||
|
|
|
@ -26,7 +26,18 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#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)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
|
@ -45,8 +56,6 @@
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#define LOKI_pthread_t \
|
#define LOKI_pthread_t \
|
||||||
pthread_t
|
pthread_t
|
||||||
#define LOKI_pthread_create(handle,attr,func,arg) \
|
#define LOKI_pthread_create(handle,attr,func,arg) \
|
||||||
|
@ -56,19 +65,6 @@
|
||||||
|
|
||||||
#endif
|
#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
|
class Thread
|
||||||
|
@ -369,9 +365,6 @@ bool TestThreadLocalClassStaticValue( void )
|
||||||
|
|
||||||
int main( int argc, const char * const argv[] )
|
int main( int argc, const char * const argv[] )
|
||||||
{
|
{
|
||||||
(void)argc;
|
|
||||||
(void)argv;
|
|
||||||
|
|
||||||
bool okay = true;
|
bool okay = true;
|
||||||
cout << "Starting ThreadLocal tests." << endl;
|
cout << "Starting ThreadLocal tests." << endl;
|
||||||
cout << "If any tests fail, or any assertions fail," << endl
|
cout << "If any tests fail, or any assertions fail," << endl
|
||||||
|
|
Loading…
Add table
Reference in a new issue