SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Private Member Functions
RWTReadUnlockGuard< Resource > Class Template Reference

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

#include <rw/sync/RWTReadUnlockGuard.h>

Inheritance diagram for RWTReadUnlockGuard< Resource >:
RWTReadGuardBase< Resource >

Public Member Functions

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

Private Member Functions

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

Additional Inherited Members

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

Detailed Description

template<class Resource>
class RWTReadUnlockGuard< Resource >

RWTReadUnlockGuard is a guard class that releases its resource upon creation and acquires read access to its resource upon destruction. Guard objects work in conjunction with block statements. The guard objects 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 release read access on a mutex upon creation and reacquire read access on that mutex 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/RWTReadUnlockGuard.h>
// ...
void foo()
{
rwlock.acquireRead();
// ... critical code
// temporarily release readers-writer lock
// for duration of block:
{
// constructor releases lock:
// ... anti-critical section
// lock will be reacquired for reading in
// RWTReadUnlockGuard destructor.
}
// ... more critical code
rwlock.release();
}
See also
RWTReadLockGuard, RWTTryReadLockGuard

Constructor & Destructor Documentation

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

Releases the resource.

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

Reacquires read access on the resource.

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

Copy construction prohibited.

Member Function Documentation

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

Assignment prohibited.

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