rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWTLockGuard< Resource > Class Template Reference
[Synchronization]

A guard that acquires its resource upon creation and releases it upon destruction. More...

#include <rw/sync/RWTLockGuard.h>

Inheritance diagram for RWTLockGuard< Resource >:
RWTLockGuardBase< Resource > RWTGuardBase< Resource >

List of all members.

Public Member Functions

 RWTLockGuard (Resource &resource)
 ~RWTLockGuard ()

Private Member Functions

 RWTLockGuard (const RWTLockGuard< Resource > &second)
RWTLockGuard< Resource > & operator= (const RWTLockGuard< Resource > &second)

Detailed Description

template<class Resource>
class RWTLockGuard< Resource >

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 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.

Examples

 #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!
 }
See also:
RWTTryLockGuard RWTUnlockGuard

Constructor & Destructor Documentation

template<class Resource >
RWTLockGuard< Resource >::RWTLockGuard ( Resource &  resource  )  [inline]

Constructs a guard instance with the given resource and acquires that resource. The resource is released in the destructor of the base class.

template<class Resource >
RWTLockGuard< Resource >::~RWTLockGuard (  )  [inline]

Destructor.

template<class Resource>
RWTLockGuard< Resource >::RWTLockGuard ( const RWTLockGuard< Resource > &  second  )  [private]

Copy construction prohibited.


Member Function Documentation

template<class Resource>
RWTLockGuard<Resource>& RWTLockGuard< Resource >::operator= ( const RWTLockGuard< Resource > &  second  )  [private]

Assignment prohibited.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© 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.