Public Member Functions | Private Member Functions | Private Attributes

nitro::MutexAbstraction Class Reference

Class for thread sinchronization. More...

#include <system/mutex_abstraction.h>

List of all members.

Public Member Functions

 MutexAbstraction (void)
void Release (void)
void CreateMutex (void)
void Lock (void)
void UnLock (void)
virtual ~MutexAbstraction ()

Private Member Functions

 MutexAbstraction (const MutexAbstraction &m)
MutexAbstraction operator= (const MutexAbstraction &m)

Private Attributes

void * Mutex

Detailed Description

Class for thread sinchronization.

Author:
Dodonov A.A.

Definition at line 45 of file mutex_abstraction.h.


Constructor & Destructor Documentation

nitro::MutexAbstraction::MutexAbstraction ( void   ) 

Constructor.

Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 21 of file mutex_abstraction.cpp.

References nitro::exception::code(), Mutex, and nitro::exception::what().

        {
                try
                {
                        Mutex = NULL;
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::MutexAbstraction( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::MutexAbstraction( void )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

nitro::MutexAbstraction::~MutexAbstraction (  )  [virtual]

Destructor.

Author:
Dodonov A.A.

Definition at line 37 of file mutex_abstraction.cpp.

References Release().

        {
                try
                {
                        Release();
                }
                catch( ... )
                {
                }
        }

Here is the call graph for this function:

nitro::MutexAbstraction::MutexAbstraction ( const MutexAbstraction m  )  [private]

Copy contructor.

Parameters:
m - Mutex to be copied.
Author:
Dodonov A.A.

Definition at line 176 of file mutex_abstraction.cpp.

        {
        }


Member Function Documentation

void nitro::MutexAbstraction::CreateMutex ( void   ) 

Function creates mutex.

Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 78 of file mutex_abstraction.cpp.

References nitro::exception::code(), Mutex, Release(), and nitro::exception::what().

Referenced by nitro::LogStream::Reset().

        {
                try
                {
                        Release();

                        #if     defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                                Mutex = ( void * )new HANDLE;

                                char            MutexName[ 1024 ];
                                memset( MutexName , 0 , 1024 );
                        #if     defined( WIN32_PLATFORM )
                                sprintf( MutexName , "%I64d" , ( __int64 )this );
                        #endif

                        #if     defined( MINGW_PLATFORM )
                                sprintf( MutexName , "%ld" , ( __int32 )this );
                        #endif
                                * ( ( HANDLE * )Mutex ) = ::CreateMutexA( NULL , false , MutexName );
                                if( * ( ( HANDLE * )Mutex ) == NULL )
                                {
                                        throw( nitro::exception( "Mutex was not initialized" , 1 ) );
                                }
                        #endif

                        #if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                                Mutex = ( void * )new pthread_mutex_t;

                                if( pthread_mutex_init( ( pthread_mutex_t * )Mutex , NULL ) != 0 )
                                {
                                        throw( nitro::exception( "Mutex was not initialized" , 1 ) );
                                }
                        #endif
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::CreateMutex( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::CreateMutex( void )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::MutexAbstraction::Lock ( void   ) 

Function blocks critical section for any outside access.

Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 122 of file mutex_abstraction.cpp.

References nitro::exception::code(), Mutex, and nitro::exception::what().

Referenced by nitro::LogStream::operator<<().

        {
                try
                {
                        if( Mutex )
                        {
                        #if     defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                                WaitForSingleObject( * ( ( HANDLE * )Mutex ) , INFINITE );
                        #endif

                        #if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                                std::cout<<"9"<<std::endl;
                                pthread_mutex_lock( ( pthread_mutex_t * )Mutex );
                                std::cout<<"10"<<std::endl;
                        #endif
                        }
                        else
                        {
                                std::cout<<"8"<<std::endl;
                                throw( nitro::exception( "Mutex was not initialized" , 1 ) );
                        }
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::Lock( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::Lock( void )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

MutexAbstraction nitro::MutexAbstraction::operator= ( const MutexAbstraction m  )  [private]

Assign operator.

Parameters:
m - Mutex to be copied.
Author:
Dodonov A.A.

Definition at line 180 of file mutex_abstraction.cpp.

        {
                return( *this );
        }

void nitro::MutexAbstraction::Release ( void   ) 

Function dletes mutex.

Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 48 of file mutex_abstraction.cpp.

References nitro::exception::code(), Mutex, and nitro::exception::what().

Referenced by CreateMutex(), nitro::LogStream::Release(), and ~MutexAbstraction().

        {
                try
                {
                        if( Mutex )
                        {
                        #if     defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                                CloseHandle( * ( ( HANDLE * )Mutex ) );

                                delete ( HANDLE * )Mutex;
                        #endif

                        #ifdef NIX_PLATFORM
                                pthread_mutex_destroy( ( pthread_mutex_t * )Mutex );

                                delete ( pthread_mutex_t * )Mutex;
                        #endif
                                Mutex = NULL;
                        }
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::Release( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::Release( void )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:

void nitro::MutexAbstraction::UnLock ( void   ) 

Function unlocks critical section.

Exceptions:
nitro::exception - An exception of that type is thrown. Contains error description.
Author:
Dodonov A.A.

Definition at line 154 of file mutex_abstraction.cpp.

References nitro::exception::code(), Mutex, and nitro::exception::what().

Referenced by nitro::LogStream::operator<<().

        {
                try
                {
                #if     defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
                        ReleaseMutex( * ( ( HANDLE * )Mutex ) );
                #endif

                #if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
                        pthread_mutex_unlock( ( pthread_mutex_t * )Mutex );
                #endif
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::UnLock( void )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "MutexAbstraction::UnLock( void )::An error occured" ) , 1 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

Mutex handle.

Author:
Dodonov A.A.

Definition at line 152 of file mutex_abstraction.h.

Referenced by CreateMutex(), Lock(), MutexAbstraction(), Release(), and UnLock().


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

Generated by  doxygen 1.6.1