Smart Mutex Pointer. More...

#include <rmutex.h>

Collaboration diagram for RSmartMutexPtr:
[legend]

Public Member Functions

 RSmartMutexPtr (RMutex *mutex)
 
RMutexGetMutex (void) const
 
 ~RSmartMutexPtr (void)
 

Private Attributes

RMutexMutex
 

Detailed Description

Smart Mutex Pointer.

The RSmartMutexPtr provides a smart pointer for a given mutex. It has the same role than the classic auto_ptr template of the standard C++ template library. In fact, when a mutex is locked in a function, it must be unlock at all closing point.

Take the following example:

RMutex mTest;
int Func(void)
{
mTest.Lock();
a=a+5;
if(a<25)
{
mTest.UnLock();
return(-1);
}
if(a<50)
{
mTest.UnLock();
return(1);
}
mTest.UnLock();
return(0);
}

Using the RSmartMutexPtr class, the code is less complex:

RMutex mTest;
int Func(void)
{
RSmartMutexPtr m(&mTest);
a=a+5;
if(a<25)
return(-1);
if(a<50)
return(1);
return(0);
}

Constructor & Destructor Documentation

RSmartMutexPtr ( RMutex mutex)

Construct the smart pointer, i.e. lock the mutex managed.

Parameters
mutexPointer to the mutex.
~RSmartMutexPtr ( void  )

Destruct the smart pointer, i.e. ulock the mutex managed.

Member Function Documentation

RMutex* GetMutex ( void  ) const

Get the mutex managed.

Field Documentation

RMutex* Mutex
private

Pointer to the mutex.