Smart Write Lock Pointer. More...
#include <rrwlock.h>
Collaboration diagram for RSmartWLockPtr:
Public Member Functions | |
RSmartWLockPtr (RRWLock *lock) | |
RRWLock * | GetLock (void) const |
~RSmartWLockPtr (void) | |
Private Attributes | |
RRWLock * | Lock |
Detailed Description
Smart Write Lock Pointer.
The RSmartWLockPtr provides a smart pointer for a lock in write mode. It has the same role than the classic auto_ptr template of the standard C++ template library. In fact, when a write lock is acquired in a function, it must be unlock at all closing point.
Take the following example:
RRWLock lTest;
int Func(void)
{
lTest.WriteLock();
a=a+5;
if(a<25)
{
lTest.WriteUnLock();
return(-1);
}
if(a<50)
{
lTest.WriteUnLock();
return(1);
}
lTest.WriteUnLock();
return(0);
}
Using the RSmartWLockPtr class, the code is less complex:
RRWLock lTest;
int Func(void)
{
RSmartWLockPtr m(&lTest);
a=a+5;
if(a<25)
return(-1);
if(a<50)
return(1);
return(0);
}
Constructor & Destructor Documentation
RSmartWLockPtr | ( | RRWLock * | lock | ) |
Construct the smart pointer, i.e. lock in write mode.
- Parameters
-
lock Pointer to the read/write lock.
~RSmartWLockPtr | ( | void | ) |
Destruct the smart pointer, i.e. release the write lock.
Member Function Documentation
RRWLock* GetLock | ( | void | ) | const |
Get the read/write lock managed.
Field Documentation
|
private |
Pointer to the Read/Write lock.