SourcePro® API Reference Guide

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

Base class for guard classes. More...

#include <rw/sync/RWTGuardBase.h>

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

Public Member Functions

 ~RWTGuardBase ()
 
void acquire ()
 
bool isAcquired () const
 
void release ()
 

Protected Member Functions

 RWTGuardBase (Resource &resource)
 
 RWTGuardBase (Resource &resource, bool acquired)
 
Resource & resource () const
 

Private Member Functions

 RWTGuardBase (const RWTGuardBase< Resource > &second)
 
RWTGuardBaseoperator= (const RWTGuardBase< Resource > &second)
 

Detailed Description

template<class Resource>
class RWTGuardBase< Resource >

RWTGuardBase is intended as a base class for guard classes. 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 when created 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 the synchronization classes in this module.

See also
RWTLockGuardBase, RWTLockGuard, RWTTryLockGuard, RWTUnlockGuard

Constructor & Destructor Documentation

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

Destructor.

template<class Resource >
RWTGuardBase< Resource >::RWTGuardBase ( Resource &  resource)
inlineprotected
Deprecated:
As of SourcePro 13, use RWTGuardBase(Resource&, bool) instead.

Constructs an instance with the given resource.

template<class Resource >
RWTGuardBase< Resource >::RWTGuardBase ( Resource &  resource,
bool  acquired 
)
inlineprotected

Constructs an instance with the given resource. If acquired is true, the resource is assumed to be owned by the caller.

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

Dummy copy constructor, required by derived class copy constructors. The copy constructor does not attempt to copy the resource.

Member Function Documentation

template<class Resource >
void RWTGuardBase< Resource >::acquire ( void  )
inline

Acquires the resource held by the guard unless it has already been acquired. Use this function instead of directly manipulating the resource so that the guard will automatically release or acquire it (as appropriate).

template<class Resource >
bool RWTGuardBase< Resource >::isAcquired ( ) const
inline

Returns true if the resource is currently acquired, otherwise false.

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

Assignment prohibited.

template<class Resource >
void RWTGuardBase< Resource >::release ( void  )
inline

Releases the resource held by the guard if it has been acquired. Use this function instead of directly manipulating the resource so that the guard will automatically release or acquire it (as appropriate).

template<class Resource >
Resource & RWTGuardBase< Resource >::resource ( ) const
inlineprotected

Returns a reference to the resource currently held by the guard.

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