Class for thread sinchronization. More...
#include <system/mutex_abstraction.h>
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 |
Class for thread sinchronization.
Definition at line 45 of file mutex_abstraction.h.
| nitro::MutexAbstraction::MutexAbstraction | ( | void | ) |
Constructor.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
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 ) );
}
}

| nitro::MutexAbstraction::~MutexAbstraction | ( | ) | [virtual] |
Destructor.
Definition at line 37 of file mutex_abstraction.cpp.
References Release().
{
try
{
Release();
}
catch( ... )
{
}
}

| nitro::MutexAbstraction::MutexAbstraction | ( | const MutexAbstraction & | m | ) | [private] |
Copy contructor.
| m | - Mutex to be copied. |
Definition at line 176 of file mutex_abstraction.cpp.
{
}
| void nitro::MutexAbstraction::CreateMutex | ( | void | ) |
Function creates mutex.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
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 ) );
}
}

| void nitro::MutexAbstraction::Lock | ( | void | ) |
Function blocks critical section for any outside access.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
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 ) );
}
}

| MutexAbstraction nitro::MutexAbstraction::operator= | ( | const MutexAbstraction & | m | ) | [private] |
Assign operator.
| m | - Mutex to be copied. |
Definition at line 180 of file mutex_abstraction.cpp.
{
return( *this );
}
| void nitro::MutexAbstraction::Release | ( | void | ) |
Function dletes mutex.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
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 ) );
}
}

| void nitro::MutexAbstraction::UnLock | ( | void | ) |
Function unlocks critical section.
| nitro::exception | - An exception of that type is thrown. Contains error description. |
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 ) );
}
}

void* nitro::MutexAbstraction::Mutex [private] |
Mutex handle.
Definition at line 152 of file mutex_abstraction.h.
Referenced by CreateMutex(), Lock(), MutexAbstraction(), Release(), and UnLock().
1.6.1