Class provides thread operating routine. More...
#include <system/thread_abstraction.h>
Public Member Functions | |
ThreadAbstraction (void) | |
void | CreateThread (void *(*theThreadFunction)(void *), void *theThreadParam) |
void | Release (void) |
~ThreadAbstraction () | |
Static Public Member Functions | |
static void | Sleep (std::size_t Milliseconds) |
Private Member Functions | |
ThreadAbstraction | operator= (const ThreadAbstraction &Thread) |
ThreadAbstraction (const ThreadAbstraction &Thread) | |
Private Attributes | |
void * | ThreadData |
void * | ThreadParam |
void *(* | ThreadFunction )(void *) |
Class provides thread operating routine.
Definition at line 52 of file thread_abstraction.h.
nitro::ThreadAbstraction::ThreadAbstraction | ( | void | ) |
Constructor.
nitro::exception | - An exception of that type is thrown if ahy error occured. |
Definition at line 124 of file thread_abstraction.cpp.
References ThreadData, and ThreadFunction.
{ ThreadFunction = NULL; ThreadData = NULL; }
nitro::ThreadAbstraction::~ThreadAbstraction | ( | ) |
Destructor (virtual).
Definition at line 131 of file thread_abstraction.cpp.
References Release().
{ try { Release(); } catch( nitro::exception e ) { } catch( ... ) { } }
nitro::ThreadAbstraction::ThreadAbstraction | ( | const ThreadAbstraction & | Thread | ) | [inline, private] |
void nitro::ThreadAbstraction::CreateThread | ( | void *(*)(void *) | theThreadFunction, | |
void * | theThreadParam | |||
) |
Function creates thread.
nitro::exception | - An exception of that type is thrown if ahy error occured. |
Definition at line 28 of file thread_abstraction.cpp.
References nitro::exception::code(), Release(), ThreadData, ThreadFunction, ThreadParam, and nitro::exception::what().
Referenced by nitro::Timer::Run(), and nitro::Thread::Run().
{ try { Release(); ThreadFunction = theThreadFunction; ThreadParam = theThreadParam; #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM ) ThreadData = ( void * )new HANDLE; * ( ( HANDLE * ) ThreadData ) = ::CreateThread( 0 , 0 , ( LPTHREAD_START_ROUTINE )WinThreadFunction , this , 0 , 0 ); if( ! * ( ( HANDLE * ) ThreadData ) ) { throw( nitro::exception( std::string( "An error occured while thread creation" ) , 0 ) ); } #endif #if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM ) ThreadData = ( void * )new pthread_t; if( pthread_create( ( pthread_t * )ThreadData , NULL , theThreadFunction , ( void * ) theThreadParam ) ) { throw( nitro::exception( std::string( "An error occured while thread creation" ) , 0 ) ); } if( pthread_detach( * ( ( pthread_t * )ThreadData ) ) ) { throw( nitro::exception( std::string( "An error occured while thread detaching" ) , 0 ) ); } #endif } catch( nitro::exception e ) { throw( nitro::exception( std::string( "ThreadAbstraction::CreateThread( void ( * theThreadFunction )( void * ) , void * theThreadParam )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "ThreadAbstraction::CreateThread( void ( * theThreadFunction )( void * ) , void * theThreadParam )::An error occured" ) , 0 ) ); } }
ThreadAbstraction nitro::ThreadAbstraction::operator= | ( | const ThreadAbstraction & | Thread | ) | [inline, private] |
void nitro::ThreadAbstraction::Release | ( | void | ) |
Function releases all data.
nitro::exception | - An exception of that type is thrown if ahy error occured. |
Definition at line 73 of file thread_abstraction.cpp.
References nitro::exception::code(), ThreadData, and nitro::exception::what().
Referenced by CreateThread(), and ~ThreadAbstraction().
{ try { if( ThreadData != NULL ) { #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM ) delete ( HANDLE * ) ThreadData; #endif #if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM ) delete ( pthread_t * ) ThreadData; #endif ThreadData = NULL; } } catch( nitro::exception e ) { throw( nitro::exception( std::string( "ThreadAbstraction::Release( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "ThreadAbstraction::Release( void )::An error occured" ) , 0 ) ); } }
void nitro::ThreadAbstraction::Sleep | ( | std::size_t | Milliseconds | ) | [static] |
Function suspends the execution of the current thread for the specified interval.
Milliseconds | - Interval. |
nitro::exception | - An exception of that type is thrown if ahy error occured. |
Definition at line 99 of file thread_abstraction.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by nitro::_TimerWrapperFunction().
{ try { #if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM ) ::Sleep( ( DWORD )Milliseconds ); #endif #if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM ) if( usleep( Milliseconds * 1000 ) == -1 ) { throw( nitro::exception( "An erro occured while usleep call" , 1 ) ); } #endif } catch( nitro::exception e ) { throw( nitro::exception( std::string( "ThreadAbstraction::Sleep( const std::size_t & Milliseconds )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "ThreadAbstraction::Sleep( const std::size_t & Milliseconds )::An error occured" ) , 0 ) ); } }
void* nitro::ThreadAbstraction::ThreadData [private] |
Thread handle.
Definition at line 156 of file thread_abstraction.h.
Referenced by CreateThread(), Release(), and ThreadAbstraction().
void*( * nitro::ThreadAbstraction::ThreadFunction)(void *) [private] |
Thread function pointer.
Definition at line 180 of file thread_abstraction.h.
Referenced by CreateThread(), and ThreadAbstraction().
void* nitro::ThreadAbstraction::ThreadParam [private] |
Thread execution parameters.
Definition at line 168 of file thread_abstraction.h.
Referenced by CreateThread().