|
OpenTop 1.3 | |||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||
#include "ot/base/AutoUnlock.h"
Releases a lock on initialization and re-acquires it on destruction.
AutoUnlock is based on the principle described by Bjarne Stroustrup as "resource acquisition is initialization". It is designed to unlock and re-lock synchronization objects in an exception-safe fashion by using local objects.In normal use, the constructor releases a lock. This lock is then free until the object is destroyed at the end of the current scope, when it is re-acquired
bool Foo::waitMethod()
{
AutoUnlock<Mutex> lock(m_mutex); // releases the lock on m_mutex
... // activity that does not require the lock
return true; // m_mutex is re-locked on exit
}
The lock can be re-acquired (and released) at any time. The general rule is that if the lock is still not held when an AutoUnlock object is destroyed, it will automatically re-acquire the lock.
AutoUnlock is a template class. It requires classes of type T to expose just two public methods: T::lock() and T::unlock().
| Constructor/Destructor Summary | |
AutoUnlock(T& lock)Constructor which takes a reference to lock and unlocks it. | |
~AutoUnlock()Destructor which re-acquires the lock if it is not being held. | |
| Method Summary | |
void |
lock()Re-acquires the lock if it is not being held; has no effect otherwise. |
void |
unlock()Releases the lock if it is being held; has no effect otherwise. |
| Constructor/Destructor Detail |
AutoUnlock(T& lock)
lock - ~AutoUnlock()
| Method Detail |
void lock()
void unlock()
|
OpenTop 1.3 | |||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||