Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

nitro::ThreadAbstraction Class Reference

Class provides thread operating routine. More...

#include <system/thread_abstraction.h>

List of all members.

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 *)

Detailed Description

Class provides thread operating routine.

Author:
Dodonov A.A.

Definition at line 52 of file thread_abstraction.h.


Constructor & Destructor Documentation

nitro::ThreadAbstraction::ThreadAbstraction ( void   ) 

Constructor.

Exceptions:
nitro::exception - An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

Definition at line 124 of file thread_abstraction.cpp.

References ThreadData, and ThreadFunction.

        {
                ThreadFunction = NULL;

                ThreadData = NULL;
        }

nitro::ThreadAbstraction::~ThreadAbstraction (  ) 

Destructor (virtual).

Author:
Dodonov A.A.

Definition at line 131 of file thread_abstraction.cpp.

References Release().

        {
                try
                {
                        Release();
                }
                catch( nitro::exception e )
                {
                }
                catch( ... )
                {
                }
        }

Here is the call graph for this function:

nitro::ThreadAbstraction::ThreadAbstraction ( const ThreadAbstraction Thread  )  [inline, private]

Private copy-constructor.

Parameters:
Thread - Thread object.
Author:
Dodonov A.A.

Definition at line 212 of file thread_abstraction.h.

{}


Member Function Documentation

void nitro::ThreadAbstraction::CreateThread ( void *(*)(void *)  theThreadFunction,
void *  theThreadParam 
)

Function creates thread.

Parameters:
theThreadFunction - Pointer on the thread function.
theThreadParam - Thread parameters.
Exceptions:
nitro::exception - An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

ThreadAbstraction nitro::ThreadAbstraction::operator= ( const ThreadAbstraction Thread  )  [inline, private]

Private assign operator.

Parameters:
Thread - Thread object.
Author:
Dodonov A.A.

Definition at line 196 of file thread_abstraction.h.

{return( *this );}

void nitro::ThreadAbstraction::Release ( void   ) 

Function releases all data.

Exceptions:
nitro::exception - An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::ThreadAbstraction::Sleep ( std::size_t  Milliseconds  )  [static]

Function suspends the execution of the current thread for the specified interval.

Parameters:
Milliseconds - Interval.
Exceptions:
nitro::exception - An exception of that type is thrown if ahy error occured.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

Thread handle.

Author:
Dodonov A.A.

Definition at line 156 of file thread_abstraction.h.

Referenced by CreateThread(), Release(), and ThreadAbstraction().

void*( * nitro::ThreadAbstraction::ThreadFunction)(void *) [private]

Thread function pointer.

Author:
Dodonov A.A.

Definition at line 180 of file thread_abstraction.h.

Referenced by CreateThread(), and ThreadAbstraction().

Thread execution parameters.

Author:
Dodonov A.A.

Definition at line 168 of file thread_abstraction.h.

Referenced by CreateThread().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.1