#include <cel_lockable.h>
Public Member Functions | |
| Locker () | |
| Locker (const Lockable &inLockable) | |
| Locker (const Locker &inLocker) | |
| ~Locker () | |
| Locker & | operator= (const Lockable &inLockable) |
| Locker & | operator= (const Locker &inLocker) |
| void | lock (const Lockable &inLockable) |
| void | unlock () |
| void | swap (Locker &inLocker) |
void someOperation(Mutex& mutex) { // Locking the mutex; Locker is initialized as an auto object. Locker lock(mutex); // do something .... if(err) { // At the time the exception is thrown, the instance of // the Locker class is automatically deleted and the mutex // is released. celThrow(errOperationFailed); } }
The code which does same operation but in the old syntax:
void someOperation(Mutex& mutex) { mutex->lock(); // lock the mutex try { // do something; it may throw some exception... .... } catch(...) { mutex->unlock(); throw; // re-throw } // place unlock here to deal with both of error and non-error // cases. mutex->unlock(); if(err) celThrow(errOperationFailed); }
Definition at line 102 of file cel_lockable.h.
| Celartem::Locker::Locker | ( | ) | [inline] |
Initializes the instance without any lockable instances.
Definition at line 108 of file cel_lockable.h.
| Celartem::Locker::Locker | ( | const Lockable & | inLockable | ) | [inline] |
This constructor it to lock the specified lockable instance.
| inLockable | An instance to lock. |
Definition at line 117 of file cel_lockable.h.
| Celartem::Locker::Locker | ( | const Locker & | inLocker | ) | [inline] |
This constructor duplicates the lock; it is dengerous when you are deal with non-recursive Mutex.
| inLocker | An instance of Locker. |
Definition at line 128 of file cel_lockable.h.
| Celartem::Locker::~Locker | ( | ) | [inline] |
Unlocks the lockable.
Definition at line 136 of file cel_lockable.h.
This method sets the lockable instance to lock.
| inLockable | An instance to lock. You can also pass NULL to release the currently locked Lockable instance. |
*this ). Definition at line 149 of file cel_lockable.h.
This method duplicates the lock; it is dengerous when you are deal with non-recursive Mutex.
| inLocker | An instance of Locker. |
*this ). Definition at line 163 of file cel_lockable.h.
| void Celartem::Locker::lock | ( | const Lockable & | inLockable | ) | [inline] |
This method locks the specified Lockable instance.
| inLockable | An instance to lock. You can also pass NULL to release the currently locked Lockable instance. |
Definition at line 189 of file cel_lockable.h.
| void Celartem::Locker::unlock | ( | ) | [inline] |
This method unlocks the currently locked instance.
Definition at line 197 of file cel_lockable.h.
Referenced by ~Locker().
| void Celartem::Locker::swap | ( | Locker & | inLocker | ) | [inline] |
This method swaps the locked instances of the two Locker instances.
| inLocker | The locker to exchange the locked instance with. |
Definition at line 212 of file cel_lockable.h.