SourcePro® API Reference Guide

Product Documentation:
   SourcePro
Documentation Home
List of all members | Public Member Functions | Private Member Functions
RWTReadLockGuard< Resource > Class Template Reference

A guard class that acquires read access to its resource upon creation and releases it upon destruction. More...

#include <rw/sync/RWTReadLockGuard.h>

Inheritance diagram for RWTReadLockGuard< Resource >:
RWTReadLockGuardBase< Resource > RWTReadGuardBase< Resource >

Public Member Functions

 RWTReadLockGuard (Resource &resource)
 
 ~RWTReadLockGuard ()
 
- Public Member Functions inherited from RWTReadLockGuardBase< Resource >
 ~RWTReadLockGuardBase ()
 
- Public Member Functions inherited from RWTReadGuardBase< Resource >
 ~RWTReadGuardBase ()
 
void acquire ()
 
bool isAcquired () const
 
void release ()
 

Private Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from RWTReadLockGuardBase< Resource >
 RWTReadLockGuardBase (Resource &resource)
 
 RWTReadLockGuardBase (Resource &resource, bool acquired)
 
- Protected Member Functions inherited from RWTReadGuardBase< Resource >
 RWTReadGuardBase (Resource &resource)
 
 RWTReadGuardBase (Resource &resource, bool acquired)
 
Resource & resource () const
 

Detailed Description

template<class Resource>
class RWTReadLockGuard< Resource >

RWTReadLockGuard is a guard class that acquires read access on 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 read access on a mutex upon creation and release it when destructed. The class used as the template parameter Resource must be one that provides acquireRead() and release() methods, such as the synchronization classes provided in this module.

Example
#include <rw/sync/RWReadersWriterLock.h>
#include <rw/sync/RWTReadLockGuard.h>
// ...
void foo()
{
// acquire read access:
// ... critical section
// lock will be released in RWTReadLockGuard destructor
// before leaving scope, especially important if an exception
// might be thrown!
}
See also
RWTTryReadLockGuard, RWTReadUnlockGuard

Constructor & Destructor Documentation

template<class Resource >
RWTReadLockGuard< Resource >::~RWTReadLockGuard ( )
inline

Destructor.

template<class Resource >
RWTReadLockGuard< Resource >::RWTReadLockGuard ( Resource &  resource)
inline

Constructs an instance with the given resource and acquires read access on that resource. The resource is released in the destructor of the base class.

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

Copy constructor prohibited.

Member Function Documentation

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

Assignment prohibited.

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