GlobalObjects
Loading...
Searching...
No Matches
EuPCriticalSection Class Reference

Is a mutex which can be queried via its lock mode. See isLocked(). More...

#include <EuPCriticalSection.h>

Inheritance diagram for EuPCriticalSection:

Public Member Functions

 EuPCriticalSection ()
 
 EuPCriticalSection (const EuPCriticalSection &rT)
 
virtual ~EuPCriticalSection ()
 
pthread_mutex_t & getMutex ()
 
bool isLocked () const
 
int lock ()
 
EuPCriticalSectionoperator= (const EuPCriticalSection &rT)
 
int unlock ()
 

Private Attributes

bool m_bIsLocked
 
pthread_mutex_t m_Mutex
 

Detailed Description

Is a mutex which can be queried via its lock mode. See isLocked().

Example

void MyClass::makeAnyThing()
{
m_MyLocalCriticalSection->lock();
// An access from a thread to m_pMyPrivateClass->makeManyThings() via this
// method prevents other threads from accessing this method (or other methods
// secured with m_MyLocalCriticalSection) before the CriticalSection is
// finished with unlock() from the first thread.
this->makeManyThings();
// catch an exception here if one can be thrown.
m_MyLocalCriticalSection->unlock();
}
Note
Based on 32 bit POSIX threads.
Author
Helmut Jakoby

Constructor & Destructor Documentation

◆ EuPCriticalSection() [1/2]

EuPCriticalSection::EuPCriticalSection ( )

Constructor. An m_Mutex is initialized.

◆ ~EuPCriticalSection()

virtual EuPCriticalSection::~EuPCriticalSection ( )
virtual

Destructor, the m_Mutex is destroyed.

◆ EuPCriticalSection() [2/2]

EuPCriticalSection::EuPCriticalSection ( const EuPCriticalSection & rT)

Copy constructor.

Parameters
[in]rTThe data is copied from this object.

Member Function Documentation

◆ getMutex()

pthread_mutex_t & EuPCriticalSection::getMutex ( )

Delivers the mutex.

Returns
The own mutex
Attention
The delivered mutex only lives as long as the supplying EuPCriticalSection.

◆ isLocked()

bool EuPCriticalSection::isLocked ( ) const

Is the CriticalSection in lock mode?

Returns
If true, then in lock mode.

◆ lock()

int EuPCriticalSection::lock ( )

Initiates a CriticalSection.

Returns
A return value < 0 indicates an error.
Attention
The CriticalSection must be terminated at some point.

◆ operator=()

EuPCriticalSection & EuPCriticalSection::operator= ( const EuPCriticalSection & rT)

Assignment operator.

Parameters
[in]rTThe data is transferred from this object.

◆ unlock()

int EuPCriticalSection::unlock ( )

Terminates a CriticalSection.

Returns
A return value < 0 indicates an error.

Member Data Documentation

◆ m_bIsLocked

bool EuPCriticalSection::m_bIsLocked
private

If an EuPCriticalSection blocks access, this attribute is set to true and on release it is set to false again.

◆ m_Mutex

pthread_mutex_t EuPCriticalSection::m_Mutex
private

A pthread_mutex_t object.

Initialized in the constructor and destroyed in the destructor.


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