OSB_LIB::RwGuard Class Reference

Collaboration diagram for OSB_LIB::RwGuard:

Collaboration graph
[legend]
List of all members.

Detailed Description

Guard a RwMutex.

A guard is an object that releases a lock, that was aquired by the creator of the guard, when it goes out of scope. The lock ownership is transferred when a guard is copied. On assignment a held lock is unlocked and the ownership is transferred.

This class provides a guard for a RwMutex.

Definition at line 330 of file mutex.h.

Public Types

Public Member Functions

Non-const construction.
The following constructor and conversion operator are used to achive the non-const copy constructor RwGuard(RwGuard) by compiler generated conversions.

Private Attributes

Classes


Member Typedef Documentation

typedef int(RwMutex::*) OSB_LIB::RwGuard::Unlock()

Call a member function of RwMutex to unlock.

Definition at line 345 of file mutex.h.


Constructor & Destructor Documentation

OSB_LIB::RwGuard::RwGuard ( bool  locked = true,
RwMutex pMutex = 0,
Unlock  unlock = 0 
)

Create a RwGuard.

If used as default constructor, i.e. without providing a mutex, the guard should behave as if it was locked. This makes it possible to verify the correct usage of guard with respect to copying and assignment.

Parameters:
locked Flag if the caller of the function owns the appropriate lock when the constructor is called (true is yes, false if no).
pMutex RwMutex to unlock.
unlock Unlock function to call: either RwMutex::readUnlock or RwMutex::writeUnlock.

OSB_LIB::RwGuard::~RwGuard (  ) 

The destructor calls the unlock function if the destructed object owns the lock.

OSB_LIB::RwGuard::RwGuard ( RwGuard rhs  ) 

Non-const copy constructor, takes the lock ownership from `rhs'.

OSB_LIB::RwGuard::RwGuard ( RwGuardRef  r  ) 

Construct from a RwGuardRef, takes the lock ownership from `r'.


Member Function Documentation

bool OSB_LIB::RwGuard::locked (  )  const [inline]

Lock owned by the current object?

Definition at line 415 of file mutex.h.

References locked_.

Referenced by OSB_LIB::ResourceList< R >::clear(), OSB_LIB::ResourceList< R >::erase(), OSB_LIB::ResourceList< R >::insert(), and OSB_LIB::ResourceList< R >::replace().

OSB_LIB::RwGuard::operator RwGuardRef (  ) 

Convert to a RwGuardRef.

RwGuard& OSB_LIB::RwGuard::operator= ( RwGuard  rhs  ) 

Non-const assignment operator.

The assignment operator first unlocks a held lock and then transfers the lock ownership.

bool OSB_LIB::RwGuard::release (  ) 

Release lock ownership without unlocking the mutex.

Remarks:
After the function is called, `locked_' is always false and the guard will no more dereference the mutex pointer to call the unlock function.
Returns:
True if the object owned the lock before the member function was called, else false.

void OSB_LIB::RwGuard::unlock (  ) 

Call the unlock function.

If the object owns the lock the mutex's unlock function is called. The function always sets `locked_' to false.


Member Data Documentation

bool OSB_LIB::RwGuard::locked_ [private]

Owner of lock?

Definition at line 429 of file mutex.h.

Referenced by locked().

RwMutex* OSB_LIB::RwGuard::pMutex_ [private]

Mutex to unlock.

Definition at line 430 of file mutex.h.

Unlock OSB_LIB::RwGuard::unlock_ [private]

Unlock function to call.

Definition at line 431 of file mutex.h.


The documentation for this class was generated from the following file:
Generated on Sat Sep 2 14:11:35 2006 for OSB Library by  doxygen 1.4.7