You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(80) |
Aug
(36) |
Sep
(120) |
Oct
(89) |
Nov
(57) |
Dec
(22) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(308) |
Feb
(66) |
Mar
(88) |
Apr
(54) |
May
(43) |
Jun
(40) |
Jul
(33) |
Aug
(1) |
Sep
(7) |
Oct
(65) |
Nov
(19) |
Dec
(10) |
2007 |
Jan
(5) |
Feb
(8) |
Mar
(7) |
Apr
|
May
(7) |
Jun
|
Jul
(5) |
Aug
(3) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
(5) |
Jun
(21) |
Jul
(27) |
Aug
(6) |
Sep
|
Oct
(1) |
Nov
(5) |
Dec
(10) |
2009 |
Jan
(67) |
Feb
(3) |
Mar
(26) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
(2) |
Sep
(10) |
Oct
(18) |
Nov
(20) |
Dec
(3) |
2010 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(9) |
Oct
(3) |
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(7) |
Jul
|
Aug
|
Sep
(39) |
Oct
(43) |
Nov
(7) |
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(7) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <ric...@us...> - 2011-10-07 07:06:07
|
Revision: 1141 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1141&view=rev Author: rich_sposato Date: 2011-10-07 07:06:01 +0000 (Fri, 07 Oct 2011) Log Message: ----------- Added 4 void declaration lines to remove compiler warning. Modified Paths: -------------- trunk/test/SafeFormat/main.cpp Modified: trunk/test/SafeFormat/main.cpp =================================================================== --- trunk/test/SafeFormat/main.cpp 2011-10-07 07:04:46 UTC (rev 1140) +++ trunk/test/SafeFormat/main.cpp 2011-10-07 07:06:01 UTC (rev 1141) @@ -213,6 +213,7 @@ } catch ( const ::std::logic_error & ex ) { + (void)ex; assert( true ); } result.clear(); @@ -225,6 +226,7 @@ } catch ( const ::std::logic_error & ex ) { + (void)ex; assert( true ); } result.clear(); @@ -237,6 +239,7 @@ } catch ( const ::std::logic_error & ex ) { + (void)ex; assert( true ); } result.clear(); @@ -249,6 +252,7 @@ } catch ( const ::std::logic_error & ex ) { + (void)ex; assert( true ); } result.clear(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-07 07:04:52
|
Revision: 1140 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1140&view=rev Author: rich_sposato Date: 2011-10-07 07:04:46 +0000 (Fri, 07 Oct 2011) Log Message: ----------- Added lines to make type of stdout clear to compiler. Modified Paths: -------------- trunk/src/SafeFormat.cpp Modified: trunk/src/SafeFormat.cpp =================================================================== --- trunk/src/SafeFormat.cpp 2011-10-04 23:46:30 UTC (rev 1139) +++ trunk/src/SafeFormat.cpp 2011-10-07 07:04:46 UTC (rev 1140) @@ -69,7 +69,8 @@ ::std::string buffer; const PrintfState< ::std::string &, char > state1( buffer, format ); ::std::fwrite( buffer.c_str(), 1, buffer.size(), stdout ); - PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( stdout ); + ::std::FILE * f = stdout; + PrintfState< std::FILE *, char > printState2( state1.ChangeDevice( f ) ); return printState2; } @@ -77,7 +78,8 @@ ::std::string buffer; const PrintfState< ::std::string &, char > state1( buffer, format.c_str() ); ::std::fwrite( buffer.c_str(), 1, buffer.size(), stdout ); - PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( stdout ); + ::std::FILE * f = stdout; + PrintfState< std::FILE *, char > printState2( state1.ChangeDevice( f ) ); return printState2; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-04 23:46:36
|
Revision: 1139 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1139&view=rev Author: rich_sposato Date: 2011-10-04 23:46:30 +0000 (Tue, 04 Oct 2011) Log Message: ----------- Added tests for bug 2694067. Modified Paths: -------------- trunk/test/SafeFormat/SafeFormat.cbp trunk/test/SafeFormat/main.cpp Added Paths: ----------- trunk/test/SafeFormat/ThreadPool.cpp trunk/test/SafeFormat/ThreadPool.hpp Modified: trunk/test/SafeFormat/SafeFormat.cbp =================================================================== --- trunk/test/SafeFormat/SafeFormat.cbp 2011-10-04 23:42:48 UTC (rev 1138) +++ trunk/test/SafeFormat/SafeFormat.cbp 2011-10-04 23:46:30 UTC (rev 1139) @@ -6,23 +6,24 @@ <Option compiler="cygwin" /> <Build> <Target title="Debug_GCC"> - <Option output="bin\Debug_GCC\SafeFormat" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="bin/Debug_GCC/SafeFormat" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> + <Add option="-g" /> <Add option="-W" /> - <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki_D.a" /> + <Add library="../../lib/GCC/Loki_D.a" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="bin\Release_GCC\SafeFormat" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="bin/Release_GCC/SafeFormat" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -30,31 +31,31 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki.a" /> + <Add library="../../lib/GCC/Loki.a" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="bin\Debug_Cygwin\SafeFormat" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_Cygwin\" /> + <Option output="bin/Debug_Cygwin/SafeFormat" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki_D.a" /> + <Add library="../../lib/Cygwin/Loki_D.a" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="bin\Release_Cygwin\SafeFormat" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_Cygwin\" /> + <Option output="bin/Release_Cygwin/SafeFormat" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> @@ -62,14 +63,16 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki.a" /> + <Add library="../../lib/Cygwin/Loki.a" /> </Linker> </Target> </Build> + <Unit filename="ThreadPool.cpp" /> + <Unit filename="ThreadPool.hpp" /> <Unit filename="main.cpp" /> <Extensions> <code_completion /> Added: trunk/test/SafeFormat/ThreadPool.cpp =================================================================== --- trunk/test/SafeFormat/ThreadPool.cpp (rev 0) +++ trunk/test/SafeFormat/ThreadPool.cpp 2011-10-04 23:46:30 UTC (rev 1139) @@ -0,0 +1,112 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// ThreadLocal test program for The Loki Library +// Copyright (c) 2009 by Richard Sposato +// The copyright on this file is protected under the terms of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- + +#include "ThreadPool.hpp" + +#include <sstream> + +// ---------------------------------------------------------------------------- + +Thread::Thread( CallFunction func, void * parm ) + : pthread_() + , func_( func ) + , parm_( parm ) +{ +} + +// ---------------------------------------------------------------------------- + +void Thread::AssignTask( CallFunction func, void * parm ) +{ + func_ = func; + parm_ = parm; +} + +// ---------------------------------------------------------------------------- + +int Thread::Start( void ) +{ + return LOKI_pthread_create( &pthread_, NULL, func_, parm_ ); +} + +// ---------------------------------------------------------------------------- + +int Thread::WaitForThread( void ) const +{ + return LOKI_pthread_join( pthread_ ); +} + +// ---------------------------------------------------------------------------- + +ThreadPool::ThreadPool( void ) : m_threads() +{ +} + +// ---------------------------------------------------------------------------- + +ThreadPool::~ThreadPool( void ) +{ + for ( size_t ii = 0; ii < m_threads.size(); ++ii ) + { + delete m_threads.at(ii); + } +} + +// ---------------------------------------------------------------------------- + +void ThreadPool::Create( size_t threadCount, Thread::CallFunction function ) +{ + for( size_t ii = 0; ii < threadCount; ii++ ) + { + ::std::stringstream buffer; + Thread * thread = new Thread( function, + reinterpret_cast< void * >( ii + 1 ) ); + m_threads.push_back( thread ); + } +} + +// ---------------------------------------------------------------------------- + +void ThreadPool::Start( void ) +{ + for ( size_t ii = 0; ii < m_threads.size(); ii++ ) + { + ::std::stringstream buffer; + m_threads.at( ii )->Start(); + } +} + +// ---------------------------------------------------------------------------- + +void ThreadPool::Join( void ) const +{ + for ( size_t ii = 0; ii < m_threads.size(); ii++ ) + m_threads.at( ii )->WaitForThread(); +} + +// ---------------------------------------------------------------------------- Added: trunk/test/SafeFormat/ThreadPool.hpp =================================================================== --- trunk/test/SafeFormat/ThreadPool.hpp (rev 0) +++ trunk/test/SafeFormat/ThreadPool.hpp 2011-10-04 23:46:30 UTC (rev 1139) @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// ThreadLocal test program for The Loki Library +// Copyright (c) 2009 by Richard Sposato +// The copyright on this file is protected under the terms of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + + +// ---------------------------------------------------------------------------- + +#include <vector> + +#if !defined( NULL ) + #define NULL 0 +#endif + +// define nullptr even though new compilers will have this keyword just so we +// have a consistent and easy way of identifying which uses of 0 mean null. +#if !defined( nullptr ) + #define nullptr NULL +#endif + +#if defined(_WIN32) + + #include <process.h> + #include <windows.h> + + typedef unsigned int ( WINAPI * ThreadFunction_ )( void * ); + + #define LOKI_pthread_t HANDLE + + #define LOKI_pthread_create( handle, attr, func, arg ) \ + ( int )( ( *handle = ( HANDLE ) _beginthreadex ( NULL, 0, ( ThreadFunction_ )func, arg, 0, NULL ) ) == NULL ) + + #define LOKI_pthread_join( thread ) \ + ( ( WaitForSingleObject( ( thread ), INFINITE ) != WAIT_OBJECT_0 ) || !CloseHandle( thread ) ) + +#else + + #include <pthread.h> + + #define LOKI_pthread_t \ + pthread_t + #define LOKI_pthread_create(handle,attr,func,arg) \ + pthread_create(handle,attr,func,arg) + #define LOKI_pthread_join(thread) \ + pthread_join(thread, NULL) + +#endif + +// ---------------------------------------------------------------------------- + +class Thread +{ +public: + + typedef void * ( * CallFunction )( void * ); + + Thread( CallFunction func, void * parm ); + + void AssignTask( CallFunction func, void * parm ); + + int Start( void ); + + int WaitForThread( void ) const; + +private: + + LOKI_pthread_t pthread_; + + CallFunction func_; + + void * parm_; + +}; + +// ---------------------------------------------------------------------------- + +class ThreadPool +{ +public: + + ThreadPool( void ); + + ~ThreadPool( void ); + + void Create( size_t threadCount, Thread::CallFunction function ); + + void Start( void ); + + void Join( void ) const; + +private: + + typedef ::std::vector< Thread * > Threads; + + Threads m_threads; +}; + +// ---------------------------------------------------------------------------- Modified: trunk/test/SafeFormat/main.cpp =================================================================== --- trunk/test/SafeFormat/main.cpp 2011-10-04 23:42:48 UTC (rev 1138) +++ trunk/test/SafeFormat/main.cpp 2011-10-04 23:46:30 UTC (rev 1139) @@ -20,7 +20,9 @@ #include <cstdlib> #include "../SmallObj/timer.h" +#include "ThreadPool.hpp" + #if defined(_MSC_VER) #if _MSC_VER >= 1400 #define sprintf sprintf_s @@ -146,7 +148,7 @@ t.start(); for (int i=loop; i > 0; --i) - Printf("Hey, %u frobnicators and %u twiddlicators\n")(i)(i); + ::Loki::Printf("Hey, %u frobnicators and %u twiddlicators\n")(i)(i); t.stop(); int t_Printf = t.t(); @@ -354,11 +356,126 @@ } } - cout << endl << "Finished RandomTest" << endl; + cout << "Finished RandomTest" << endl; } // ---------------------------------------------------------------------------- +void * DoLokiPrintfLoop( void * p ) +{ + const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + + for ( unsigned int loop = 0; loop < 10; ++loop ) + { + ::Loki::Printf( "Loop: [%u] Thread: [%u]\n" )( loop )( threadIndex ); + } + + return 0; +} + +// ---------------------------------------------------------------------------- + +void * DoLokiFPrintfLoop( void * p ) +{ + const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + + for ( unsigned int loop = 0; loop < 10; ++loop ) + { + ::Loki::FPrintf( cout, "Loop: [%u] Thread: [%u]\n" )( loop )( threadIndex ); + } + + return 0; +} + +// ---------------------------------------------------------------------------- + +void * DoCoutLoop( void * p ) +{ + const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + + for ( unsigned int loop = 0; loop < 10; ++loop ) + { + cout << "Loop: [" << loop << "] Thread: [" << threadIndex << "]\n"; + } + + return 0; +} + +// ---------------------------------------------------------------------------- + +void * DoStdOutLoop( void * p ) +{ + const unsigned int threadIndex = reinterpret_cast< unsigned int >( p ); + + for ( unsigned int loop = 0; loop < 10; ++loop ) + { + printf( "Loop: [%d] Thread: [%d]\n", loop, threadIndex ); + } + + return 0; +} + +// ---------------------------------------------------------------------------- + +void AtomicTest( void ) +{ + char ender; + + cout << "Starting Loki::Printf AtomicTest" << endl; + { + ThreadPool pool; + pool.Create( 20, &DoLokiPrintfLoop ); + pool.Start(); + pool.Join(); + } + cout << "Finished Loki::Printf AtomicTest." << endl; + cout << "If the output lines up in neat columns, the test passed." << endl; + cout << "If the output is not in columns, then the test failed." << endl; + cout << "Press <Enter> key to continue. "; + cin.get( ender ); + + cout << "Starting Loki::FPrintf AtomicTest" << endl; + { + ThreadPool pool; + pool.Create( 20, &DoLokiFPrintfLoop ); + pool.Start(); + pool.Join(); + } + cout << "Finished Loki::FPrintf AtomicTest." << endl; + cout << "If the output lines up in neat columns, the test passed." << endl; + cout << "If the output is not in columns, then the test failed." << endl; + cout << "Press <Enter> key to continue. "; + cin.get( ender ); + + cout << "Starting stdout AtomicTest" << endl; + { + ThreadPool pool; + pool.Create( 20, &DoStdOutLoop ); + pool.Start(); + pool.Join(); + } + cout << "Finished stdout AtomicTest." << endl; + cout << "If the output lines up in neat columns, your compiler implements printf correctly." << endl; + cout << "If the output is not in columns, then your compiler implements printf incorrectly." << endl; + cout << "Press <Enter> key to continue. "; + cin.get( ender ); + + cout << "Starting cout AtomicTest" << endl; + { + ThreadPool pool; + pool.Create( 20, &DoCoutLoop ); + pool.Start(); + pool.Join(); + } + cout << "Finished cout AtomicTest." << endl; + cout << "If the output lines up in neat columns, your compiler implements cout correctly." << endl; + cout << "If the output is not in columns, then your compiler implements cout incorrectly." << endl; + cout << "Press <Enter> key to continue. "; + cin.get( ender ); +} + +// ---------------------------------------------------------------------------- + class CommandLineArgs { public: @@ -371,6 +488,7 @@ inline bool DoSpeedTest( void ) const { return ( 0 < m_speedLoopCount ); } inline bool DoRandomTest( void ) const { return ( 0 < m_randomLoopCount ); } inline bool DoFormatTest( void ) const { return m_doFormatTest; } + inline bool DoAtomicTest( void ) const { return m_doAtomicTest; } inline bool DoShowHelp( void ) const { return m_showHelp; } void ShowHelp( void ) const; @@ -380,6 +498,7 @@ unsigned int m_speedLoopCount; unsigned int m_randomLoopCount; bool m_doFormatTest; + bool m_doAtomicTest; bool m_showHelp; const char * m_exeName; }; @@ -390,6 +509,7 @@ m_speedLoopCount( 0 ), m_randomLoopCount( 0 ), m_doFormatTest( false ), + m_doAtomicTest( false ), m_showHelp( false ), m_exeName( argv[0] ) { @@ -416,6 +536,7 @@ default: isValid = false; break; case 'h': m_showHelp = true; break; case 'f': m_doFormatTest = true; break; + case 'a': m_doAtomicTest = true; break; case 'r': { @@ -458,6 +579,7 @@ cout << "Usage: " << m_exeName << " [-h] [-f] [-r:#] [-s:#]" << endl; cout << " -h Show this help info and exit. Overrides all other options." << endl; cout << " -f Run formatting tests." << endl; + cout << " -a Run atomic tests." << endl; cout << " -r:# Run random tests for # of loops. # is a positive decimal value greater than 100." << endl; cout << " -s:# Run speed tests for # of loops. # is a positive decimal value greater than 100." << endl; } @@ -487,6 +609,10 @@ { FormatTest(); } + if ( args.DoAtomicTest() ) + { + AtomicTest(); + } } // ---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-04 23:42:54
|
Revision: 1138 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1138&view=rev Author: rich_sposato Date: 2011-10-04 23:42:48 +0000 (Tue, 04 Oct 2011) Log Message: ----------- Fixed bug 2694067. Modified Paths: -------------- trunk/include/loki/SafeFormat.h trunk/src/SafeFormat.cpp Modified: trunk/include/loki/SafeFormat.h =================================================================== --- trunk/include/loki/SafeFormat.h 2011-10-04 20:48:36 UTC (rev 1137) +++ trunk/include/loki/SafeFormat.h 2011-10-04 23:42:48 UTC (rev 1138) @@ -100,6 +100,21 @@ template <class Device, class Char> struct PrintfState { + + /** This constructor exists only to convert a PrintfState for one device type into a + PrintfState for another device type. It is not for public use. + */ + template < class Device2 > + PrintfState( Device2 & dev, const Char * format, size_t width, size_t prec, + unsigned int flags, LOKI_SAFEFORMAT_SIGNED_LONG result ) + : device_( dev ) + , format_( format ) + , width_( width ) + , prec_( prec ) + , flags_( flags ) + , result_( result ) { + } + PrintfState(Device dev, const Char * format) : device_(dev) , format_(format) @@ -113,6 +128,15 @@ ~PrintfState() { } + /** This function converts a PrintfState for one device type into a PrintfState for + another device type. It is not for public use. + */ + template < class Device2 > + PrintfState< Device2, Char > ChangeDevice( Device2 & device ) const + { + return PrintfState< Device2, Char >( device, format_, width_, prec_, flags_, result_ ); + } + #define LOKI_PRINTF_STATE_FORWARD(type) \ PrintfState& operator()(type par) {\ return (*this)(static_cast< LOKI_SAFEFORMAT_UNSIGNED_LONG >(par)); \ Modified: trunk/src/SafeFormat.cpp =================================================================== --- trunk/src/SafeFormat.cpp 2011-10-04 20:48:36 UTC (rev 1137) +++ trunk/src/SafeFormat.cpp 2011-10-04 23:42:48 UTC (rev 1138) @@ -66,27 +66,51 @@ PrintfState<std::FILE*, char> Printf(const char* format) { - return PrintfState<std::FILE*, char>(stdout, format); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format ); + ::std::fwrite( buffer.c_str(), 1, buffer.size(), stdout ); + PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( stdout ); + return printState2; } PrintfState<std::FILE*, char> Printf(const std::string& format) { - return PrintfState<std::FILE*, char>(stdout, format.c_str()); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format.c_str() ); + ::std::fwrite( buffer.c_str(), 1, buffer.size(), stdout ); + PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( stdout ); + return printState2; } PrintfState<std::FILE*, char> FPrintf(std::FILE* f, const char* format) { - return PrintfState<std::FILE*, char>(f, format); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format ); + ::std::fwrite( buffer.c_str(), 1, buffer.size(), f ); + PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( f ); + return printState2; } PrintfState<std::FILE*, char> FPrintf(std::FILE* f, const std::string& format) { - return PrintfState<std::FILE*, char>(f, format.c_str()); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format.c_str() ); + ::std::fwrite( buffer.c_str(), 1, buffer.size(), f ); + PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( f ); + return printState2; } PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const char* format) { - return PrintfState<std::ostream&, char>(f, format); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format ); + f.write( buffer.c_str(), buffer.size() ); + PrintfState< ::std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( f ); + return printState2; } PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const std::string& format) { - return PrintfState<std::ostream&, char>(f, format.c_str()); + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format.c_str() ); + f.write( buffer.c_str(), buffer.size() ); + PrintfState< std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( f ); + return printState2; } PrintfState<std::string&, char> SPrintf(std::string& s, const char* format) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-04 20:48:42
|
Revision: 1137 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1137&view=rev Author: rich_sposato Date: 2011-10-04 20:48:36 +0000 (Tue, 04 Oct 2011) Log Message: ----------- Fix for bug 2694073. Added calls to reserve so append won't resize as often. Modified Paths: -------------- trunk/src/SafeFormat.cpp Modified: trunk/src/SafeFormat.cpp =================================================================== --- trunk/src/SafeFormat.cpp 2011-10-04 00:52:09 UTC (rev 1136) +++ trunk/src/SafeFormat.cpp 2011-10-04 20:48:36 UTC (rev 1137) @@ -43,6 +43,11 @@ void write(std::string& s, const char* from, const char* to) { assert(from <= to); + const size_t addCount = to - from; + if ( s.capacity() <= s.size() + addCount ) + { + s.reserve( 2 * s.size() + addCount ); + } s.append(from, to); } @@ -85,10 +90,14 @@ } PrintfState<std::string&, char> SPrintf(std::string& s, const char* format) { + const size_t estimate = ::strlen( format ) + 128; + s.reserve( estimate ); return PrintfState<std::string&, char>(s, format); } PrintfState<std::string&, char> SPrintf(std::string& s, const std::string& format) { + const size_t estimate = format.size() + 128; + s.reserve( estimate ); return PrintfState<std::string&, char>(s, format.c_str()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-04 00:52:15
|
Revision: 1136 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1136&view=rev Author: rich_sposato Date: 2011-10-04 00:52:09 +0000 (Tue, 04 Oct 2011) Log Message: ----------- Added test for bugs 2792371 and 2694060. Cleaned up code. Modified Paths: -------------- trunk/test/SafeFormat/main.cpp Modified: trunk/test/SafeFormat/main.cpp =================================================================== --- trunk/test/SafeFormat/main.cpp 2011-10-04 00:50:00 UTC (rev 1135) +++ trunk/test/SafeFormat/main.cpp 2011-10-04 00:52:09 UTC (rev 1136) @@ -16,6 +16,8 @@ #include <iostream> #include <cassert> #include <utility> +#include <cctype> +#include <cstdlib> #include "../SmallObj/timer.h" @@ -104,157 +106,387 @@ assert(s == buf); } -int main(int argc, char** argv) -{ +// ---------------------------------------------------------------------------- - if (argc == 2) - { - // test speed +void test_dword() +{ + typedef signed int Int; + typedef unsigned int UInt; + typedef signed long Long; + typedef unsigned long ULong; + Int i(0); + UInt ui(0); + Long l(0); + ULong ul(0); + Printf("%d")(i); + Printf("%d")(ui); + Printf("%d")(l); + Printf("%d")(ul); +} - Timer t; +// ---------------------------------------------------------------------------- - int loop = atoi(argv[1]); +void SpeedTest( unsigned int loop ) +{ + cout << "Starting SpeedTest" << endl; - if(loop < 100) - loop = 100; + // test speed + Timer t; - t.start(); - for (int i=loop; i > 0; --i) - printf("Hey, %u frobnicators and %u twiddlicators\n",i, i); - t.stop(); - t.t100 = t.t(); - int t_printf = t.t(); + if(loop < 100) + loop = 100; + t.start(); + for (int i=loop; i > 0; --i) + printf("Hey, %u frobnicators and %u twiddlicators\n",i, i); + t.stop(); + t.t100 = t.t(); + int t_printf = t.t(); - t.start(); - for (int i=loop; i > 0; --i) - Printf("Hey, %u frobnicators and %u twiddlicators\n")(i)(i); - t.stop(); - int t_Printf = t.t(); + t.start(); + for (int i=loop; i > 0; --i) + Printf("Hey, %u frobnicators and %u twiddlicators\n")(i)(i); + t.stop(); + int t_Printf = t.t(); - t.start(); - for (int i=loop; i > 0; --i) - cout << "Hey, " << i << " frobnicators and " << i <<" twiddlicators\n"; - t.stop(); - int t_cout = t.t(); + t.start(); + for (int i=loop; i > 0; --i) + cout << "Hey, " << i << " frobnicators and " << i <<" twiddlicators\n"; + t.stop(); + int t_cout = t.t(); - Printf("\n\nElapsed time for %i outputs\n\n")(loop); - t.print(t_printf,"printf : "); - t.print(t_Printf,"Printf : "); - t.print(t_cout, "std::cout: "); + + Printf("\n\nElapsed time for %i outputs\n\n")(loop); + t.print(t_printf,"printf : "); + t.print(t_Printf,"Printf : "); + t.print(t_cout, "std::cout: "); + + cout << "Finished SpeedTest" << endl; +} + +// ---------------------------------------------------------------------------- + +void FormatTest( void ) +{ + cout << "Starting FormatTest" << endl; + + string result; + unsigned int i = 1; + signed short ss = 2; + float f = 3.4; + const char * message = " over here! "; + + const char * format = ""; + ::Loki::SPrintf( result, format ); + assert( result == format ); + result.clear(); + + format = "abc"; + ::Loki::SPrintf( result, format ); + assert( result == format ); + result.clear(); + + format = "%%"; + ::Loki::SPrintf( result, format ); + assert( result == "%" ); + result.clear(); + + format = "%d"; + ::Loki::SPrintf( result, format )( i ); + assert( result == "1" ); + result.clear(); + + format = "%s"; + ::Loki::SPrintf( result, format )( message ); + assert( result == message ); + result.clear(); + + format = "%d"; + try + { + ::Loki::SPrintf( result, format )( i )( message ); + assert( false ); } - else + catch ( const ::std::logic_error & ex ) { - //srand(time(0)); - srand(0); - printf("\nNumber of tests:\n"); - for (unsigned i = 0; ; ++i) + assert( true ); + } + result.clear(); + + format = "%d"; + try + { + ::Loki::SPrintf( result, format )( i )( message )( ss ); + assert( false ); + } + catch ( const ::std::logic_error & ex ) + { + assert( true ); + } + result.clear(); + + format = "%d"; + try + { + ::Loki::SPrintf( result, format )( i )( ss ); + assert( false ); + } + catch ( const ::std::logic_error & ex ) + { + assert( true ); + } + result.clear(); + + format = "%d"; + try + { + ::Loki::SPrintf( result, format )( i )( f ); + assert( false ); + } + catch ( const ::std::logic_error & ex ) + { + assert( true ); + } + result.clear(); + + cout << "Finished FormatTest" << endl; +} + +// ---------------------------------------------------------------------------- + +void RandomTest( unsigned int loopCount ) +{ + cout << "Starting RandomTest" << endl; + if ( loopCount < 100 ) + loopCount = 100; + + //srand(time(0)); + srand(0); + printf("\nNumber of tests:\n"); + for ( unsigned int i = 0; i < loopCount; ++i ) + { + printf("%u\r", i); + + // Generate a random string for the head + string lead = RandomString(100); + // This string will hold a random format specification + string formatSpec(lead + "|%"); + // Generate a random set of flags + static const string flags("-+0 #"); + size_t maxFlags = RandomInt(0u, flags.length() - 1); + for (size_t i = 0; i != maxFlags; ++i) { - printf("%u\r", i); + formatSpec += flags[RandomInt(0u, flags.length() - 1)]; + } + // Generate an optional random width + if (RandomInt(0, 1)) + { + const unsigned int width = RandomInt(0, 100); + char buf[4]; + sprintf(buf, "%u", width); + formatSpec += buf; + } + // Generate an optional random precision + if (RandomInt(0, 1)) + { + const unsigned int prec = RandomInt(0, 100); + char buf[4]; + sprintf(buf, "%u", prec); + formatSpec += '.'; + formatSpec += buf; + } - // Generate a random string for the head - string lead = RandomString(100); - // This string will hold a random format specification - string formatSpec(lead + "|%"); - // Generate a random set of flags - static const string flags("-+0 #"); - size_t maxFlags = RandomInt(0u, flags.length() - 1); - for (size_t i = 0; i != maxFlags; ++i) + // Generate a random type character + static const string type("cdeEfgGinopsuxX"); + + const char typeSpec = type[RandomInt(0u, type.size() - 1)]; + // Generate an optional type prefix + static const string prefix("hl"); + if (typeSpec != 's' && RandomInt(0, 1)) + { + formatSpec += prefix[RandomInt(0u, prefix.size() - 1)]; + } + formatSpec += typeSpec; + formatSpec += '|'; + formatSpec += RandomString(100); + + switch (typeSpec) + { + case 'c': + TestCase(formatSpec, RandomInt(1, 127)); + break; + case 'd': + case 'i': + case 'o': + case 'u': + case 'x': + case 'X': + //TestCase(formatSpec, RandomInt(-10000, 10000)); + // don't test negative values on 64bit systems, because + // snprintf does not support 64 Bit values + TestCase(formatSpec, RandomInt( -10000 * (sizeof(size_t)>4 ? 0 : 1) , 10000)); + break; + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + TestCase(formatSpec, + RandomInt(-10000, 10000) / double(RandomInt(1, 100))); + break; + case 'n': + break; + case 'p': { - formatSpec += flags[RandomInt(0u, flags.length() - 1)]; + void * p = malloc(RandomInt(1, 1000)); + TestCase(formatSpec, p); + free(p); } - // Generate an optional random width - if (RandomInt(0, 1)) - { - const unsigned int width = RandomInt(0, 100); - char buf[4]; - sprintf(buf, "%u", width); - formatSpec += buf; - } - // Generate an optional random precision - if (RandomInt(0, 1)) - { - const unsigned int prec = RandomInt(0, 100); - char buf[4]; - sprintf(buf, "%u", prec); - formatSpec += '.'; - formatSpec += buf; - } + break; + case 's': + TestCase(formatSpec, RandomString(100).c_str()); + break; + default: + assert(false); + break; + } + } - // Generate a random type character - static const string type("cdeEfgGinopsuxX"); + cout << endl << "Finished RandomTest" << endl; +} - const char typeSpec = type[RandomInt(0u, type.size() - 1)]; - // Generate an optional type prefix - static const string prefix("hl"); - if (typeSpec != 's' && RandomInt(0, 1)) +// ---------------------------------------------------------------------------- + +class CommandLineArgs +{ +public: + + CommandLineArgs( unsigned int argc, const char * argv[] ); + + inline unsigned int GetSpeedLoopCount( void ) const { return m_speedLoopCount; } + inline unsigned int GetRandomLoopCount( void ) const { return m_randomLoopCount; } + + inline bool DoSpeedTest( void ) const { return ( 0 < m_speedLoopCount ); } + inline bool DoRandomTest( void ) const { return ( 0 < m_randomLoopCount ); } + inline bool DoFormatTest( void ) const { return m_doFormatTest; } + inline bool DoShowHelp( void ) const { return m_showHelp; } + + void ShowHelp( void ) const; + +private: + + unsigned int m_speedLoopCount; + unsigned int m_randomLoopCount; + bool m_doFormatTest; + bool m_showHelp; + const char * m_exeName; +}; + +// ---------------------------------------------------------------------------- + +CommandLineArgs::CommandLineArgs( unsigned int argc, const char * argv[] ) : + m_speedLoopCount( 0 ), + m_randomLoopCount( 0 ), + m_doFormatTest( false ), + m_showHelp( false ), + m_exeName( argv[0] ) +{ + + if ( argc < 2 ) + { + m_showHelp = true; + return; + } + + bool isValid = true; + for ( unsigned int ii = 1; ( isValid ) && ( ii < argc ); ++ii ) + { + const char * arg = argv[ii]; + const unsigned int length = ::strlen( arg ); + if ( ( '-' != *arg ) || ( length < 2 ) ) + { + isValid = false; + break; + } + + switch ( arg[1] ) + { + default: isValid = false; break; + case 'h': m_showHelp = true; break; + case 'f': m_doFormatTest = true; break; + + case 'r': { - formatSpec += prefix[RandomInt(0u, prefix.size() - 1)]; + if ( ( length < 3 ) || ( ':' != arg[2] ) || ( 0 == isdigit( arg[3] ) ) ) + { + isValid = false; + break; + } + m_randomLoopCount = ::atoi( arg + 3 ); + break; } - formatSpec += typeSpec; - formatSpec += '|'; - formatSpec += RandomString(100); - switch (typeSpec) + case 's': { - case 'c': - TestCase(formatSpec, RandomInt(1, 127)); - break; - case 'd': - case 'i': - case 'o': - case 'u': - case 'x': - case 'X': - //TestCase(formatSpec, RandomInt(-10000, 10000)); - // don't test negative values on 64bit systems, because - // snprintf does not support 64 Bit values - TestCase(formatSpec, RandomInt( -10000 * (sizeof(size_t)>4 ? 0 : 1) , 10000)); - break; - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': - TestCase(formatSpec, - RandomInt(-10000, 10000) / double(RandomInt(1, 100))); - break; - case 'n': - break; - case 'p': + if ( ( length < 3 ) || ( ':' != arg[2] ) || ( 0 == isdigit( arg[3] ) ) ) { - void * p = malloc(RandomInt(1, 1000)); - TestCase(formatSpec, p); - free(p); + isValid = false; + break; } + m_speedLoopCount = ::atoi( arg + 3 ); break; - case 's': - TestCase(formatSpec, RandomString(100).c_str()); - break; - default: - assert(false); - break; } + } } + + if ( !isValid ) + { + m_showHelp = true; + m_speedLoopCount = 0; + m_randomLoopCount = 0; + m_doFormatTest = false; + } } -void test_dword() +// ---------------------------------------------------------------------------- + +void CommandLineArgs::ShowHelp( void ) const { - typedef signed int Int; - typedef unsigned int UInt; - typedef signed long Long; - typedef unsigned long ULong; - Int i(0); - UInt ui(0); - Long l(0); - ULong ul(0); - Printf("%d")(i); - Printf("%d")(ui); - Printf("%d")(l); - Printf("%d")(ul); + cout << "Usage: " << m_exeName << " [-h] [-f] [-r:#] [-s:#]" << endl; + cout << " -h Show this help info and exit. Overrides all other options." << endl; + cout << " -f Run formatting tests." << endl; + cout << " -r:# Run random tests for # of loops. # is a positive decimal value greater than 100." << endl; + cout << " -s:# Run speed tests for # of loops. # is a positive decimal value greater than 100." << endl; } +// ---------------------------------------------------------------------------- +int main( int argc, const char * argv[] ) +{ + + const CommandLineArgs args( argc, argv ); + + if ( args.DoShowHelp() ) + { + args.ShowHelp(); + return 0; + } + + if ( args.DoSpeedTest() ) + { + SpeedTest( args.GetSpeedLoopCount() ); + } + if ( args.DoRandomTest() ) + { + RandomTest( args.GetRandomLoopCount() ); + } + if ( args.DoFormatTest() ) + { + FormatTest(); + } +} + +// ---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-04 00:50:11
|
Revision: 1135 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1135&view=rev Author: rich_sposato Date: 2011-10-04 00:50:00 +0000 (Tue, 04 Oct 2011) Log Message: ----------- Fixed bugs 2792371 and 2694060 by adding checks for end of format. Modified Paths: -------------- trunk/include/loki/SafeFormat.h Modified: trunk/include/loki/SafeFormat.h =================================================================== --- trunk/include/loki/SafeFormat.h 2011-10-03 05:05:41 UTC (rev 1134) +++ trunk/include/loki/SafeFormat.h 2011-10-04 00:50:00 UTC (rev 1135) @@ -135,6 +135,11 @@ // Print (or gobble in case of the "*" specifier) an int PrintfState& operator()(LOKI_SAFEFORMAT_UNSIGNED_LONG i) { + if ( '\0' == *format_ ) + { + ::std::logic_error ex( "invalid number of parameters for Loki::SafeFormat!" ); + throw ex; + } if (result_ == -1) return *this; // don't even bother // % [flags] [width] [.prec] [modifier] type_char // Fetch the flags @@ -208,6 +213,11 @@ } PrintfState& operator()(const char *const s) { + if ( '\0' == *format_ ) + { + ::std::logic_error ex( "invalid number of parameters for Loki::SafeFormat!" ); + throw ex; + } if (result_ == -1) return *this; ReadLeaders(); const char fmt = *format_; @@ -219,7 +229,7 @@ result_ = -1; return *this; } - const size_t len = std::min(std::strlen(s), prec_); + const size_t len = std::min(std::strlen(s), prec_); if (width_ > len) { if (LeftJustify()) { Write(s, s + len); @@ -359,6 +369,11 @@ template <class Value> void PrintUsing_snprintf(Value n, const char* check_fmt_char) { + if ( '\0' == *format_ ) + { + ::std::logic_error ex( "invalid number of parameters for Loki::SafeFormat!" ); + throw ex; + } const Char *const fmt = format_ - 1; assert(*fmt == '%'); // enforce format string validity This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-03 05:05:47
|
Revision: 1134 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1134&view=rev Author: rich_sposato Date: 2011-10-03 05:05:41 +0000 (Mon, 03 Oct 2011) Log Message: ----------- Minor cosmetic changes. Also replaced system call with use of std::cin.get. Modified Paths: -------------- trunk/test/ThreadLocal/main.cpp Modified: trunk/test/ThreadLocal/main.cpp =================================================================== --- trunk/test/ThreadLocal/main.cpp 2011-10-03 05:03:10 UTC (rev 1133) +++ trunk/test/ThreadLocal/main.cpp 2011-10-03 05:05:41 UTC (rev 1134) @@ -28,10 +28,10 @@ #include <cstdlib> -#include <iostream> - -using namespace ::std; +#include <iostream> +using namespace ::std; + extern bool TestThreadLocalClassStaticValue( void ); extern bool TestThreadLocalFunctionStaticValue( void ); @@ -45,34 +45,36 @@ { (void)argc; (void)argv; - + bool okay = true; - cout << "Starting ThreadLocal tests." << endl; - cout << "If any tests fail, or any assertions fail," << endl + cout << "Starting ThreadLocal tests." << endl; + cout << "If any tests fail, or any assertions fail," << endl << "then your compiler does not implement thread_local storage correctly." << endl; - - cout << endl << "Testing static thread_local storage inside classes." << endl; - okay = TestThreadLocalClassStaticValue(); - if ( okay ) - cout << "Your compiler correctly implements thread_local storage for class static values." << endl; - else - cout << "Your compiler does not properly implement thread_local storage for class static values." << endl; - + + cout << endl << "Testing static thread_local storage inside classes." << endl; + okay = TestThreadLocalClassStaticValue(); + if ( okay ) + cout << "Your compiler correctly implements thread_local storage for class static values." << endl; + else + cout << "Your compiler does not properly implement thread_local storage for class static values." << endl; + cout << endl << "Testing static thread_local storage inside functions." << endl; okay = TestThreadLocalFunctionStaticValue(); if ( okay ) cout << "Your compiler correctly implements thread_local storage for function static values." << endl; else cout << "Your compiler does not properly implement thread_local storage for function static values." << endl; - - cout << endl << "Testing standalone static thread_local storage." << endl; - okay = TestThreadLocalStaticValue(); - if ( okay ) - cout << "Your compiler correctly implements thread_local storage for standalone static values." << endl; - else - cout << "Your compiler does not properly implement thread_local storage for standalone static values." << endl; - ::system( "pause" ); + cout << endl << "Testing standalone static thread_local storage." << endl; + okay = TestThreadLocalStaticValue(); + if ( okay ) + cout << "Your compiler correctly implements thread_local storage for standalone static values." << endl; + else + cout << "Your compiler does not properly implement thread_local storage for standalone static values." << endl; + + ::std::cout << "Please press enter key to continue." << ::std::endl; + ::std::cin.get(); + return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-03 05:03:16
|
Revision: 1133 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1133&view=rev Author: rich_sposato Date: 2011-10-03 05:03:10 +0000 (Mon, 03 Oct 2011) Log Message: ----------- Added void lines to remove compiler warnings. Modified Paths: -------------- trunk/test/Singleton/Phoenix.cpp Modified: trunk/test/Singleton/Phoenix.cpp =================================================================== --- trunk/test/Singleton/Phoenix.cpp 2011-10-03 05:01:16 UTC (rev 1132) +++ trunk/test/Singleton/Phoenix.cpp 2011-10-03 05:03:10 UTC (rev 1133) @@ -81,6 +81,9 @@ int main(int argc, char* argv[]) { + (void)argc; + (void)argv; + Example *example = new Example(); SetLongevity<Example, void (*)(Example*)>(example, 1, &Loki::Private::Deleter<Example>::Delete); LogBook::Instance().echo("LogClass now instantiated."); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <ric...@us...> - 2011-10-03 04:57:00
|
Revision: 1131 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1131&view=rev Author: rich_sposato Date: 2011-10-03 04:56:54 +0000 (Mon, 03 Oct 2011) Log Message: ----------- Added void lines to remove compiler warnings. Commented out inappropriate tests. Added call to single-owner test for StrongPtr. Modified Paths: -------------- trunk/test/SmartPtr/main.cpp Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-10-03 04:52:52 UTC (rev 1130) +++ trunk/test/SmartPtr/main.cpp 2011-10-03 04:56:54 UTC (rev 1131) @@ -36,6 +36,7 @@ extern void DoStrongForwardReferenceTest( void ); extern void DoStrongCompareTests( void ); extern void DoStrongPtrDynamicCastTests( void ); +extern void DoSingleOwnerTests( void ); extern void DoStrongArrayTests( void ); extern void DoLockedPtrTest( void ); @@ -60,6 +61,10 @@ NoCheck, DefaultSPStorage, PropagateConst > Thingy_DefaultStorage_ptr; +//typedef Loki::SmartPtr< Thingy, RefCountedMTAdj< >, DisallowConversion, +// AssertCheck, DefaultSPStorage, PropagateConst > +// Thingy_Locked_ptr; + typedef Loki::SmartPtr< Thingy, RefCounted, DisallowConversion, AssertCheck, HeapStorage, PropagateConst > Thingy_HeapStorage_ptr; @@ -1425,20 +1430,23 @@ from const to non-const, or about assigning a read-only reference, then DestructiveCopy was designed correctly. */ - DestructiveCopyPtr p2; - assert( !p2 ); - p2 = p1; - assert( !p1 ); - assert( p2 ); - DestructiveCopyPtr p3( p2 ); - assert( p3 ); - assert( !p2 ); + //DestructiveCopyPtr p2; + //assert( !p2 ); + //p2 = p1; + //assert( !p1 ); + //assert( p2 ); + //DestructiveCopyPtr p3( p2 ); + //assert( p3 ); + //assert( !p2 ); } { /// @todo The following lines need to be uncommented when bug 3224572 gets fixed. DestructiveCopyPtr p1( MakePointer() ); assert( p1 ); + DestructiveCopyPtr p2; + p2 = MakePointer(); + assert( p2 ); } assert( BaseClass::AllDestroyed() ); @@ -1497,10 +1505,12 @@ try { Tiger & p4 = sp2[ 4 ]; + (void)p4; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } @@ -1508,10 +1518,12 @@ try { Tiger & p8 = sp1[ 8 ]; + (void)p8; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } @@ -1540,20 +1552,24 @@ try { Tiger & p4 = sp1[ 4 ]; + (void)p4; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } try { Tiger & p8 = sp2[ 8 ]; + (void)p8; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } @@ -1563,10 +1579,12 @@ try { const Tiger & p4 = sp3[ 4 ]; + (void)p4; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } @@ -1576,10 +1594,12 @@ try { const Tiger & p8 = sp5[ 8 ]; + (void)p8; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } @@ -1622,6 +1642,7 @@ DoStrongReleaseTests(); DoWeakCycleTests(); DoStrongCompareTests(); + DoSingleOwnerTests(); DoForwardReferenceTest(); DoStrongForwardReferenceTest(); @@ -1633,7 +1654,7 @@ DoRefLinkSwapTests(); DoComRefTest(); - TryColvinGibbonsTrick(); +// TryColvinGibbonsTrick(); DoStrongConstTests(); DoConstConversionTests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-03 04:52:58
|
Revision: 1130 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1130&view=rev Author: rich_sposato Date: 2011-10-03 04:52:52 +0000 (Mon, 03 Oct 2011) Log Message: ----------- Added void lines to remove compiler warnings. Modified Paths: -------------- trunk/test/SmartPtr/strong.cpp Modified: trunk/test/SmartPtr/strong.cpp =================================================================== --- trunk/test/SmartPtr/strong.cpp 2011-10-03 04:39:17 UTC (rev 1129) +++ trunk/test/SmartPtr/strong.cpp 2011-10-03 04:52:52 UTC (rev 1130) @@ -2113,10 +2113,12 @@ try { Tiger & p4 = sp2[ 4 ]; + (void)p4; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } @@ -2124,10 +2126,12 @@ try { Tiger & p8 = sp1[ 8 ]; + (void)p8; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } @@ -2156,20 +2160,24 @@ try { Tiger & p4 = sp1[ 4 ]; + (void)p4; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } try { Tiger & p8 = sp2[ 8 ]; + (void)p8; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } @@ -2179,10 +2187,12 @@ try { const Tiger & p4 = sp3[ 4 ]; + (void)p4; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } @@ -2192,10 +2202,12 @@ try { const Tiger & p8 = sp5[ 8 ]; + (void)p8; assert( false ); } catch ( const ::std::out_of_range & ex ) { + (void)ex; assert( true ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-03 04:39:23
|
Revision: 1129 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1129&view=rev Author: rich_sposato Date: 2011-10-03 04:39:17 +0000 (Mon, 03 Oct 2011) Log Message: ----------- Changed order of actions to remove warning. Modified Paths: -------------- trunk/include/loki/Singleton.h Modified: trunk/include/loki/Singleton.h =================================================================== --- trunk/include/loki/Singleton.h 2011-10-03 04:00:22 UTC (rev 1128) +++ trunk/include/loki/Singleton.h 2011-10-03 04:39:17 UTC (rev 1129) @@ -829,8 +829,8 @@ { if (destroyed_) { + destroyed_ = false; LifetimePolicy<T>::OnDeadReference(); - destroyed_ = false; } pInstance_ = CreationPolicy<T>::Create(); LifetimePolicy<T>::ScheduleDestruction(pInstance_, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-10-03 04:00:29
|
Revision: 1128 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1128&view=rev Author: rich_sposato Date: 2011-10-03 04:00:22 +0000 (Mon, 03 Oct 2011) Log Message: ----------- Minor changes for Visual Studio. Modified Paths: -------------- trunk/include/loki/AssocVector.h Modified: trunk/include/loki/AssocVector.h =================================================================== --- trunk/include/loki/AssocVector.h 2011-09-30 23:16:08 UTC (rev 1127) +++ trunk/include/loki/AssocVector.h 2011-10-03 04:00:22 UTC (rev 1128) @@ -153,8 +153,9 @@ typedef ::std::map< K, V, C, A > TempMap; typedef ::std::back_insert_iterator< Base > MyInserter; MyCompare & me = *this; - // Make a temporary map similar to this type to prevent any duplicates elements. - TempMap temp( first, last, me, alloc ); + const A tempAlloc; + // Make a temporary map similar to this type to prevent any duplicate elements. + TempMap temp( first, last, me, tempAlloc ); Base::reserve( temp.size() ); BaseType & target = static_cast< BaseType & >( *this ); MyInserter myInserter = ::std::back_inserter( target ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-30 23:16:14
|
Revision: 1127 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1127&view=rev Author: rich_sposato Date: 2011-09-30 23:16:08 +0000 (Fri, 30 Sep 2011) Log Message: ----------- Fixed bug 3388381 by changing ctor body. Modified Paths: -------------- trunk/include/loki/AssocVector.h Modified: trunk/include/loki/AssocVector.h =================================================================== --- trunk/include/loki/AssocVector.h 2011-09-30 23:14:41 UTC (rev 1126) +++ trunk/include/loki/AssocVector.h 2011-09-30 23:16:08 UTC (rev 1127) @@ -33,7 +33,10 @@ #include <functional> #include <vector> #include <utility> +#include <iterator> +#include <map> + namespace Loki { //////////////////////////////////////////////////////////////////////////////// @@ -144,10 +147,18 @@ AssocVector(InputIterator first, InputIterator last, const key_compare& comp = key_compare(), const A& alloc = A()) - : Base(first, last, alloc), MyCompare(comp) + : Base( alloc ), MyCompare( comp ) { - MyCompare& me = *this; - std::sort(begin(), end(), me); + typedef ::std::vector< ::std::pair< K, V >, A > BaseType; + typedef ::std::map< K, V, C, A > TempMap; + typedef ::std::back_insert_iterator< Base > MyInserter; + MyCompare & me = *this; + // Make a temporary map similar to this type to prevent any duplicates elements. + TempMap temp( first, last, me, alloc ); + Base::reserve( temp.size() ); + BaseType & target = static_cast< BaseType & >( *this ); + MyInserter myInserter = ::std::back_inserter( target ); + ::std::copy( temp.begin(), temp.end(), myInserter ); } AssocVector& operator=(const AssocVector& rhs) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-30 23:14:47
|
Revision: 1126 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1126&view=rev Author: rich_sposato Date: 2011-09-30 23:14:41 +0000 (Fri, 30 Sep 2011) Log Message: ----------- Added tests for AssocVector class. Changed order of projects. Modified Paths: -------------- trunk/Loki.workspace Modified: trunk/Loki.workspace =================================================================== --- trunk/Loki.workspace 2011-09-30 23:13:59 UTC (rev 1125) +++ trunk/Loki.workspace 2011-09-30 23:14:41 UTC (rev 1126) @@ -1,7 +1,8 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_workspace_file> <Workspace title="Workspace"> - <Project filename="Loki.cbp" /> + <Project filename="Loki.cbp" active="1" /> + <Project filename="test/AssocVector/AssocVector.cbp" /> <Project filename="test/CachedFactory/CachedFactory.cbp"> <Depends filename="Loki.cbp" /> </Project> @@ -16,6 +17,9 @@ <Project filename="test/LevelMutex/LevelMutex.cbp"> <Depends filename="Loki.cbp" /> </Project> + <Project filename="test/Lockable/Lockable.cbp"> + <Depends filename="Loki.cbp" /> + </Project> <Project filename="test/LockingPtr/LockingPtr.cbp" /> <Project filename="test/Longevity/Longevity.cbp" /> <Project filename="test/OrderedStatic/OrderedStatic.cbp"> @@ -26,6 +30,7 @@ <Project filename="test/RegressionTest/RegressionTest.cbp"> <Depends filename="Loki.cbp" /> </Project> + <Project filename="test/SafeBits/SafeBits.cbp" /> <Project filename="test/SafeFormat/SafeFormat.cbp"> <Depends filename="Loki.cbp" /> </Project> @@ -40,11 +45,7 @@ <Project filename="test/SmartPtr/SmartPtr.cbp"> <Depends filename="Loki.cbp" /> </Project> + <Project filename="test/ThreadLocal/ThreadLocal.cbp" /> <Project filename="test/Visitor/Visitor.cbp" /> - <Project filename="test/SafeBits/SafeBits.cbp" /> - <Project filename="test/ThreadLocal/ThreadLocal.cbp" /> - <Project filename="test/Lockable/Lockable.cbp" active="1"> - <Depends filename="Loki.cbp" /> - </Project> </Workspace> </CodeBlocks_workspace_file> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-30 23:14:06
|
Revision: 1125 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1125&view=rev Author: rich_sposato Date: 2011-09-30 23:13:59 +0000 (Fri, 30 Sep 2011) Log Message: ----------- Added tests for AssocVector class. Added Paths: ----------- trunk/test/AssocVector/ trunk/test/AssocVector/AssocVector.cbp trunk/test/AssocVector/main.cpp Added: trunk/test/AssocVector/AssocVector.cbp =================================================================== --- trunk/test/AssocVector/AssocVector.cbp (rev 0) +++ trunk/test/AssocVector/AssocVector.cbp 2011-09-30 23:13:59 UTC (rev 1125) @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="AssocVector" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="Debug"> + <Option output="bin/Debug/AssocVector" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-std=c++0x" /> + <Add option="-std=c++98" /> + <Add option="-Wextra" /> + <Add option="-Wall" /> + <Add option="-g" /> + <Add directory="../../include" /> + </Compiler> + </Target> + <Target title="Release"> + <Option output="bin/Release/AssocVector" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + <Add option="-std=c++0x" /> + <Add option="-std=c++98" /> + <Add option="-Wextra" /> + <Add option="-Wall" /> + <Add directory="../../include" /> + </Compiler> + <Linker> + <Add option="-s" /> + </Linker> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + <Add option="-fexceptions" /> + </Compiler> + <Unit filename="main.cpp" /> + <Extensions> + <envvars /> + <code_completion /> + <lib_finder disable_auto="1" /> + <debugger /> + </Extensions> + </Project> +</CodeBlocks_project_file> Added: trunk/test/AssocVector/main.cpp =================================================================== --- trunk/test/AssocVector/main.cpp (rev 0) +++ trunk/test/AssocVector/main.cpp 2011-09-30 23:13:59 UTC (rev 1125) @@ -0,0 +1,191 @@ +//////////////////////////////////////////////////////////////////////////////// +// The Loki Library +// Copyright (c) 2011 by Rich Sposato +// +// This code does not accompany the book: +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Patterns Applied". Copyright (c) 2001. Addison-Wesley. +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +//////////////////////////////////////////////////////////////////////////////// + +#include <loki/AssocVector.h> + +#include <cassert> + +#include <string> +#include <iostream> + +using namespace std; + +typedef ::std::map< ::std::string, unsigned int > StudentGradeMap; +typedef StudentGradeMap::iterator StudentGradeMapIter; +typedef StudentGradeMap::const_iterator StudentGradeMapCIter; + +typedef ::Loki::AssocVector< ::std::string, unsigned int > StudentGrades; +typedef StudentGrades::iterator StudentGradeIter; +typedef StudentGrades::const_iterator StudentGradeCIter; + +typedef ::std::pair< ::std::string, unsigned int > GradeInfo; + + +GradeInfo oneStudent = ::std::make_pair( "Anne", 100 ); + +GradeInfo noDuplicates[] = +{ + ::std::make_pair( "Anne", 100 ), + ::std::make_pair( "Bill", 88 ), + ::std::make_pair( "Clay", 91 ), + ::std::make_pair( "Dina", 62 ), + ::std::make_pair( "Evan", 77 ), + ::std::make_pair( "Fran", 84 ), + ::std::make_pair( "Greg", 95 ) +}; + + +GradeInfo hasDuplicates[] = +{ + ::std::make_pair( "Anne", 100 ), + ::std::make_pair( "Anne", 73 ), + ::std::make_pair( "Bill", 88 ), + ::std::make_pair( "Clay", 91 ), + ::std::make_pair( "Dina", 62 ), + ::std::make_pair( "Evan", 77 ), + ::std::make_pair( "Fran", 74 ), + ::std::make_pair( "Fran", 84 ), + ::std::make_pair( "Greg", 95 ) +}; + +// ---------------------------------------------------------------------------- + +void TestEmptyAssocVector( void ) +{ + cout << "Starting TestEmptyAssocVector" << endl; + + StudentGrades grades; + const StudentGrades & cGrades = grades; + assert( grades.empty() ); + assert( grades.size() == 0 ); + assert( cGrades.empty() ); + assert( cGrades.size() == 0 ); + + StudentGradeIter it1( grades.begin() ); + assert( it1 == grades.end() ); + + const StudentGradeIter it2( grades.begin() ); + assert( it2 == grades.end() ); + assert( it2 == it1 ); + assert( it1 == it2 ); + + StudentGradeCIter cit1( grades.begin() ); + assert( cit1 == grades.end() ); + assert( cit1 == it1 ); + assert( cit1 == it2 ); + assert( it1 == cit1 ); + assert( it2 == cit1 ); + + const StudentGradeCIter cit2( grades.begin() ); + assert( cit2 == grades.end() ); + assert( cit1 == cit2 ); + assert( cit2 == cit1 ); + assert( cit2 == it1 ); + assert( cit2 == it2 ); + assert( it1 == cit2 ); + assert( it2 == cit2 ); + + StudentGradeCIter cit3( cGrades.begin() ); + assert( cit3 == cGrades.end() ); + assert( cit3 == it1 ); + assert( cit3 == it2 ); + assert( it1 == cit3 ); + assert( it2 == cit3 ); + + const StudentGradeCIter cit4( cGrades.begin() ); + assert( cit4 == cGrades.end() ); + assert( cit1 == cit4 ); + assert( cit4 == cit1 ); + assert( cit4 == it1 ); + assert( cit4 == it2 ); + assert( it1 == cit4 ); + assert( it2 == cit4 ); + + cout << "Finished TestEmptyAssocVector" << endl; +} + +// ---------------------------------------------------------------------------- + +void TestAssocVectorCtor( void ) +{ + cout << "Starting TestAssocVectorCtor" << endl; + + static const unsigned int noDuplicateCount = ( sizeof(noDuplicates) / sizeof(noDuplicates[0]) ); + static const unsigned int hasDuplicateCount = ( sizeof(hasDuplicates) / sizeof(hasDuplicates[0]) ); + + { + // This test demonstrates the iterator constructor does not allow any duplicate elements. + StudentGrades grades1( noDuplicates, noDuplicates + noDuplicateCount ); + StudentGrades grades2( hasDuplicates, hasDuplicates + hasDuplicateCount ); + assert( grades1.size() != 0 ); + assert( grades2.size() != 0 ); + assert( grades1.size() == noDuplicateCount ); + assert( grades2.size() == noDuplicateCount ); + assert( grades1.size() == grades2.size() ); + } + + { + // This test demonstrates copy construction. + StudentGrades grades1( noDuplicates, noDuplicates + noDuplicateCount ); + const StudentGrades grades2( grades1 ); + assert( grades1.size() != 0 ); + assert( grades2.size() != 0 ); + assert( grades1.size() == noDuplicateCount ); + assert( grades2.size() == noDuplicateCount ); + assert( grades1.size() == grades2.size() ); + assert( grades1 == grades2 ); + + StudentGrades grades3; + grades3 = grades1; + assert( grades3.size() != 0 ); + assert( grades3.size() == noDuplicateCount ); + assert( grades3.size() == grades1.size() ); + assert( grades1 == grades3 ); + } + + cout << "Finished TestAssocVectorCtor" << endl; +} + +// ---------------------------------------------------------------------------- + +int main( int argc, const char * const argv[] ) +{ + (void)argc; + (void)argv; + char ender; + + TestEmptyAssocVector(); + TestAssocVectorCtor(); + + cout << "Press <Enter> key to finish. " << endl; + cin.get( ender ); + + return 0; +} + +// ---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-30 19:58:50
|
Revision: 1124 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1124&view=rev Author: rich_sposato Date: 2011-09-30 19:58:43 +0000 (Fri, 30 Sep 2011) Log Message: ----------- Fixed 3415388. Changed predefined to match #define in Threads.h Modified Paths: -------------- trunk/doc/Doxyfile Modified: trunk/doc/Doxyfile =================================================================== --- trunk/doc/Doxyfile 2011-09-29 23:33:53 UTC (rev 1123) +++ trunk/doc/Doxyfile 2011-09-30 19:58:43 UTC (rev 1124) @@ -215,7 +215,7 @@ SEARCH_INCLUDES = YES INCLUDE_PATH = INCLUDE_FILE_PATTERNS = -PREDEFINED = _WINDOWS_H +PREDEFINED = LOKI_WINDOWS_H EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-29 23:34:00
|
Revision: 1123 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1123&view=rev Author: rich_sposato Date: 2011-09-29 23:33:53 +0000 (Thu, 29 Sep 2011) Log Message: ----------- Added tests for ObjectLevelLockable and ClassLevelLockable. Modified Paths: -------------- trunk/Loki.workspace Modified: trunk/Loki.workspace =================================================================== --- trunk/Loki.workspace 2011-09-29 23:33:08 UTC (rev 1122) +++ trunk/Loki.workspace 2011-09-29 23:33:53 UTC (rev 1123) @@ -1,47 +1,50 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_workspace_file> <Workspace title="Workspace"> - <Project filename="Loki.cbp" active="1" /> - <Project filename="test\CachedFactory\CachedFactory.cbp"> + <Project filename="Loki.cbp" /> + <Project filename="test/CachedFactory/CachedFactory.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Checker\Checker.cbp" /> - <Project filename="test\CheckReturn\CheckReturn.cbp" /> - <Project filename="test\DeletableSingleton\DeletableSingleton.cbp"> + <Project filename="test/Checker/Checker.cbp" /> + <Project filename="test/CheckReturn/CheckReturn.cbp" /> + <Project filename="test/DeletableSingleton/DeletableSingleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Factory\Factory.cbp" /> - <Project filename="test\flex_string\flex_string.cbp" /> - <Project filename="test\Function\Function.cbp" /> - <Project filename="test\LevelMutex\LevelMutex.cbp"> + <Project filename="test/Factory/Factory.cbp" /> + <Project filename="test/flex_string/flex_string.cbp" /> + <Project filename="test/Function/Function.cbp" /> + <Project filename="test/LevelMutex/LevelMutex.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\LockingPtr\LockingPtr.cbp" /> - <Project filename="test\Longevity\Longevity.cbp" /> - <Project filename="test\OrderedStatic\OrderedStatic.cbp"> + <Project filename="test/LockingPtr/LockingPtr.cbp" /> + <Project filename="test/Longevity/Longevity.cbp" /> + <Project filename="test/OrderedStatic/OrderedStatic.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Pimpl\Pimpl.cbp" /> - <Project filename="test\Register\Register.cbp" /> - <Project filename="test\RegressionTest\RegressionTest.cbp"> + <Project filename="test/Pimpl/Pimpl.cbp" /> + <Project filename="test/Register/Register.cbp" /> + <Project filename="test/RegressionTest/RegressionTest.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\SafeFormat\SafeFormat.cbp"> + <Project filename="test/SafeFormat/SafeFormat.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\ScopeGuard\ScopeGuard.cbp" /> - <Project filename="test\Singleton\Singleton.cbp"> + <Project filename="test/ScopeGuard/ScopeGuard.cbp" /> + <Project filename="test/Singleton/Singleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\SmallObj\SmallObj.cbp"> + <Project filename="test/SmallObj/SmallObj.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\SmallObj\DefaultAlloc.cbp" /> - <Project filename="test\SmartPtr\SmartPtr.cbp"> + <Project filename="test/SmallObj/DefaultAlloc.cbp" /> + <Project filename="test/SmartPtr/SmartPtr.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Visitor\Visitor.cbp" /> - <Project filename="test\SafeBits\SafeBits.cbp" /> - <Project filename="test\ThreadLocal\ThreadLocal.cbp" /> + <Project filename="test/Visitor/Visitor.cbp" /> + <Project filename="test/SafeBits/SafeBits.cbp" /> + <Project filename="test/ThreadLocal/ThreadLocal.cbp" /> + <Project filename="test/Lockable/Lockable.cbp" active="1"> + <Depends filename="Loki.cbp" /> + </Project> </Workspace> </CodeBlocks_workspace_file> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-29 23:33:14
|
Revision: 1122 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1122&view=rev Author: rich_sposato Date: 2011-09-29 23:33:08 +0000 (Thu, 29 Sep 2011) Log Message: ----------- Changed compiler and linker settings for Release build. Modified Paths: -------------- trunk/test/Lockable/Lockable.cbp Modified: trunk/test/Lockable/Lockable.cbp =================================================================== --- trunk/test/Lockable/Lockable.cbp 2011-09-29 23:31:47 UTC (rev 1121) +++ trunk/test/Lockable/Lockable.cbp 2011-09-29 23:33:08 UTC (rev 1122) @@ -20,6 +20,7 @@ </Compiler> <Linker> <Add library="/usr/lib/libpthread.so" /> + <Add library="../../lib/GCC/Loki_D.a" /> </Linker> </Target> <Target title="Release"> @@ -29,9 +30,16 @@ <Option compiler="gcc" /> <Compiler> <Add option="-O2" /> + <Add option="-std=c++0x" /> + <Add option="-std=c++98" /> + <Add option="-Wextra" /> + <Add option="-Wall" /> + <Add directory="../../include" /> </Compiler> <Linker> <Add option="-s" /> + <Add library="/usr/lib/libpthread.so" /> + <Add library="../../lib/GCC/Loki.a" /> </Linker> </Target> </Build> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-29 23:31:53
|
Revision: 1121 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1121&view=rev Author: rich_sposato Date: 2011-09-29 23:31:47 +0000 (Thu, 29 Sep 2011) Log Message: ----------- Added tests for ObjectLevelLockable and ClassLevelLockable. Added Paths: ----------- trunk/test/Lockable/ trunk/test/Lockable/Lockable.cbp trunk/test/Lockable/ThreadPool.cpp trunk/test/Lockable/ThreadPool.hpp trunk/test/Lockable/main.cpp Added: trunk/test/Lockable/Lockable.cbp =================================================================== --- trunk/test/Lockable/Lockable.cbp (rev 0) +++ trunk/test/Lockable/Lockable.cbp 2011-09-29 23:31:47 UTC (rev 1121) @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="Lockable" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="Debug"> + <Option output="bin/Debug/Lockable" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-std=c++0x" /> + <Add option="-Wextra" /> + <Add option="-Wall" /> + <Add option="-g" /> + <Add directory="../../include" /> + </Compiler> + <Linker> + <Add library="/usr/lib/libpthread.so" /> + </Linker> + </Target> + <Target title="Release"> + <Option output="bin/Release/Lockable" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release/" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + </Compiler> + <Linker> + <Add option="-s" /> + </Linker> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + <Add option="-fexceptions" /> + </Compiler> + <Unit filename="ThreadPool.cpp" /> + <Unit filename="ThreadPool.hpp" /> + <Unit filename="main.cpp" /> + <Extensions> + <envvars /> + <code_completion /> + <lib_finder disable_auto="1" /> + <debugger /> + </Extensions> + </Project> +</CodeBlocks_project_file> Added: trunk/test/Lockable/ThreadPool.cpp =================================================================== --- trunk/test/Lockable/ThreadPool.cpp (rev 0) +++ trunk/test/Lockable/ThreadPool.cpp 2011-09-29 23:31:47 UTC (rev 1121) @@ -0,0 +1,116 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// ThreadLocal test program for The Loki Library +// Copyright (c) 2009 by Richard Sposato +// The copyright on this file is protected under the terms of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- + +#include "ThreadPool.hpp" + +#include <sstream> +#include <iostream> + +// ---------------------------------------------------------------------------- + +Thread::Thread( CallFunction func, void * parm ) + : pthread_() + , func_( func ) + , parm_( parm ) +{ +} + +// ---------------------------------------------------------------------------- + +void Thread::AssignTask( CallFunction func, void * parm ) +{ + func_ = func; + parm_ = parm; +} + +// ---------------------------------------------------------------------------- + +int Thread::Start( void ) +{ + return LOKI_pthread_create( &pthread_, NULL, func_, parm_ ); +} + +// ---------------------------------------------------------------------------- + +int Thread::WaitForThread( void ) const +{ + return LOKI_pthread_join( pthread_ ); +} + +// ---------------------------------------------------------------------------- + +ThreadPool::ThreadPool( void ) : m_threads() +{ +} + +// ---------------------------------------------------------------------------- + +ThreadPool::~ThreadPool( void ) +{ + for ( size_t ii = 0; ii < m_threads.size(); ++ii ) + { + delete m_threads.at( ii ); + } +} + +// ---------------------------------------------------------------------------- + +void ThreadPool::Create( size_t threadCount, Thread::CallFunction function ) +{ + for( size_t ii = 0; ii < threadCount; ii++ ) + { + ::std::stringstream buffer; + buffer << "Creating thread " << ii << ::std::endl; + ::std::cout << buffer.rdbuf(); + Thread * thread = new Thread( function, reinterpret_cast< void * >( ii ) ); + m_threads.push_back( thread ); + } +} + +// ---------------------------------------------------------------------------- + +void ThreadPool::Start( void ) +{ + for ( size_t ii = 0; ii < m_threads.size(); ii++ ) + { + ::std::stringstream buffer; + buffer << "Starting thread " << ii << ::std::endl; + ::std::cout << buffer.rdbuf(); + m_threads.at( ii )->Start(); + } +} + +// ---------------------------------------------------------------------------- + +void ThreadPool::Join( void ) const +{ + for ( size_t ii = 0; ii < m_threads.size(); ii++ ) + m_threads.at( ii )->WaitForThread(); +} + +// ---------------------------------------------------------------------------- Added: trunk/test/Lockable/ThreadPool.hpp =================================================================== --- trunk/test/Lockable/ThreadPool.hpp (rev 0) +++ trunk/test/Lockable/ThreadPool.hpp 2011-09-29 23:31:47 UTC (rev 1121) @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// ThreadLocal test program for The Loki Library +// Copyright (c) 2009 by Richard Sposato +// The copyright on this file is protected under the terms of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + + +// ---------------------------------------------------------------------------- + +#include <vector> + +#if !defined( NULL ) + #define NULL 0 +#endif + +// define nullptr even though new compilers will have this keyword just so we +// have a consistent and easy way of identifying which uses of 0 mean null. +#if !defined( nullptr ) + #define nullptr NULL +#endif + +#if defined(_WIN32) + + #include <process.h> + #include <windows.h> + + typedef unsigned int ( WINAPI * ThreadFunction_ )( void * ); + + #define LOKI_pthread_t HANDLE + + #define LOKI_pthread_create( handle, attr, func, arg ) \ + ( int )( ( *handle = ( HANDLE ) _beginthreadex ( NULL, 0, ( ThreadFunction_ )func, arg, 0, NULL ) ) == NULL ) + + #define LOKI_pthread_join( thread ) \ + ( ( WaitForSingleObject( ( thread ), INFINITE ) != WAIT_OBJECT_0 ) || !CloseHandle( thread ) ) + +#else + + #include <pthread.h> + + #define LOKI_pthread_t \ + pthread_t + #define LOKI_pthread_create(handle,attr,func,arg) \ + pthread_create(handle,attr,func,arg) + #define LOKI_pthread_join(thread) \ + pthread_join(thread, NULL) + +#endif + +// ---------------------------------------------------------------------------- + +class Thread +{ +public: + + typedef void * ( * CallFunction )( void * ); + + Thread( CallFunction func, void * parm ); + + void AssignTask( CallFunction func, void * parm ); + + int Start( void ); + + int WaitForThread( void ) const; + +private: + + LOKI_pthread_t pthread_; + + CallFunction func_; + + void * parm_; + +}; + +// ---------------------------------------------------------------------------- + +class ThreadPool +{ +public: + + ThreadPool( void ); + + ~ThreadPool( void ); + + void Create( size_t threadCount, Thread::CallFunction function ); + + void Start( void ); + + void Join( void ) const; + +private: + + typedef ::std::vector< Thread * > Threads; + + Threads m_threads; +}; + +// ---------------------------------------------------------------------------- Added: trunk/test/Lockable/main.cpp =================================================================== --- trunk/test/Lockable/main.cpp (rev 0) +++ trunk/test/Lockable/main.cpp 2011-09-29 23:31:47 UTC (rev 1121) @@ -0,0 +1,302 @@ +//////////////////////////////////////////////////////////////////////////////// +// The Loki Library +// Copyright (c) 2011 by Rich Sposato +// +// This code does not accompany the book: +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Patterns Applied". Copyright (c) 2001. Addison-Wesley. +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +//////////////////////////////////////////////////////////////////////////////// + +#define LOKI_OBJECT_LEVEL_THREADING +#include <loki/Threads.h> + +#include <vector> +#include <iostream> + +#include <loki/SafeFormat.h> +#include "ThreadPool.hpp" + + +using namespace std; + +static unsigned int g = 0; + +#define DO for(int i=0; i<10000000; i++) g++; + +static const unsigned int ThreadCount = 10; + +static const unsigned int ObjectCount = 50; + +static const unsigned int ClassCount = 5; + +static unsigned int FailCounts[ ThreadCount ]; + +// ---------------------------------------------------------------------------- + +class LockableObject : public ::Loki::ObjectLevelLockable< LockableObject > +{ +public: + + typedef ::Loki::ObjectLevelLockable< LockableObject > BaseClass; + + explicit LockableObject( unsigned int index ) : + BaseClass(), m_index( index ), m_value( ObjectCount ) {} + + ~LockableObject( void ) {} + + unsigned int GetIndex( void ) const { return m_index; } + + unsigned int GetValue( void ) const { return m_value; } + + void SetValue( unsigned int value ) { m_value = value; } + + void DoSomething( void ); + + void Print( unsigned int threadIndex ); + +private: + + const unsigned int m_index; + unsigned int m_value; + +}; + +// ---------------------------------------------------------------------------- + +void LockableObject::DoSomething( void) +{ + 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 ); +} + +// ---------------------------------------------------------------------------- + +typedef ::std::vector< LockableObject * > LockableObjects; + +LockableObjects & GetLockableObjects( void ) +{ + static LockableObjects objects; + return objects; +} + +// ---------------------------------------------------------------------------- + +LockableObject * GetLockableObject( unsigned int index ) +{ + LockableObjects & objects = GetLockableObjects(); + if ( objects.size() <= index ) + return NULL; + + LockableObject * object = objects[ index ]; + return object; +} + +// ---------------------------------------------------------------------------- + +void * RunObjectTest( void * p ) +{ + 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; + } + + FailCounts[ threadIndex ] = failCount; + + return NULL; +} + +// ---------------------------------------------------------------------------- + +void DoObjectLockTest( void ) +{ + 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 ); + } + + { + ThreadPool pool; + pool.Create( ThreadCount, &RunObjectTest ); + pool.Start(); + 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"; + + cout << "Finished DoObjectLockTest. Total Fails: " << totalFails << " Result: " + << result << endl; +} + +// ---------------------------------------------------------------------------- + +class LockableClass : public ::Loki::ClassLevelLockable< LockableClass > +{ +public: + + typedef ::Loki::ClassLevelLockable< LockableClass > BaseClass; + + explicit LockableClass( unsigned int index ) : BaseClass(), m_index( index ) {} + + ~LockableClass( void ) {} + + unsigned int GetIndex( void ) const { return m_index; } + + void Print( unsigned int threadIndex ); + +private: + 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 ); +} + +// ---------------------------------------------------------------------------- + +typedef ::std::vector< LockableClass * > LockableClasses; + +LockableClasses & GetLockableClasses( void ) +{ + static LockableClasses objects; + return objects; +} + +// ---------------------------------------------------------------------------- + +LockableClass * GetLockableClass( unsigned int index ) +{ + LockableClasses & objects = GetLockableClasses(); + if ( objects.size() <= index ) + return NULL; + + LockableClass * object = objects[ index ]; + return object; +} + +// ---------------------------------------------------------------------------- + +void * RunClassTest( void * p ) +{ + 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 ); + } + + return NULL; +} + +// ---------------------------------------------------------------------------- + +void DoClassLockTest( void ) +{ + 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 ); + } + + { + ThreadPool pool; + pool.Create( ThreadCount, &RunClassTest ); + pool.Start(); + pool.Join(); + } + + cout << "Finished DoClassLockTest" << endl; +} + +// ---------------------------------------------------------------------------- + +int main( int argc, const char * const argv[] ) +{ + (void)argc; + (void)argv; + char ender; + + DoObjectLockTest(); + cout << "Press <Enter> key to continue. "; + cin.get( ender ); + + DoClassLockTest(); + cout << "Press <Enter> key to finish. "; + cin.get( ender ); + + return 0; +} + +// ---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-29 20:47:17
|
Revision: 1120 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1120&view=rev Author: rich_sposato Date: 2011-09-29 20:47:11 +0000 (Thu, 29 Sep 2011) Log Message: ----------- Changed which libraries are linked. Modified Paths: -------------- trunk/test/ThreadLocal/ThreadLocal.cbp Modified: trunk/test/ThreadLocal/ThreadLocal.cbp =================================================================== --- trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-29 20:40:13 UTC (rev 1119) +++ trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-29 20:47:11 UTC (rev 1120) @@ -15,11 +15,13 @@ <Add option="-Wmain" /> <Add option="-pedantic" /> <Add option="-g" /> - <Add option="-W -lc" /> + <Add option="-W -fPIE" /> <Add directory="../../include" /> </Compiler> <Linker> - <Add library="/usr/lib/libpthread.a" /> + <Add option="-pie" /> + <Add library="/usr/lib/libpthread.so" /> + <Add library="/usr/lib/libc.so" /> </Linker> </Target> <Target title="Release_GCC"> @@ -29,9 +31,14 @@ <Option compiler="gcc" /> <Compiler> <Add option="-O2" /> + <Add option="-W -fPIE" /> + <Add directory="../../include" /> </Compiler> <Linker> <Add option="-s" /> + <Add option="-pie" /> + <Add library="/usr/lib/libpthread.so" /> + <Add library="/usr/lib/libc.so" /> </Linker> </Target> </Build> @@ -39,6 +46,9 @@ <Add option="-Wall" /> <Add option="-fexceptions" /> </Compiler> + <Unit filename="ThreadPool.cpp" /> + <Unit filename="ThreadPool.hpp" /> + <Unit filename="ThreadTests.cpp" /> <Unit filename="main.cpp" /> <Extensions> <code_completion /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-29 20:40:19
|
Revision: 1119 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1119&view=rev Author: rich_sposato Date: 2011-09-29 20:40:13 +0000 (Thu, 29 Sep 2011) Log Message: ----------- Changed check for GCC version 4.4 Modified Paths: -------------- trunk/include/loki/ThreadLocal.h Modified: trunk/include/loki/ThreadLocal.h =================================================================== --- trunk/include/loki/ThreadLocal.h 2011-09-29 20:36:38 UTC (rev 1118) +++ trunk/include/loki/ThreadLocal.h 2011-09-29 20:40:13 UTC (rev 1119) @@ -34,25 +34,28 @@ // macro which allows compiler to see the code inside this file. // Then #undef the macro for compilers which do not support thread-local // storage or do not implement it correctly. -#define LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE 1 +#define LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE 1 #if defined( __GNUC__ ) // The __APPLE__ macro does not refer to a compiler, but to the Apple OSX operating system. #if defined( __APPLE__ ) #warning "GCC for Apple does not allow thread_local storage, so you can not use some parts of Loki." - #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #elif defined( __CYGWIN__ ) #if ( __GNUC__ <= 3 ) #warning "Older versions of GCC for Cygwin do not allow thread_local storage, so you can not use some parts of Loki." - #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #endif #elif ( __GNUC__ == 4 ) // GNU versions other than Cygwin. - #if ( __GNUC_MINOR__ == 4 ) - #warning "GCC version 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki." - #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE - #endif + #if ( __GNUC_MINOR__ < 4 ) + #warning "GCC versions before 4.4 implement thread_local storage incorrectly, so you can not use some parts of Loki." + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #elif ( __GNUC_MINOR__ == 4 ) + #warning "GCC version 4.4 implements thread_local storage incorrectly for some platforms but not others." + #endif + #endif #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-29 20:36:45
|
Revision: 1118 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1118&view=rev Author: rich_sposato Date: 2011-09-29 20:36:38 +0000 (Thu, 29 Sep 2011) Log Message: ----------- Moved some code in main.cpp to separate files. Modified Paths: -------------- trunk/test/ThreadLocal/ThreadLocal.cbp trunk/test/ThreadLocal/main.cpp Added Paths: ----------- trunk/test/ThreadLocal/ThreadPool.cpp trunk/test/ThreadLocal/ThreadPool.hpp trunk/test/ThreadLocal/ThreadTests.cpp Modified: trunk/test/ThreadLocal/ThreadLocal.cbp =================================================================== --- trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-29 19:56:39 UTC (rev 1117) +++ trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-29 20:36:38 UTC (rev 1118) @@ -7,21 +7,24 @@ <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="obj\Debug_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="obj/Debug_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> <Add option="-Wmain" /> <Add option="-pedantic" /> - <Add option="-W" /> <Add option="-g" /> - <Add directory="..\..\include" /> + <Add option="-W -lc" /> + <Add directory="../../include" /> </Compiler> + <Linker> + <Add library="/usr/lib/libpthread.a" /> + </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj\Release_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="obj/Release_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -41,6 +44,7 @@ <code_completion /> <debugger /> <lib_finder disable_auto="1" /> + <envvars /> </Extensions> </Project> </CodeBlocks_project_file> Added: trunk/test/ThreadLocal/ThreadPool.cpp =================================================================== --- trunk/test/ThreadLocal/ThreadPool.cpp (rev 0) +++ trunk/test/ThreadLocal/ThreadPool.cpp 2011-09-29 20:36:38 UTC (rev 1118) @@ -0,0 +1,117 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// ThreadLocal test program for The Loki Library +// Copyright (c) 2009 by Richard Sposato +// The copyright on this file is protected under the terms of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- + +#include "ThreadPool.hpp" + +#include <sstream> +#include <iostream> + +// ---------------------------------------------------------------------------- + +Thread::Thread( CallFunction func, void * parm ) + : pthread_() + , func_( func ) + , parm_( parm ) +{ +} + +// ---------------------------------------------------------------------------- + +void Thread::AssignTask( CallFunction func, void * parm ) +{ + func_ = func; + parm_ = parm; +} + +// ---------------------------------------------------------------------------- + +int Thread::Start( void ) +{ + return LOKI_pthread_create( &pthread_, NULL, func_, parm_ ); +} + +// ---------------------------------------------------------------------------- + +int Thread::WaitForThread( void ) const +{ + return LOKI_pthread_join( pthread_ ); +} + +// ---------------------------------------------------------------------------- + +ThreadPool::ThreadPool( void ) : m_threads() +{ +} + +// ---------------------------------------------------------------------------- + +ThreadPool::~ThreadPool( void ) +{ + for ( size_t ii = 0; ii < m_threads.size(); ++ii ) + { + delete m_threads.at(ii); + } +} + +// ---------------------------------------------------------------------------- + +void ThreadPool::Create( size_t threadCount, Thread::CallFunction function ) +{ + for( size_t ii = 0; ii < threadCount; ii++ ) + { + ::std::stringstream buffer; + buffer << "Creating thread " << ii << ::std::endl; + ::std::cout << buffer.rdbuf(); + Thread * thread = new Thread( function, + reinterpret_cast< void * >( ii + 1 ) ); + m_threads.push_back( thread ); + } +} + +// ---------------------------------------------------------------------------- + +void ThreadPool::Start( void ) +{ + for ( size_t ii = 0; ii < m_threads.size(); ii++ ) + { + ::std::stringstream buffer; + buffer << "Starting thread " << ii << ::std::endl; + ::std::cout << buffer.rdbuf(); + m_threads.at( ii )->Start(); + } +} + +// ---------------------------------------------------------------------------- + +void ThreadPool::Join( void ) const +{ + for ( size_t ii = 0; ii < m_threads.size(); ii++ ) + m_threads.at( ii )->WaitForThread(); +} + +// ---------------------------------------------------------------------------- Added: trunk/test/ThreadLocal/ThreadPool.hpp =================================================================== --- trunk/test/ThreadLocal/ThreadPool.hpp (rev 0) +++ trunk/test/ThreadLocal/ThreadPool.hpp 2011-09-29 20:36:38 UTC (rev 1118) @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// ThreadLocal test program for The Loki Library +// Copyright (c) 2009 by Richard Sposato +// The copyright on this file is protected under the terms of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + + +// ---------------------------------------------------------------------------- + +#include <vector> + +#if !defined( NULL ) + #define NULL 0 +#endif + +// define nullptr even though new compilers will have this keyword just so we +// have a consistent and easy way of identifying which uses of 0 mean null. +#if !defined( nullptr ) + #define nullptr NULL +#endif + +#if defined(_WIN32) + + #include <process.h> + #include <windows.h> + + typedef unsigned int ( WINAPI * ThreadFunction_ )( void * ); + + #define LOKI_pthread_t HANDLE + + #define LOKI_pthread_create( handle, attr, func, arg ) \ + ( int )( ( *handle = ( HANDLE ) _beginthreadex ( NULL, 0, ( ThreadFunction_ )func, arg, 0, NULL ) ) == NULL ) + + #define LOKI_pthread_join( thread ) \ + ( ( WaitForSingleObject( ( thread ), INFINITE ) != WAIT_OBJECT_0 ) || !CloseHandle( thread ) ) + +#else + + #include <pthread.h> + + #define LOKI_pthread_t \ + pthread_t + #define LOKI_pthread_create(handle,attr,func,arg) \ + pthread_create(handle,attr,func,arg) + #define LOKI_pthread_join(thread) \ + pthread_join(thread, NULL) + +#endif + +// ---------------------------------------------------------------------------- + +class Thread +{ +public: + + typedef void * ( * CallFunction )( void * ); + + Thread( CallFunction func, void * parm ); + + void AssignTask( CallFunction func, void * parm ); + + int Start( void ); + + int WaitForThread( void ) const; + +private: + + LOKI_pthread_t pthread_; + + CallFunction func_; + + void * parm_; + +}; + +// ---------------------------------------------------------------------------- + +class ThreadPool +{ +public: + + ThreadPool( void ); + + ~ThreadPool( void ); + + void Create( size_t threadCount, Thread::CallFunction function ); + + void Start( void ); + + void Join( void ) const; + +private: + + typedef ::std::vector< Thread * > Threads; + + Threads m_threads; +}; + +// ---------------------------------------------------------------------------- Added: trunk/test/ThreadLocal/ThreadTests.cpp =================================================================== --- trunk/test/ThreadLocal/ThreadTests.cpp (rev 0) +++ trunk/test/ThreadLocal/ThreadTests.cpp 2011-09-29 20:36:38 UTC (rev 1118) @@ -0,0 +1,246 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// ThreadLocal test program for The Loki Library +// Copyright (c) 2009 by Richard Sposato +// The copyright on this file is protected under the terms of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +//////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- + +#include "ThreadPool.hpp" + +#include <loki/ThreadLocal.h> + +#include <vector> +#include <sstream> +#include <iostream> + +#include <cassert> + + +// ---------------------------------------------------------------------------- + +typedef ::std::vector< unsigned int > IntVector; + +static LOKI_THREAD_LOCAL unsigned int StandaloneStaticValue = 0; + +static const unsigned int ThreadCount = 4; + +// ---------------------------------------------------------------------------- + +IntVector & GetIntVector( void ) +{ + unsigned int v = 0; + static IntVector addresses( ThreadCount, v ); + return addresses; +} + +// ---------------------------------------------------------------------------- + +void * AddToIntVector( void * p ) +{ + assert( 0 == StandaloneStaticValue ); + const unsigned int ii = reinterpret_cast< unsigned int >( p ); + assert( 0 < ii ); + assert( ii < ThreadCount + 1 ); + StandaloneStaticValue = ii; + IntVector & v = GetIntVector(); + v[ ii - 1 ] = StandaloneStaticValue; + assert( ii == StandaloneStaticValue ); + assert( v[ ii - 1 ] == StandaloneStaticValue ); + return nullptr; +} + +// ---------------------------------------------------------------------------- + +bool TestThreadLocalStaticValue( void ) +{ + assert( StandaloneStaticValue == 0 ); + { + ThreadPool pool; + pool.Create( ThreadCount, &AddToIntVector ); + pool.Start(); + pool.Join(); + } + + bool allDifferent = true; + IntVector & v = GetIntVector(); + for ( unsigned int i1 = 0; i1 < ThreadCount - 1; ++i1 ) + { + const unsigned int v1 = v[ i1 ]; + for ( unsigned int i2 = i1 + 1; i2 < ThreadCount; ++i2 ) + { + const unsigned int v2 = v[ i2 ]; + if ( v1 == v2 ) + { + allDifferent = false; + break; + } + } + if ( !allDifferent ) + break; + } + assert( StandaloneStaticValue == 0 ); + + return allDifferent; +} + +// ---------------------------------------------------------------------------- + +unsigned int & GetFunctionThreadLocalValue( void ) +{ + static LOKI_THREAD_LOCAL unsigned int FunctionStaticValue = 0; + return FunctionStaticValue; +} + +// ---------------------------------------------------------------------------- + +void * ChangeFunctionStaticValue( void * p ) +{ + unsigned int & thatValue = GetFunctionThreadLocalValue(); + assert( 0 == thatValue ); + const unsigned int ii = reinterpret_cast< unsigned int >( p ); + assert( 0 < ii ); + assert( ii < ThreadCount + 1 ); + thatValue = ii + ThreadCount; + IntVector & v = GetIntVector(); + v[ ii - 1 ] = thatValue + ThreadCount; + assert( ii + ThreadCount == thatValue ); + assert( v[ ii - 1 ] == thatValue + ThreadCount ); + return nullptr; +} + +// ---------------------------------------------------------------------------- + +bool TestThreadLocalFunctionStaticValue( void ) +{ + assert( GetFunctionThreadLocalValue() == 0 ); + + IntVector & v = GetIntVector(); + for ( unsigned int i0 = 0; i0 < v.size(); ++i0 ) + { + v[ i0 ] = 0; + } + + { + ThreadPool pool; + pool.Create( ThreadCount, &ChangeFunctionStaticValue ); + pool.Start(); + pool.Join(); + } + + bool allDifferent = true; + for ( unsigned int i1 = 0; i1 < ThreadCount - 1; ++i1 ) + { + const unsigned int v1 = v[ i1 ]; + for ( unsigned int i2 = i1 + 1; i2 < ThreadCount; ++i2 ) + { + const unsigned int v2 = v[ i2 ]; + if ( v1 == v2 ) + { + allDifferent = false; + break; + } + } + if ( !allDifferent ) + break; + } + assert( GetFunctionThreadLocalValue() == 0 ); + + return allDifferent; +} + +// ---------------------------------------------------------------------------- + +class ThreadAware +{ +public: + + static inline void SetValue( unsigned int value ) { ClassThreadLocal = value; } + + static inline unsigned int GetValue( void ) { return ClassThreadLocal; } + +private: + + static LOKI_THREAD_LOCAL unsigned int ClassThreadLocal; + +}; + +LOKI_THREAD_LOCAL unsigned int ThreadAware::ClassThreadLocal = 0; + +// ---------------------------------------------------------------------------- + +void * ChangeClassStaticValue( void * p ) +{ + assert( ThreadAware::GetValue() == 0 ); + const unsigned int ii = reinterpret_cast< unsigned int >( p ); + assert( 0 < ii ); + assert( ii < ThreadCount + 1 ); + ThreadAware::SetValue( ii + 2 * ThreadCount ); + IntVector & v = GetIntVector(); + v[ ii - 1 ] = ThreadAware::GetValue(); + assert( v[ ii - 1 ] == ThreadAware::GetValue() ); + assert( ThreadAware::GetValue() == ii + 2 * ThreadCount ); + return nullptr; +} + +// ---------------------------------------------------------------------------- + +bool TestThreadLocalClassStaticValue( void ) +{ + assert( ThreadAware::GetValue() == 0 ); + + IntVector & v = GetIntVector(); + for ( unsigned int i0 = 0; i0 < v.size(); ++i0 ) + { + v[ i0 ] = 0; + } + + { + ThreadPool pool; + pool.Create( ThreadCount, &ChangeClassStaticValue ); + pool.Start(); + pool.Join(); + } + + bool allDifferent = true; + for ( unsigned int i1 = 0; i1 < ThreadCount - 1; ++i1 ) + { + const unsigned int v1 = v[ i1 ]; + for ( unsigned int i2 = i1 + 1; i2 < ThreadCount; ++i2 ) + { + const unsigned int v2 = v[ i2 ]; + if ( v1 == v2 ) + { + allDifferent = false; + break; + } + } + if ( !allDifferent ) + break; + } + assert( ThreadAware::GetValue() == 0 ); + + return allDifferent; +} + +// ---------------------------------------------------------------------------- Modified: trunk/test/ThreadLocal/main.cpp =================================================================== --- trunk/test/ThreadLocal/main.cpp 2011-09-29 19:56:39 UTC (rev 1117) +++ trunk/test/ThreadLocal/main.cpp 2011-09-29 20:36:38 UTC (rev 1118) @@ -4,367 +4,48 @@ // Copyright (c) 2009 by Richard Sposato // The copyright on this file is protected under the terms of the MIT license. // -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this -// permission notice appear in supporting documentation. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: // -// The author makes no representations about the suitability of this software -// for any purpose. It is provided "as is" without express or implied warranty. +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// //////////////////////////////////////////////////////////////////////////////// -// $Id$ +// ---------------------------------------------------------------------------- +#include <cstdlib> -// ---------------------------------------------------------------------------- +#include <iostream> -#include <loki/ThreadLocal.h> -#include <loki/Threads.h> - -#include <vector> -#include <sstream> -#include <iostream> - - using namespace ::std; - -#if !defined( NULL ) - #define NULL 0 -#endif - -// define nullptr even though new compilers will have this keyword just so we -// have a consistent and easy way of identifying which uses of 0 mean null. -#if !defined( nullptr ) - #define nullptr NULL -#endif - -#if defined(_WIN32) - #include <process.h> - #include <windows.h> +extern bool TestThreadLocalClassStaticValue( void ); - typedef unsigned int ( WINAPI * ThreadFunction_ )( void * ); +extern bool TestThreadLocalFunctionStaticValue( void ); - #define LOKI_pthread_t HANDLE +extern bool TestThreadLocalStaticValue( void ); - #define LOKI_pthread_create( handle, attr, func, arg ) \ - ( int )( ( *handle = ( HANDLE ) _beginthreadex ( NULL, 0, ( ThreadFunction_ )func, arg, 0, NULL ) ) == NULL ) - #define LOKI_pthread_join( thread ) \ - ( ( WaitForSingleObject( ( thread ), INFINITE ) != WAIT_OBJECT_0 ) || !CloseHandle( thread ) ) - -#else - - #define LOKI_pthread_t \ - pthread_t - #define LOKI_pthread_create(handle,attr,func,arg) \ - pthread_create(handle,attr,func,arg) - #define LOKI_pthread_join(thread) \ - pthread_join(thread, NULL) - -#endif - // ---------------------------------------------------------------------------- -class Thread +int main( int argc, const char * const argv[] ) { -public: - - typedef void * ( * CallFunction )( void * ); - - Thread( CallFunction func, void * parm ) - : pthread_() - , func_( func ) - , parm_( parm ) - { - } - - void AssignTask( CallFunction func, void * parm ) - { - func_ = func; - parm_ = parm; - } - - int Start( void ) - { - return LOKI_pthread_create( &pthread_, NULL, func_, parm_ ); - } - - int WaitForThread( void ) const - { - return LOKI_pthread_join( pthread_ ); - } - -private: - LOKI_pthread_t pthread_; - CallFunction func_; - void * parm_; -}; - -// ---------------------------------------------------------------------------- - -class ThreadPool -{ -public: - ThreadPool( void ) : m_threads() - { - } - - void Create( size_t threadCount, Thread::CallFunction function ) - { - for( size_t ii = 0; ii < threadCount; ii++ ) - { - stringstream buffer; - buffer << "Creating thread " << ii << endl; - cout << buffer.rdbuf(); - Thread * thread = new Thread( function, - reinterpret_cast< void * >( ii + 1 ) ); - m_threads.push_back( thread ); - } - } - - void Start( void ) - { - for ( size_t ii = 0; ii < m_threads.size(); ii++ ) - { - stringstream buffer; - buffer << "Starting thread " << ii << endl; - cout << buffer.rdbuf(); - m_threads.at( ii )->Start(); - } - } - - void Join( void ) const - { - for ( size_t ii = 0; ii < m_threads.size(); ii++ ) - m_threads.at( ii )->WaitForThread(); - } - - ~ThreadPool( void ) - { - for ( size_t ii = 0; ii < m_threads.size(); ii++ ) - { - delete m_threads.at(ii); - } - } - -private: - typedef std::vector< Thread * > Threads; - - Threads m_threads; -}; - -// ---------------------------------------------------------------------------- + (void)argc; + (void)argv; -typedef ::std::vector< unsigned int > IntVector; - -static LOKI_THREAD_LOCAL unsigned int StandaloneStaticValue = 0; - -static const unsigned int ThreadCount = 4; - -// ---------------------------------------------------------------------------- - -IntVector & GetIntVector( void ) -{ - unsigned int v = 0; - static IntVector addresses( ThreadCount, v ); - return addresses; -} - -// ---------------------------------------------------------------------------- - -void * AddToIntVector( void * p ) -{ - assert( 0 == StandaloneStaticValue ); - const unsigned int ii = reinterpret_cast< unsigned int >( p ); - assert( 0 < ii ); - assert( ii < ThreadCount + 1 ); - StandaloneStaticValue = ii; - IntVector & v = GetIntVector(); - v[ ii - 1 ] = StandaloneStaticValue; - assert( ii == StandaloneStaticValue ); - assert( v[ ii - 1 ] == StandaloneStaticValue ); - return nullptr; -} - -// ---------------------------------------------------------------------------- - -bool TestThreadLocalStaticValue( void ) -{ - assert( StandaloneStaticValue == 0 ); - { - ThreadPool pool; - pool.Create( ThreadCount, &AddToIntVector ); - pool.Start(); - pool.Join(); - } - - bool allDifferent = true; - IntVector & v = GetIntVector(); - for ( unsigned int i1 = 0; i1 < ThreadCount - 1; ++i1 ) - { - const unsigned int v1 = v[ i1 ]; - for ( unsigned int i2 = i1 + 1; i2 < ThreadCount; ++i2 ) - { - const unsigned int v2 = v[ i2 ]; - if ( v1 == v2 ) - { - allDifferent = false; - break; - } - } - if ( !allDifferent ) - break; - } - assert( StandaloneStaticValue == 0 ); - - return allDifferent; -} - -// ---------------------------------------------------------------------------- - -unsigned int & GetFunctionThreadLocalValue( void ) -{ - static LOKI_THREAD_LOCAL unsigned int FunctionStaticValue = 0; - return FunctionStaticValue; -} - -// ---------------------------------------------------------------------------- - -void * ChangeFunctionStaticValue( void * p ) -{ - unsigned int & thatValue = GetFunctionThreadLocalValue(); - assert( 0 == thatValue ); - const unsigned int ii = reinterpret_cast< unsigned int >( p ); - assert( 0 < ii ); - assert( ii < ThreadCount + 1 ); - thatValue = ii + ThreadCount; - IntVector & v = GetIntVector(); - v[ ii - 1 ] = thatValue + ThreadCount; - assert( ii + ThreadCount == thatValue ); - assert( v[ ii - 1 ] == thatValue + ThreadCount ); - return nullptr; -} - -// ---------------------------------------------------------------------------- - -bool TestThreadLocalFunctionStaticValue( void ) -{ - assert( GetFunctionThreadLocalValue() == 0 ); - - IntVector & v = GetIntVector(); - for ( unsigned int i0 = 0; i0 < v.size(); ++i0 ) - { - v[ i0 ] = 0; - } - - { - ThreadPool pool; - pool.Create( ThreadCount, &ChangeFunctionStaticValue ); - pool.Start(); - pool.Join(); - } - - bool allDifferent = true; - for ( unsigned int i1 = 0; i1 < ThreadCount - 1; ++i1 ) - { - const unsigned int v1 = v[ i1 ]; - for ( unsigned int i2 = i1 + 1; i2 < ThreadCount; ++i2 ) - { - const unsigned int v2 = v[ i2 ]; - if ( v1 == v2 ) - { - allDifferent = false; - break; - } - } - if ( !allDifferent ) - break; - } - assert( GetFunctionThreadLocalValue() == 0 ); - - return allDifferent; -} - -// ---------------------------------------------------------------------------- - -class ThreadAware -{ -public: - - static inline void SetValue( unsigned int value ) { ClassThreadLocal = value; } - - static inline unsigned int GetValue( void ) { return ClassThreadLocal; } - -private: - - static LOKI_THREAD_LOCAL unsigned int ClassThreadLocal; - -}; - -LOKI_THREAD_LOCAL unsigned int ThreadAware::ClassThreadLocal = 0; - -// ---------------------------------------------------------------------------- - -void * ChangeClassStaticValue( void * p ) -{ - assert( ThreadAware::GetValue() == 0 ); - const unsigned int ii = reinterpret_cast< unsigned int >( p ); - assert( 0 < ii ); - assert( ii < ThreadCount + 1 ); - ThreadAware::SetValue( ii + 2 * ThreadCount ); - IntVector & v = GetIntVector(); - v[ ii - 1 ] = ThreadAware::GetValue(); - assert( v[ ii - 1 ] == ThreadAware::GetValue() ); - assert( ThreadAware::GetValue() == ii + 2 * ThreadCount ); - return nullptr; -} - -// ---------------------------------------------------------------------------- - -bool TestThreadLocalClassStaticValue( void ) -{ - assert( ThreadAware::GetValue() == 0 ); - - IntVector & v = GetIntVector(); - for ( unsigned int i0 = 0; i0 < v.size(); ++i0 ) - { - v[ i0 ] = 0; - } - - { - ThreadPool pool; - pool.Create( ThreadCount, &ChangeClassStaticValue ); - pool.Start(); - pool.Join(); - } - - bool allDifferent = true; - for ( unsigned int i1 = 0; i1 < ThreadCount - 1; ++i1 ) - { - const unsigned int v1 = v[ i1 ]; - for ( unsigned int i2 = i1 + 1; i2 < ThreadCount; ++i2 ) - { - const unsigned int v2 = v[ i2 ]; - if ( v1 == v2 ) - { - allDifferent = false; - break; - } - } - if ( !allDifferent ) - break; - } - assert( ThreadAware::GetValue() == 0 ); - - return allDifferent; -} - -// ---------------------------------------------------------------------------- - -int main( int argc, const char * const argv[] ) -{ bool okay = true; cout << "Starting ThreadLocal tests." << endl; cout << "If any tests fail, or any assertions fail," << endl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <syn...@us...> - 2011-09-29 19:56:45
|
Revision: 1117 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1117&view=rev Author: syntheticpp Date: 2011-09-29 19:56:39 +0000 (Thu, 29 Sep 2011) Log Message: ----------- remove some GCC warnings and update Makefile Modified Paths: -------------- trunk/include/loki/LevelMutex.h trunk/include/loki/SmallObj.h trunk/include/loki/StrongPtr.h trunk/src/LevelMutex.cpp trunk/src/SmallObj.cpp trunk/src/StrongPtr.cpp trunk/test/SmartPtr/Makefile Modified: trunk/include/loki/LevelMutex.h =================================================================== --- trunk/include/loki/LevelMutex.h 2011-09-23 00:46:54 UTC (rev 1116) +++ trunk/include/loki/LevelMutex.h 2011-09-29 19:56:39 UTC (rev 1117) @@ -254,7 +254,7 @@ /** Returns true if this mutex was locked within the last count mutexes. @param count How many recent mutexes to look through to find this mutex. */ - bool IsRecentLock( unsigned int count ) const volatile; + bool IsRecentLock( std::size_t count ) const volatile; /// Returns true if this was locked by current thread. bool IsLockedByCurrentThread( void ) const volatile; Modified: trunk/include/loki/SmallObj.h =================================================================== --- trunk/include/loki/SmallObj.h 2011-09-23 00:46:54 UTC (rev 1116) +++ trunk/include/loki/SmallObj.h 2011-09-29 19:56:39 UTC (rev 1117) @@ -88,7 +88,7 @@ namespace Private { class FixedAllocator; - }; // end namespace Private + } // end namespace Private /** @class SmallObjAllocator @ingroup SmallObjectGroupInternal Modified: trunk/include/loki/StrongPtr.h =================================================================== --- trunk/include/loki/StrongPtr.h 2011-09-23 00:46:54 UTC (rev 1116) +++ trunk/include/loki/StrongPtr.h 2011-09-29 19:56:39 UTC (rev 1117) @@ -1468,9 +1468,9 @@ inline explicit TwoRefLinks( bool strong ) : m_pointer( 0 ) - , m_strong( strong ) , m_prev( this ) , m_next( this ) + , m_strong( strong ) { } Modified: trunk/src/LevelMutex.cpp =================================================================== --- trunk/src/LevelMutex.cpp 2011-09-23 00:46:54 UTC (rev 1116) +++ trunk/src/LevelMutex.cpp 2011-09-29 19:56:39 UTC (rev 1117) @@ -200,7 +200,7 @@ MutexErrors::Type DoMutexesMatchContainer( const LevelMutexInfo::MutexContainer & mutexes ) { - const unsigned int count = mutexes.size(); + const std::size_t count = mutexes.size(); if ( 0 == count ) return MutexErrors::EmptyContainer; unsigned int currentLevel = GetCurrentThreadsLevel(); @@ -334,7 +334,7 @@ { assert( IsValidList() ); - const unsigned int count = mutexes.size(); + const std::size_t count = mutexes.size(); if ( count == 0 ) return MutexErrors::EmptyContainer; @@ -417,7 +417,8 @@ if ( 0 == milliSeconds ) return MultiLock( mutexes ); - const unsigned int count = mutexes.size(); + + const std::size_t count = mutexes.size(); if ( 0 == count ) return MutexErrors::EmptyContainer; @@ -507,7 +508,7 @@ LevelMutexInfo::UnlockedLevel, result ); } - const unsigned int count = mutexes.size(); + const std::size_t count = mutexes.size(); if ( 1 < count ) { ::std::sort( mutexes.begin(), mutexes.end() ); @@ -628,7 +629,7 @@ // ---------------------------------------------------------------------------- -bool LevelMutexInfo::IsRecentLock( unsigned int count ) const volatile +bool LevelMutexInfo::IsRecentLock( std::size_t count ) const volatile { LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; ) Modified: trunk/src/SmallObj.cpp =================================================================== --- trunk/src/SmallObj.cpp 2011-09-23 00:46:54 UTC (rev 1116) +++ trunk/src/SmallObj.cpp 2011-09-29 19:56:39 UTC (rev 1117) @@ -1119,7 +1119,7 @@ // ---------------------------------------------------------------------------- -}; // end namespace Private +} // end namespace Private using namespace ::Loki::Private; Modified: trunk/src/StrongPtr.cpp =================================================================== --- trunk/src/StrongPtr.cpp 2011-09-23 00:46:54 UTC (rev 1116) +++ trunk/src/StrongPtr.cpp 2011-09-29 19:56:39 UTC (rev 1117) @@ -344,9 +344,9 @@ TwoRefLinks::TwoRefLinks( const void * p, bool strong ) : m_pointer( const_cast< void * >( p ) ) - , m_strong( strong ) , m_prev( this ) , m_next( this ) + , m_strong( strong ) { assert( IsValid() ); } Modified: trunk/test/SmartPtr/Makefile =================================================================== --- trunk/test/SmartPtr/Makefile 2011-09-23 00:46:54 UTC (rev 1116) +++ trunk/test/SmartPtr/Makefile 2011-09-29 19:56:39 UTC (rev 1117) @@ -1,7 +1,7 @@ include ../Makefile.common BIN := main$(BIN_SUFFIX) -SRC := main.cpp strong.cpp LockTest.cpp +SRC := main.cpp strong.cpp LockTest.cpp colvin_gibbons_trick.cpp OBJ := $(SRC:.cpp=.o) LDLIBS += -lpthread This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |