|
From: <ric...@us...> - 2011-10-03 05:01:23
|
Revision: 1132
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1132&view=rev
Author: rich_sposato
Date: 2011-10-03 05:01:16 +0000 (Mon, 03 Oct 2011)
Log Message:
-----------
Replaced tabs with spaces.
Modified Paths:
--------------
trunk/test/Lockable/main.cpp
Modified: trunk/test/Lockable/main.cpp
===================================================================
--- trunk/test/Lockable/main.cpp 2011-10-03 04:56:54 UTC (rev 1131)
+++ trunk/test/Lockable/main.cpp 2011-10-03 05:01:16 UTC (rev 1132)
@@ -33,11 +33,11 @@
#include <iostream>
#include <loki/SafeFormat.h>
-#include "ThreadPool.hpp"
+#include "ThreadPool.hpp"
-
-using namespace std;
+using namespace std;
+
static unsigned int g = 0;
#define DO for(int i=0; i<10000000; i++) g++;
@@ -56,27 +56,27 @@
{
public:
- typedef ::Loki::ObjectLevelLockable< LockableObject > BaseClass;
+ typedef ::Loki::ObjectLevelLockable< LockableObject > BaseClass;
- explicit LockableObject( unsigned int index ) :
- BaseClass(), m_index( index ), m_value( ObjectCount ) {}
+ explicit LockableObject( unsigned int index ) :
+ BaseClass(), m_index( index ), m_value( ObjectCount ) {}
- ~LockableObject( void ) {}
+ ~LockableObject( void ) {}
- unsigned int GetIndex( void ) const { return m_index; }
+ unsigned int GetIndex( void ) const { return m_index; }
- unsigned int GetValue( void ) const { return m_value; }
+ unsigned int GetValue( void ) const { return m_value; }
- void SetValue( unsigned int value ) { m_value = value; }
+ void SetValue( unsigned int value ) { m_value = value; }
- void DoSomething( void );
+ void DoSomething( void );
- void Print( unsigned int threadIndex );
+ void Print( unsigned int threadIndex );
private:
- const unsigned int m_index;
- unsigned int m_value;
+ const unsigned int m_index;
+ unsigned int m_value;
};
@@ -84,18 +84,20 @@
void LockableObject::DoSomething( void)
{
- assert( NULL != this );
- DO;
+ assert( NULL != this );
+ DO;
}
// ----------------------------------------------------------------------------
void LockableObject::Print( unsigned int threadIndex )
{
- assert( NULL != this );
- const char * message = ( threadIndex != m_value ) ? "Mismatch!" : "";
- ::Loki::Printf( "Object: [%u] Thread: [%u] Value: [%u] %s\n" )
- ( m_index )( threadIndex )( m_value )( message );
+ assert( NULL != this );
+ const char * result = ( threadIndex != m_value ) ? "Mismatch!" : "";
+ ::std::string message;
+ ::Loki::SPrintf( message, "Object: [%u] Thread: [%u] Value: [%u] %s\n" )
+ ( m_index )( threadIndex )( m_value )( result );
+ cout << message;
}
// ----------------------------------------------------------------------------
@@ -104,20 +106,20 @@
LockableObjects & GetLockableObjects( void )
{
- static LockableObjects objects;
- return objects;
+ static LockableObjects objects;
+ return objects;
}
// ----------------------------------------------------------------------------
LockableObject * GetLockableObject( unsigned int index )
{
- LockableObjects & objects = GetLockableObjects();
- if ( objects.size() <= index )
- return NULL;
+ LockableObjects & objects = GetLockableObjects();
+ if ( objects.size() <= index )
+ return NULL;
- LockableObject * object = objects[ index ];
- return object;
+ LockableObject * object = objects[ index ];
+ return object;
}
// ----------------------------------------------------------------------------
@@ -127,40 +129,40 @@
const unsigned int threadIndex = reinterpret_cast< unsigned int >( p );
assert( threadIndex < ThreadCount );
- unsigned int failCount = 0;
- for ( unsigned int ii = 0; ii < ObjectCount; ++ii )
- {
- LockableObject * object = GetLockableObject( ii );
- assert( NULL != object );
- LockableObject::Lock lock( *object );
- (void)lock;
- object->SetValue( threadIndex );
- object->DoSomething();
- object->Print( threadIndex );
- object->DoSomething();
- const unsigned int value = object->GetValue();
- if ( value != threadIndex )
- ++failCount;
- }
+ unsigned int failCount = 0;
+ for ( unsigned int ii = 0; ii < ObjectCount; ++ii )
+ {
+ LockableObject * object = GetLockableObject( ii );
+ assert( NULL != object );
+ LockableObject::Lock lock( *object );
+ (void)lock;
+ object->SetValue( threadIndex );
+ object->DoSomething();
+ object->Print( threadIndex );
+ object->DoSomething();
+ const unsigned int value = object->GetValue();
+ if ( value != threadIndex )
+ ++failCount;
+ }
- FailCounts[ threadIndex ] = failCount;
+ FailCounts[ threadIndex ] = failCount;
- return NULL;
+ return NULL;
}
// ----------------------------------------------------------------------------
void DoObjectLockTest( void )
{
- cout << "Starting DoObjectLockTest" << endl;
+ cout << "Starting DoObjectLockTest" << endl;
- LockableObjects & objects = GetLockableObjects();
- objects.reserve( ObjectCount );
- for ( unsigned int ii = 0; ii < ObjectCount; ++ii )
- {
- LockableObject * object = new LockableObject( ii );
- objects.push_back( object );
- }
+ LockableObjects & objects = GetLockableObjects();
+ objects.reserve( ObjectCount );
+ for ( unsigned int ii = 0; ii < ObjectCount; ++ii )
+ {
+ LockableObject * object = new LockableObject( ii );
+ objects.push_back( object );
+ }
{
ThreadPool pool;
@@ -169,17 +171,17 @@
pool.Join();
}
- unsigned int totalFails = 0;
- for ( unsigned int ii = 0; ii < ThreadCount; ++ii )
- {
- const unsigned int failCount = FailCounts[ ii ];
- ::Loki::Printf( "Thread: [%u] Failures: [%u]\n" )( ii )( failCount );
- totalFails += failCount;
- }
- const char * result = ( 0 == totalFails ) ? "Passed" : "FAILED";
+ unsigned int totalFails = 0;
+ for ( unsigned int ii = 0; ii < ThreadCount; ++ii )
+ {
+ const unsigned int failCount = FailCounts[ ii ];
+ ::Loki::Printf( "Thread: [%u] Failures: [%u]\n" )( ii )( failCount );
+ totalFails += failCount;
+ }
+ const char * result = ( 0 == totalFails ) ? "Passed" : "FAILED";
- cout << "Finished DoObjectLockTest. Total Fails: " << totalFails << " Result: "
- << result << endl;
+ cout << "Finished DoObjectLockTest. Total Fails: " << totalFails << " Result: "
+ << result << endl;
}
// ----------------------------------------------------------------------------
@@ -188,31 +190,33 @@
{
public:
- typedef ::Loki::ClassLevelLockable< LockableClass > BaseClass;
+ typedef ::Loki::ClassLevelLockable< LockableClass > BaseClass;
- explicit LockableClass( unsigned int index ) : BaseClass(), m_index( index ) {}
+ explicit LockableClass( unsigned int index ) : BaseClass(), m_index( index ) {}
- ~LockableClass( void ) {}
+ ~LockableClass( void ) {}
- unsigned int GetIndex( void ) const { return m_index; }
+ unsigned int GetIndex( void ) const { return m_index; }
- void Print( unsigned int threadIndex );
+ void Print( unsigned int threadIndex );
private:
- const unsigned int m_index;
+ /// Assignment operator is not implemented.
+ LockableClass & operator = ( const LockableClass & );
+ const unsigned int m_index;
};
// ----------------------------------------------------------------------------
void LockableClass::Print( unsigned int threadIndex )
{
- assert( NULL != this );
- DO; ::Loki::Printf( "%u: %u: -----\n" )( m_index )( threadIndex );
- DO; ::Loki::Printf( "%u: %u: ----\n" )( m_index )( threadIndex );
- DO; ::Loki::Printf( "%u: %u: ---\n" )( m_index )( threadIndex );
- DO; ::Loki::Printf( "%u: %u: --\n" )( m_index )( threadIndex );
- DO; ::Loki::Printf( "%u: %u: -\n" )( m_index )( threadIndex );
- DO; ::Loki::Printf( "%u: %u: \n" )( m_index )( threadIndex );
+ assert( NULL != this );
+ DO; ::Loki::Printf( "%u: %u: -----\n" )( m_index )( threadIndex );
+ DO; ::Loki::Printf( "%u: %u: ----\n" )( m_index )( threadIndex );
+ DO; ::Loki::Printf( "%u: %u: ---\n" )( m_index )( threadIndex );
+ DO; ::Loki::Printf( "%u: %u: --\n" )( m_index )( threadIndex );
+ DO; ::Loki::Printf( "%u: %u: -\n" )( m_index )( threadIndex );
+ DO; ::Loki::Printf( "%u: %u:\n" )( m_index )( threadIndex );
}
// ----------------------------------------------------------------------------
@@ -221,20 +225,20 @@
LockableClasses & GetLockableClasses( void )
{
- static LockableClasses objects;
- return objects;
+ static LockableClasses objects;
+ return objects;
}
// ----------------------------------------------------------------------------
LockableClass * GetLockableClass( unsigned int index )
{
- LockableClasses & objects = GetLockableClasses();
- if ( objects.size() <= index )
- return NULL;
+ LockableClasses & objects = GetLockableClasses();
+ if ( objects.size() <= index )
+ return NULL;
- LockableClass * object = objects[ index ];
- return object;
+ LockableClass * object = objects[ index ];
+ return object;
}
// ----------------------------------------------------------------------------
@@ -244,31 +248,31 @@
const unsigned int threadIndex = reinterpret_cast< unsigned int >( p );
assert( threadIndex < ThreadCount );
- for ( unsigned int ii = 0; ii < ClassCount; ++ii )
- {
- LockableClass * object = GetLockableClass( ii );
- assert( NULL != object );
- LockableClass::Lock lock( *object );
- (void)lock;
- object->Print( threadIndex );
- }
+ for ( unsigned int ii = 0; ii < ClassCount; ++ii )
+ {
+ LockableClass * object = GetLockableClass( ii );
+ assert( NULL != object );
+ LockableClass::Lock lock( *object );
+ (void)lock;
+ object->Print( threadIndex );
+ }
- return NULL;
+ return NULL;
}
// ----------------------------------------------------------------------------
void DoClassLockTest( void )
{
- cout << "Starting DoClassLockTest" << endl;
+ cout << "Starting DoClassLockTest" << endl;
- LockableClasses & objects = GetLockableClasses();
- objects.reserve( ClassCount );
- for ( unsigned int ii = 0; ii < ClassCount; ++ii )
- {
- LockableClass * object = new LockableClass( ii );
- objects.push_back( object );
- }
+ LockableClasses & objects = GetLockableClasses();
+ objects.reserve( ClassCount );
+ for ( unsigned int ii = 0; ii < ClassCount; ++ii )
+ {
+ LockableClass * object = new LockableClass( ii );
+ objects.push_back( object );
+ }
{
ThreadPool pool;
@@ -277,24 +281,24 @@
pool.Join();
}
- cout << "Finished DoClassLockTest" << endl;
+ cout << "Finished DoClassLockTest" << endl;
}
// ----------------------------------------------------------------------------
-
+
int main( int argc, const char * const argv[] )
{
(void)argc;
(void)argv;
- char ender;
+ char ender;
- DoObjectLockTest();
+ DoObjectLockTest();
cout << "Press <Enter> key to continue. ";
- cin.get( ender );
+ cin.get( ender );
- DoClassLockTest();
+ DoClassLockTest();
cout << "Press <Enter> key to finish. ";
- cin.get( ender );
+ cin.get( ender );
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|