From: <ric...@us...> - 2013-06-24 05:13:52
|
Revision: 1186 http://sourceforge.net/p/loki-lib/code/1186 Author: rich_sposato Date: 2013-06-24 05:13:49 +0000 (Mon, 24 Jun 2013) Log Message: ----------- Changed unsigned int to uintptr_t. Patch #23. Modified Paths: -------------- trunk/test/LevelMutex/MultiThreadTests.cpp trunk/test/LevelMutex/Thing.cpp trunk/test/LevelMutex/Thing.hpp trunk/test/Lockable/main.cpp trunk/test/SafeFormat/main.cpp trunk/test/ThreadLocal/ThreadTests.cpp Modified: trunk/test/LevelMutex/MultiThreadTests.cpp =================================================================== --- trunk/test/LevelMutex/MultiThreadTests.cpp 2013-06-23 01:14:58 UTC (rev 1185) +++ trunk/test/LevelMutex/MultiThreadTests.cpp 2013-06-24 05:13:49 UTC (rev 1186) @@ -89,7 +89,7 @@ void * PrintSafeThread( void * p ) { - unsigned int value = reinterpret_cast< unsigned int >( p ); + uintptr_t value = reinterpret_cast< uintptr_t >( p ); volatile Thing & thing = Thing::GetIt(); try { @@ -119,7 +119,7 @@ void * PrintUnsafeThread( void * p ) { - unsigned int value = reinterpret_cast< unsigned int >( p ); + uintptr_t value = reinterpret_cast< uintptr_t >( p ); Thing & thing = const_cast< Thing & >( Thing::GetIt() ); try { @@ -147,7 +147,7 @@ // ---------------------------------------------------------------------------- -void OutputResults( unsigned int loop, unsigned int value, unsigned int result ) +void OutputResults( unsigned int loop, uintptr_t value, uintptr_t result ) { static volatile SleepMutex mutex( 2 ); static bool initialized = false; @@ -177,7 +177,7 @@ const unsigned int testCount = 8; unsigned int fails = 0; - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); volatile Thing & thing = Thing::GetIt(); try { @@ -187,7 +187,7 @@ (void)locker; thing.SetValue( value ); ::GoToSleep( 3 ); - const unsigned int result = thing.GetValue(); + const uintptr_t result = thing.GetValue(); OutputResults( ii, value, result ); if ( result != value ) fails++; @@ -210,7 +210,7 @@ const unsigned int testCount = 8; unsigned int fails = 0; - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); // cast away volatility so the mutex doesn't get used by volatile functions. Thing & thing = const_cast< Thing & >( Thing::GetIt() ); try @@ -219,7 +219,7 @@ { thing.SetValue( value ); ::GoToSleep( 3 ); - const unsigned int result = thing.GetValue(); + const uintptr_t result = thing.GetValue(); OutputResults( ii, value, result ); if ( result != value ) fails++; @@ -249,7 +249,7 @@ cout << "Doing thread-locked print test. This test should pass and not deadlock" << endl; cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( PrintSafeThread, p ); @@ -262,7 +262,7 @@ cout << endl << "Doing thread-unsafe print test. This test may fail, but not deadlock." << endl; cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( PrintUnsafeThread, p ); @@ -279,7 +279,7 @@ void * TryLockThread( void * p ) { - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); volatile Thing & thing = Thing::GetIt(); volatile SleepMutex & mutex = thing.GetMutex(); assert( mutex.IsLockedByAnotherThread() ); @@ -297,7 +297,7 @@ result = mutex.Unlock(); assert( result == MutexErrors::Success ); } - const unsigned int gotValue = thing.GetValue(); + const uintptr_t gotValue = thing.GetValue(); assert( gotValue != value ); (void)gotValue; } @@ -313,7 +313,7 @@ cout << "Starting MultiThreadTryLockTest." << endl; char ender; - static const unsigned int threadCount = 3; + static const uintptr_t threadCount = 3; Thing::Init( 0 ); volatile Thing & thing = Thing::GetIt(); volatile SleepMutex & mutex = thing.GetMutex(); @@ -330,13 +330,13 @@ cout << endl << "Doing multi-threaded TryLock test. This test should not deadlock." << endl; cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( TryLockThread, p ); } pool.JoinAll(); - const unsigned int value = thing.GetValue(); + const uintptr_t value = thing.GetValue(); assert( value == threadCount ); } @@ -368,7 +368,7 @@ cout << endl << "Doing thread-safe value test. This test should pass and not deadlock." << endl; cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( ValueSafeThread, p ); @@ -401,7 +401,7 @@ bool RandomizeMutexOrder( LevelMutexInfo::MutexContainer & mutexes ) { - unsigned int count = mutexes.size(); + const size_t count = mutexes.size(); if ( count < 2 ) return false; @@ -409,7 +409,7 @@ for ( unsigned int ii = 0; ii < count; ++ii ) { volatile LevelMutexInfo * mutex = nullptr; - const unsigned int sizeNow = mutexes.size(); + const size_t sizeNow = mutexes.size(); if ( 1 < sizeNow ) { unsigned int index = ( ::rand() % sizeNow ); @@ -542,7 +542,7 @@ void * MultiLockSafeThread( void * p ) { - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); LevelMutexInfo::MutexContainer mutexes( thingCount ); volatile Thing * thing = nullptr; unsigned int jj = 0; @@ -618,7 +618,7 @@ void * MultiLockUnsafeThread( void * p ) { - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); Thing * thing = nullptr; unsigned int jj = 0; unsigned int tests = 0; @@ -683,7 +683,7 @@ char ender; Thing::MakePool( thingCount ); - const unsigned int threadCount = 8; + const uintptr_t threadCount = 8; TestResults::Create( threadCount ); { @@ -691,7 +691,7 @@ cout << endl << "Doing thread-safe multi-lock test. This test should pass and not deadlock." << endl; cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( MultiLockSafeThread, p ); @@ -706,7 +706,7 @@ TestResults::GetIt()->Reset( threadCount ); cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( MultiLockUnsafeThread, p ); @@ -725,7 +725,7 @@ void * MultiLockRandomSafeThread( void * p ) { - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); unsigned int testCount = 0; unsigned int failCount = 0; volatile Thing * thing = nullptr; @@ -751,7 +751,7 @@ assert( nullptr != thing ); pool.push_back( thing ); } - const unsigned int poolCount = pool.size(); + const size_t poolCount = pool.size(); mutexes.clear(); for ( jj = 0; jj < poolCount; ++jj ) @@ -795,7 +795,7 @@ void * MultiLockRandomUnsafeThread( void * p ) { - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); unsigned int testCount = 0; unsigned int failCount = 0; Thing * thing = nullptr; @@ -819,7 +819,7 @@ assert( nullptr != thing ); pool.push_back( thing ); } - const unsigned int poolCount = pool.size(); + const size_t poolCount = pool.size(); for ( jj = 0; jj < poolCount; ++jj ) { @@ -857,7 +857,7 @@ char ender; Thing::MakePool( thingCount ); - const unsigned int threadCount = 8; + const uintptr_t threadCount = 8; TestResults::Create( threadCount ); { @@ -865,7 +865,7 @@ cout << endl << "Doing thread-safe random multi-lock test. This test should pass and not deadlock." << endl; cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( MultiLockRandomSafeThread, p ); @@ -880,7 +880,7 @@ TestResults::GetIt()->Reset( threadCount ); cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( MultiLockRandomUnsafeThread, p ); @@ -900,7 +900,7 @@ void * SafeHierarchyTest( void * p ) { - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); volatile LevelThing * thing = nullptr; unsigned int testCount = 0; unsigned int failCount = 0; @@ -949,7 +949,7 @@ void * UnsafeHierarchyTest( void * p ) { - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); LevelThing * thing = nullptr; unsigned int testCount = 0; unsigned int failCount = 0; @@ -997,7 +997,7 @@ char ender; LevelThing::MakePool( thingCount ); - const unsigned int threadCount = 8; + const uintptr_t threadCount = 8; TestResults::Create( threadCount ); { @@ -1005,7 +1005,7 @@ cout << endl << "Doing thread-safe hierarchy test. This test should pass and not deadlock." << endl; cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( SafeHierarchyTest, p ); @@ -1020,7 +1020,7 @@ cout << "Press <Enter> key to start test. "; cin.get( ender ); TestResults::GetIt()->Reset( threadCount ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( UnsafeHierarchyTest, p ); @@ -1040,7 +1040,7 @@ void * SafeHierarchyMultiLockTest( void * p ) { - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); unsigned int testCount = 0; unsigned int failCount = 0; unsigned int totalTestCount = 0; @@ -1091,7 +1091,7 @@ void * UnsafeHierarchyMultiLockTest( void * p ) { - const unsigned int value = reinterpret_cast< unsigned int >( p ); + const uintptr_t value = reinterpret_cast< uintptr_t >( p ); unsigned int testCount = 0; unsigned int failCount = 0; unsigned int totalTestCount = 0; @@ -1137,7 +1137,7 @@ char ender; MultiLevelPool::MakePool( 10, thingCount ); - const unsigned int threadCount = 8; + const uintptr_t threadCount = 8; TestResults::Create( threadCount ); { @@ -1145,7 +1145,7 @@ cout << endl << "Doing thread-safe multilock hierarchy test. This test should pass and not deadlock." << endl; cout << "Press <Enter> key to start test. "; cin.get( ender ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( SafeHierarchyMultiLockTest, p ); @@ -1160,7 +1160,7 @@ cout << "Press <Enter> key to start test. "; cin.get( ender ); TestResults::GetIt()->Reset( threadCount ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + for ( uintptr_t ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); pool.Start( UnsafeHierarchyMultiLockTest, p ); Modified: trunk/test/LevelMutex/Thing.cpp =================================================================== --- trunk/test/LevelMutex/Thing.cpp 2013-06-23 01:14:58 UTC (rev 1185) +++ trunk/test/LevelMutex/Thing.cpp 2013-06-24 05:13:49 UTC (rev 1186) @@ -195,7 +195,7 @@ // ---------------------------------------------------------------------------- -void TestResults::SetResult( unsigned int threadIndex, unsigned int total, +void TestResults::SetResult( uintptr_t threadIndex, unsigned int total, unsigned int fails ) { assert( NULL != this ); @@ -361,7 +361,7 @@ // ---------------------------------------------------------------------------- -void Thing::Print( unsigned int value, unsigned int index, unsigned int startSize ) const volatile +void Thing::Print( uintptr_t value, unsigned int index, unsigned int startSize ) const volatile { assert( NULL != this ); MutexLocker locker( m_mutex ); @@ -374,7 +374,7 @@ // ---------------------------------------------------------------------------- -void Thing::Print( unsigned int value, unsigned int index, unsigned int startSize ) const +void Thing::Print( uintptr_t value, unsigned int index, unsigned int startSize ) const { assert( NULL != this ); switch ( startSize ) @@ -402,7 +402,7 @@ // ---------------------------------------------------------------------------- -void Thing::SetValue( unsigned int value ) volatile +void Thing::SetValue( uintptr_t value ) volatile { assert( NULL != this ); SingleThingLocker pSafeThis( *this, m_mutex ); @@ -506,7 +506,7 @@ // ---------------------------------------------------------------------------- -void LevelThing::SetValue( unsigned int value ) volatile +void LevelThing::SetValue( uintptr_t value ) volatile { assert( NULL != this ); MutexLocker locker( m_mutex, !m_mutex.IsLockedByCurrentThread() ); @@ -522,7 +522,7 @@ // ---------------------------------------------------------------------------- -void LevelThing::SetValue( unsigned int value ) +void LevelThing::SetValue( uintptr_t value ) { assert( NULL != this ); m_value = value; @@ -536,7 +536,7 @@ // ---------------------------------------------------------------------------- -bool LevelThing::DoValuesMatch( unsigned int value ) const volatile +bool LevelThing::DoValuesMatch( uintptr_t value ) const volatile { assert( NULL != this ); { @@ -555,7 +555,7 @@ // ---------------------------------------------------------------------------- -bool LevelThing::DoValuesMatch( unsigned int value ) const +bool LevelThing::DoValuesMatch( uintptr_t value ) const { assert( NULL != this ); if ( m_value != value ) @@ -592,7 +592,7 @@ // ---------------------------------------------------------------------------- -void SomeThing::SetValue( unsigned int value ) volatile +void SomeThing::SetValue( uintptr_t value ) volatile { assert( NULL != this ); SomeThingLocker pSafeThis( *this, m_mutex ); @@ -707,7 +707,7 @@ // ---------------------------------------------------------------------------- void CheckForMatchingValues( unsigned int & failCount, unsigned int & testCount, - unsigned int value, const SomeThingPool & pool ) + uintptr_t value, const SomeThingPool & pool ) { const unsigned int count = pool.size(); for ( unsigned int ii = 0; ii < count; ++ii ) @@ -723,7 +723,7 @@ // ---------------------------------------------------------------------------- void CheckForMatchingValues( unsigned int & failCount, unsigned int & testCount, - unsigned int value, const SomeThingPool & pool, bool locked ) + uintptr_t value, const SomeThingPool & pool, bool locked ) { if ( !locked ) { Modified: trunk/test/LevelMutex/Thing.hpp =================================================================== --- trunk/test/LevelMutex/Thing.hpp 2013-06-23 01:14:58 UTC (rev 1185) +++ trunk/test/LevelMutex/Thing.hpp 2013-06-24 05:13:49 UTC (rev 1186) @@ -27,7 +27,17 @@ #include <vector> +#if !defined(_MSC_VER) + #if defined(__sparc__) + #include <inttypes.h> + #else + #include <stdint.h> + #endif +#else + typedef unsigned int uintptr_t; +#endif + // ---------------------------------------------------------------------------- void GoToSleep( unsigned int milliSeconds ); @@ -89,7 +99,7 @@ void Reset( unsigned int threadCount ); - void SetResult( unsigned int threadIndex, unsigned int total, + void SetResult( uintptr_t threadIndex, unsigned int total, unsigned int fails ); void OutputResults( void ); @@ -142,17 +152,17 @@ static void DestroyPool( void ); - void Print( unsigned int value, unsigned int index, unsigned int startSize ) const volatile; + void Print( uintptr_t value, unsigned int index, unsigned int startSize ) const volatile; - void Print( unsigned int value, unsigned int index, unsigned int startSize ) const; + void Print( uintptr_t value, unsigned int index, unsigned int startSize ) const; - unsigned int GetValue( void ) const volatile { return m_value; } + uintptr_t GetValue( void ) const volatile { return m_value; } - unsigned int GetValue( void ) const { return m_value; } + uintptr_t GetValue( void ) const { return m_value; } - void SetValue( unsigned int value ) volatile; + void SetValue( uintptr_t value ) volatile; - void SetValue( unsigned int value ) { m_value = value; } + void SetValue( uintptr_t value ) { m_value = value; } inline volatile SleepMutex & GetMutex( void ) volatile { return m_mutex; } @@ -175,7 +185,7 @@ static TestResults s_results; mutable volatile SleepMutex m_mutex; - unsigned int m_value; + uintptr_t m_value; }; typedef ::std::vector< Thing * > UnsafeThingPool; @@ -219,17 +229,17 @@ void UnlockHierarchy( void ) volatile; - void SetValue( unsigned int value ) volatile; + void SetValue( uintptr_t value ) volatile; - void SetValue( unsigned int value ); + void SetValue( uintptr_t value ); - inline unsigned int GetValue( void ) const volatile { return m_value; } + inline uintptr_t GetValue( void ) const volatile { return m_value; } - inline unsigned int GetValue( void ) const { return m_value; } + inline uintptr_t GetValue( void ) const { return m_value; } - bool DoValuesMatch( unsigned int value ) const volatile; + bool DoValuesMatch( uintptr_t value ) const volatile; - bool DoValuesMatch( unsigned int value ) const; + bool DoValuesMatch( uintptr_t value ) const; inline volatile ::Loki::LevelMutexInfo & GetMutex( void ) volatile { return m_mutex; } @@ -251,7 +261,7 @@ mutable volatile SleepMutex m_mutex; const unsigned int m_place; - unsigned int m_value; + uintptr_t m_value; }; // ---------------------------------------------------------------------------- @@ -266,13 +276,13 @@ inline unsigned int GetLevel( void ) const volatile { return m_level; } - void SetValue( unsigned int value ) volatile; + void SetValue( uintptr_t value ) volatile; - void SetValue( unsigned int value ); + void SetValue( uintptr_t value ); - inline unsigned int GetValue( void ) const volatile { return m_value; } + inline uintptr_t GetValue( void ) const volatile { return m_value; } - inline unsigned int GetValue( void ) const { return m_value; } + inline uintptr_t GetValue( void ) const { return m_value; } inline volatile ::Loki::LevelMutexInfo & GetMutex( void ) volatile { return m_mutex; } @@ -287,7 +297,7 @@ mutable volatile SleepMutex m_mutex; const unsigned int m_place; const unsigned int m_level; - unsigned int m_value; + uintptr_t m_value; }; typedef ::std::vector< volatile SomeThing * > SomeThingPool; @@ -346,10 +356,10 @@ // ---------------------------------------------------------------------------- void CheckForMatchingValues( unsigned int & failCount, unsigned int & testCount, - unsigned int value, const SomeThingPool & pool ); + uintptr_t value, const SomeThingPool & pool ); void CheckForMatchingValues( unsigned int & failCount, unsigned int & testCount, - unsigned int value, const SomeThingPool & pool, bool locked ); + uintptr_t value, const SomeThingPool & pool, bool locked ); void MakePool( SomeThingPool & pool ); Modified: trunk/test/Lockable/main.cpp =================================================================== --- trunk/test/Lockable/main.cpp 2013-06-23 01:14:58 UTC (rev 1185) +++ trunk/test/Lockable/main.cpp 2013-06-24 05:13:49 UTC (rev 1186) @@ -36,6 +36,17 @@ #include "ThreadPool.hpp" +#if !defined(_MSC_VER) + #if defined(__sparc__) + #include <inttypes.h> + #else + #include <stdint.h> + #endif +#else + typedef unsigned int uintptr_t; +#endif + + using namespace std; static unsigned int g = 0; @@ -58,25 +69,25 @@ typedef ::Loki::ObjectLevelLockable< LockableObject > BaseClass; - explicit LockableObject( unsigned int index ) : + explicit LockableObject( uintptr_t index ) : BaseClass(), m_index( index ), m_value( ObjectCount ) {} ~LockableObject( void ) {} - unsigned int GetIndex( void ) const { return m_index; } + uintptr_t GetIndex( void ) const { return m_index; } - unsigned int GetValue( void ) const { return m_value; } + uintptr_t GetValue( void ) const { return m_value; } - void SetValue( unsigned int value ) { m_value = value; } + void SetValue( uintptr_t value ) { m_value = value; } void DoSomething( void ); - void Print( unsigned int threadIndex ); + void Print( uintptr_t threadIndex ); private: - const unsigned int m_index; - unsigned int m_value; + const uintptr_t m_index; + uintptr_t m_value; }; @@ -90,7 +101,7 @@ // ---------------------------------------------------------------------------- -void LockableObject::Print( unsigned int threadIndex ) +void LockableObject::Print( uintptr_t threadIndex ) { assert( NULL != this ); const char * result = ( threadIndex != m_value ) ? "Mismatch!" : ""; @@ -126,7 +137,7 @@ void * RunObjectTest( void * p ) { - const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + const uintptr_t threadIndex = reinterpret_cast< uintptr_t >( p ); assert( threadIndex < ThreadCount ); unsigned int failCount = 0; @@ -140,7 +151,7 @@ object->DoSomething(); object->Print( threadIndex ); object->DoSomething(); - const unsigned int value = object->GetValue(); + const uintptr_t value = object->GetValue(); if ( value != threadIndex ) ++failCount; } @@ -192,23 +203,23 @@ typedef ::Loki::ClassLevelLockable< LockableClass > BaseClass; - explicit LockableClass( unsigned int index ) : BaseClass(), m_index( index ) {} + explicit LockableClass( uintptr_t index ) : BaseClass(), m_index( index ) {} ~LockableClass( void ) {} - unsigned int GetIndex( void ) const { return m_index; } + uintptr_t GetIndex( void ) const { return m_index; } - void Print( unsigned int threadIndex ); + void Print( uintptr_t threadIndex ); private: /// Assignment operator is not implemented. LockableClass & operator = ( const LockableClass & ); - const unsigned int m_index; + const uintptr_t m_index; }; // ---------------------------------------------------------------------------- -void LockableClass::Print( unsigned int threadIndex ) +void LockableClass::Print( uintptr_t threadIndex ) { assert( NULL != this ); DO; ::Loki::Printf( "%u: %u: -----\n" )( m_index )( threadIndex ); @@ -245,7 +256,7 @@ void * RunClassTest( void * p ) { - const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + const uintptr_t threadIndex = reinterpret_cast< uintptr_t >( p ); assert( threadIndex < ThreadCount ); for ( unsigned int ii = 0; ii < ClassCount; ++ii ) Modified: trunk/test/SafeFormat/main.cpp =================================================================== --- trunk/test/SafeFormat/main.cpp 2013-06-23 01:14:58 UTC (rev 1185) +++ trunk/test/SafeFormat/main.cpp 2013-06-24 05:13:49 UTC (rev 1186) @@ -23,6 +23,17 @@ #include "ThreadPool.hpp" +#if !defined(_MSC_VER) + #if defined(__sparc__) + #include <inttypes.h> + #else + #include <stdint.h> + #endif +#else + typedef unsigned int uintptr_t; +#endif + + #if defined(_MSC_VER) #if _MSC_VER >= 1400 #define sprintf sprintf_s @@ -367,7 +378,7 @@ void * DoLokiFPrintfLoop( void * p ) { - const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + const uintptr_t threadIndex = reinterpret_cast< uintptr_t >( p ); for ( unsigned int loop = 0; loop < 10; ++loop ) { @@ -381,7 +392,7 @@ void * DoLokiPrintfLoop( void * p ) { - const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + const uintptr_t threadIndex = reinterpret_cast< uintptr_t >( p ); for ( unsigned int loop = 0; loop < 10; ++loop ) { @@ -395,7 +406,7 @@ void * DoStdOutLoop( void * p ) { - const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + const uintptr_t threadIndex = reinterpret_cast< uintptr_t >( p ); for ( unsigned int loop = 0; loop < 10; ++loop ) { @@ -409,7 +420,7 @@ void * DoCoutLoop( void * p ) { - const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + const uintptr_t threadIndex = reinterpret_cast< uintptr_t >( p ); for ( unsigned int loop = 0; loop < 10; ++loop ) { Modified: trunk/test/ThreadLocal/ThreadTests.cpp =================================================================== --- trunk/test/ThreadLocal/ThreadTests.cpp 2013-06-23 01:14:58 UTC (rev 1185) +++ trunk/test/ThreadLocal/ThreadTests.cpp 2013-06-24 05:13:49 UTC (rev 1186) @@ -37,11 +37,22 @@ #include <cassert> +#if !defined(_MSC_VER) + #if defined(__sparc__) + #include <inttypes.h> + #else + #include <stdint.h> + #endif +#else + typedef unsigned int uintptr_t; +#endif + + // ---------------------------------------------------------------------------- -typedef ::std::vector< unsigned int > IntVector; +typedef ::std::vector< uintptr_t > IntVector; -static LOKI_THREAD_LOCAL unsigned int StandaloneStaticValue = 0; +static LOKI_THREAD_LOCAL uintptr_t StandaloneStaticValue = 0; static const unsigned int ThreadCount = 4; @@ -49,7 +60,7 @@ IntVector & GetIntVector( void ) { - unsigned int v = 0; + uintptr_t v = 0; static IntVector addresses( ThreadCount, v ); return addresses; } @@ -59,7 +70,7 @@ void * AddToIntVector( void * p ) { assert( 0 == StandaloneStaticValue ); - const unsigned int ii = reinterpret_cast< unsigned int >( p ); + const uintptr_t ii = reinterpret_cast< uintptr_t >( p ); assert( 0 < ii ); assert( ii < ThreadCount + 1 ); StandaloneStaticValue = ii; @@ -86,10 +97,10 @@ IntVector & v = GetIntVector(); for ( unsigned int i1 = 0; i1 < ThreadCount - 1; ++i1 ) { - const unsigned int v1 = v[ i1 ]; + const uintptr_t v1 = v[ i1 ]; for ( unsigned int i2 = i1 + 1; i2 < ThreadCount; ++i2 ) { - const unsigned int v2 = v[ i2 ]; + const uintptr_t v2 = v[ i2 ]; if ( v1 == v2 ) { allDifferent = false; @@ -106,9 +117,9 @@ // ---------------------------------------------------------------------------- -unsigned int & GetFunctionThreadLocalValue( void ) +uintptr_t & GetFunctionThreadLocalValue( void ) { - static LOKI_THREAD_LOCAL unsigned int FunctionStaticValue = 0; + static LOKI_THREAD_LOCAL uintptr_t FunctionStaticValue = 0; return FunctionStaticValue; } @@ -116,9 +127,9 @@ void * ChangeFunctionStaticValue( void * p ) { - unsigned int & thatValue = GetFunctionThreadLocalValue(); + uintptr_t & thatValue = GetFunctionThreadLocalValue(); assert( 0 == thatValue ); - const unsigned int ii = reinterpret_cast< unsigned int >( p ); + const uintptr_t ii = reinterpret_cast< uintptr_t >( p ); assert( 0 < ii ); assert( ii < ThreadCount + 1 ); thatValue = ii + ThreadCount; @@ -151,10 +162,10 @@ bool allDifferent = true; for ( unsigned int i1 = 0; i1 < ThreadCount - 1; ++i1 ) { - const unsigned int v1 = v[ i1 ]; + const uintptr_t v1 = v[ i1 ]; for ( unsigned int i2 = i1 + 1; i2 < ThreadCount; ++i2 ) { - const unsigned int v2 = v[ i2 ]; + const uintptr_t v2 = v[ i2 ]; if ( v1 == v2 ) { allDifferent = false; @@ -175,24 +186,24 @@ { public: - static inline void SetValue( unsigned int value ) { ClassThreadLocal = value; } + static inline void SetValue( uintptr_t value ) { ClassThreadLocal = value; } - static inline unsigned int GetValue( void ) { return ClassThreadLocal; } + static inline uintptr_t GetValue( void ) { return ClassThreadLocal; } private: - static LOKI_THREAD_LOCAL unsigned int ClassThreadLocal; + static LOKI_THREAD_LOCAL uintptr_t ClassThreadLocal; }; -LOKI_THREAD_LOCAL unsigned int ThreadAware::ClassThreadLocal = 0; +LOKI_THREAD_LOCAL uintptr_t ThreadAware::ClassThreadLocal = 0; // ---------------------------------------------------------------------------- void * ChangeClassStaticValue( void * p ) { assert( ThreadAware::GetValue() == 0 ); - const unsigned int ii = reinterpret_cast< unsigned int >( p ); + const uintptr_t ii = reinterpret_cast< uintptr_t >( p ); assert( 0 < ii ); assert( ii < ThreadCount + 1 ); ThreadAware::SetValue( ii + 2 * ThreadCount ); @@ -225,10 +236,10 @@ bool allDifferent = true; for ( unsigned int i1 = 0; i1 < ThreadCount - 1; ++i1 ) { - const unsigned int v1 = v[ i1 ]; + const uintptr_t v1 = v[ i1 ]; for ( unsigned int i2 = i1 + 1; i2 < ThreadCount; ++i2 ) { - const unsigned int v2 = v[ i2 ]; + const uintptr_t v2 = v[ i2 ]; if ( v1 == v2 ) { allDifferent = false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |