DD::Image::Guard Class Reference

Inherits DD::Image::BaseLockGuard.

Public Member Functions

 Guard (Lock &m)
 
 Guard (Lock *m)
 
 ~Guard ()
 

Additional Inherited Members

- Protected Member Functions inherited from DD::Image::BaseLockGuard
 BaseLockGuard (Lock &m)
 
- Protected Attributes inherited from DD::Image::BaseLockGuard
Lock_lock
 

Detailed Description

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;
}

Constructor & Destructor Documentation

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.



©2021 The Foundry Visionmongers, Ltd. All Rights Reserved.
www.thefoundry.co.uk