#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) |
This class is to lock Lockable instances.
This class is introduced to make the code exception-safe. Since the scheme of calling lock method in the first of a function and unlock on return is usually not easy to be exception-safe and the programmers may happen to introduce dirty try-catch hack to recover from it. The Locker object is to get rid of such dirty temporary hacks; all you have to do is to initialize the instance of Locker class directly in the local scope. (This class is intended to be initialized as auto variable or class member variable.) The following code shows how to use Locker class.
The code which does same operation but in the old syntax:
|
inline |
Initializes the instance without any lockable instances.
|
inline |
This constructor it to lock the specified lockable instance.
inLockable | An instance to lock. |
|
inline |
This constructor duplicates the lock; it is dengerous when you are deal with non-recursive Mutex.
inLocker | An instance of Locker. |
|
inline |
Unlocks the lockable.
|
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. |
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
). This method duplicates the lock; it is dengerous when you are deal with non-recursive Mutex.
inLocker | An instance of Locker. |
*this
).
|
inline |
This method swaps the locked instances of the two Locker instances.
inLocker | The locker to exchange the locked instance with. |
|
inline |
This method unlocks the currently locked instance.
Referenced by ~Locker().