SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWTLockGuard< Resource > Class Template Reference

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 >

Public Member Functions

 RWTLockGuard (Resource &resource)
 
 ~RWTLockGuard (void)
 
- Public Member Functions inherited from RWTLockGuardBase< Resource >
 ~RWTLockGuardBase (void)
 
- Public Member Functions inherited from RWTGuardBase< Resource >
 ~RWTGuardBase (void)
 
void acquire (void)
 
bool isAcquired (void) const
 
void release (void)
 

Private Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from RWTLockGuardBase< Resource >
 RWTLockGuardBase (Resource &resource)
 
 RWTLockGuardBase (Resource &resource, bool acquired)
 
- Protected Member Functions inherited from RWTGuardBase< Resource >
 RWTGuardBase (Resource &resource)
 
 RWTGuardBase (Resource &resource, bool acquired)
 
Resource & resource (void) const
 

Detailed Description

template<class Resource>
class RWTLockGuard< Resource >

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

Example
#include <rw/sync/RWMutexLock.h>
#include <rw/sync/RWTLockGuard.h>
// ...
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!
}
Implements a mutex, or mutual exclusion lock.
Definition RWMutexLock.h:231
A guard that acquires its resource upon creation and releases it upon destruction.
Definition RWTLockGuard.h:61
See also
RWTTryLockGuard, RWTUnlockGuard

Constructor & Destructor Documentation

◆ RWTLockGuard() [1/2]

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.

◆ ~RWTLockGuard()

template<class Resource >
RWTLockGuard< Resource >::~RWTLockGuard ( void )
inline

Destructor.

◆ RWTLockGuard() [2/2]

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

Copy construction prohibited.

Member Function Documentation

◆ operator=()

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

Assignment prohibited.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.