Inherits DD::Image::BaseLockGuard.
Public Member Functions | |
Guard (Lock &m) | |
Guard (Lock *m) | |
~Guard () |
This wrapper class locks a lock in it's constructor, and unlocks it upon destruction. This is convienent if your function has many exit points or you are using exceptions, creating a Guard as a local variable will cause the compiler to insert the unlock call everywhere it is needed.
int proc() { static Lock thelock; Guard guard(thelock); access_protected_data(); if (dont_need_to_do_it()) return; access_protected_data(); do_stuff_that_may_throw_exceptions(); access_protected_data(); // lock is always unlocked even if this statement is not reached: return whatever; }
DD::Image::Guard::Guard | ( | Lock & | m | ) | [inline] |
The constructor calls m.lock()
DD::Image::Guard::Guard | ( | Lock * | m | ) | [inline] |
You can also construct it with a pointer to a lock.
DD::Image::Guard::~Guard | ( | ) | [inline] |
Calls unlock() on the lock passed to the constructor.