SourcePro® API Reference Guide

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

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

#include <rw/sync/RWTWriteLockGuard.h>

Inheritance diagram for RWTWriteLockGuard< Resource >:
RWTWriteLockGuardBase< Resource > RWTWriteGuardBase< Resource >

Public Member Functions

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

Private Member Functions

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

Additional Inherited Members

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

Detailed Description

template<class Resource>
class RWTWriteLockGuard< Resource >

RWTWriteLockGuard is a guard class that acquires write 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 write access on a mutex when created and release it when destructed.

The class used as the actual template parameter for Resource must provide acquireWrite() and release() methods, such as the synchronization classes in this module.

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

Constructor & Destructor Documentation

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

Destructor.

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

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

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

Copy constructor prohibited.

Member Function Documentation

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

Assignment prohibited.

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