Nuke binary plugins 15.1.4
 
Loading...
Searching...
No Matches
DD::Image::Guard Class Reference
Inheritance diagram for DD::Image::Guard:
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;
}
Definition: Thread.h:501
Definition: Thread.h:56

Constructor & Destructor Documentation

◆ Guard() [1/2]

DD::Image::Guard::Guard ( Lock m)
inline

The constructor calls m.lock()

◆ Guard() [2/2]

DD::Image::Guard::Guard ( Lock m)
inline

You can also construct it with a pointer to a lock.

◆ ~Guard()

DD::Image::Guard::~Guard ( )
inline

Calls unlock() on the lock passed to the constructor.



©2024 The Foundry Visionmongers, Ltd. All Rights Reserved.
www.foundry.com