SourcePro 11.1 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
A guard that cquires its resource upon creation and releases it upon destruction. More...
#include <rw/sync/RWTLockGuard.h>
Public Member Functions | |
RWTLockGuard (Resource &resource) | |
~RWTLockGuard () | |
Private Member Functions | |
RWTLockGuard (const RWTLockGuard< Resource > &second) | |
RWTLockGuard< Resource > & | operator= (const RWTLockGuard< Resource > &second) |
RWTLockGuard<Resource> is a guard class that acquires its resource upon creation and releases it upon destruction. Guard objects work in conjunction with block statements in such a way as to establish an appropriate state upon creation, maintain that state for the duration of the block, and restore the original state upon destruction. For example, a guard may acquire a mutex upon creation and release it when destructed. The class used as the actual template parameter for Resource
must be one that provides acquire
and release
methods, such as provided by the Threads Module synchronization classes.
#include <rw/sync/RWMutexLock.h> #include <rw/sync/RWTLockGuard.h> // ... RWMutexLock mutex; void foo() { RWTLockGuard<RWMutexLock> lock(mutex); // acquires mutex // ... critical section // Mutex will be released in RWTLockGuard destructor // before leaving scope, especially important if an exception // might be thrown! }
RWTLockGuard< Resource >::RWTLockGuard | ( | Resource & | resource | ) | [inline] |
Constructs an instance with the given resource and acquires that resource. (The resource will be released in the destructor of the base class.)
RWTLockGuard< Resource >::~RWTLockGuard | ( | ) | [inline] |
Destructor.
RWTLockGuard< Resource >::RWTLockGuard | ( | const RWTLockGuard< Resource > & | second | ) | [private] |
Copy construction prohibited.
RWTLockGuard<Resource>& RWTLockGuard< Resource >::operator= | ( | const RWTLockGuard< Resource > & | second | ) | [private] |
Assignment prohibited.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.