GlobalObjects
Loading...
Searching...
No Matches
eut::CriticalSection Class Reference

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

#include <EuCriticalSection.h>

Public Member Functions

 CriticalSection ()
 
 CriticalSection (const CriticalSection &rT)
 
virtual ~CriticalSection ()
 
bool isLocked () const
 
void lock ()
 
CriticalSectionoperator= (const CriticalSection &rT)
 
void unlock ()
 

Private Attributes

bool m_bIsLocked
 
std::mutex m_ExclusiveAccessMutex
 

Detailed Description

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

Example

void MyClass::makeAnyThing()
{
m_MyCriticalSection->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_MyCriticalSection->unlock();
}
Author
Helmut Jakoby

Constructor & Destructor Documentation

◆ CriticalSection() [1/2]

eut::CriticalSection::CriticalSection ( )

Constructor.

◆ ~CriticalSection()

virtual eut::CriticalSection::~CriticalSection ( )
virtual

Destructor.

◆ CriticalSection() [2/2]

eut::CriticalSection::CriticalSection ( const CriticalSection & rT)

Copy constructor.

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

Member Function Documentation

◆ isLocked()

bool eut::CriticalSection::isLocked ( ) const

Is the CriticalSection in lock mode?

Returns
If true, then in lock mode.

◆ lock()

void eut::CriticalSection::lock ( )

Initiates a CriticalSection.

Attention
The CriticalSection must be terminated at some point.

◆ operator=()

CriticalSection & eut::CriticalSection::operator= ( const CriticalSection & rT)

Assignment operator.

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

◆ unlock()

void eut::CriticalSection::unlock ( )

Terminates a CriticalSection.

Member Data Documentation

◆ m_bIsLocked

bool eut::CriticalSection::m_bIsLocked
private

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

◆ m_ExclusiveAccessMutex

std::mutex eut::CriticalSection::m_ExclusiveAccessMutex
private

A mutex to protect local variables, for example.

See also
lock() and unlock()

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