OSB_LIB::ReadGuard< T * > Class Template Reference

Collaboration diagram for OSB_LIB::ReadGuard< T * >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename T>
class OSB_LIB::ReadGuard< T * >

Guard a locked pointer.

The template allows to guard a pointer. The guard behaviour is implemented by the member guard_.

Definition at line 448 of file mutex.h.

Public Member Functions

Copy construction from another pointer type.
The other pointer type S must be convertible to T.

Assignment from another pointer type.
The other pointer type S must be convertible to T.

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

Guard related functions:
The following members are wrappers to the RwGuard member of the class, see there for more details.

Public Attributes

Private Attributes

Friends

Classes


Constructor & Destructor Documentation

template<typename T>
OSB_LIB::ReadGuard< T * >::ReadGuard ( const T *  ptr = 0,
bool  locked = true,
RwMutex pMutex = 0 
) [inline]

Constructor for the issuer of the guard.

Parameters:
ptr Locked pointer.
locked Flag if the caller of the function owns the appropriate lock when the constructor is called (true is yes, false if no).
pMutex Mutex protecting the pointer.
The constructor initializes it's member RwGuard guard_ to use RwMutex::readUnlock() to release the lock.
The status_ flag is set to 0.

Remarks:
The parameter `locked' should be set to true by the issuer of the guard even if no locking at all is applied. Failing to do so will make it impossible for the receiver of the guard to access the protected pointer with get().

Definition at line 481 of file mutex.h.

template<typename T>
OSB_LIB::ReadGuard< T * >::ReadGuard ( int  stat  )  [inline, explicit]

Constructor to set the status.

Parameters:
stat Status of the guard.
The constructor initializes the member RwGuard guard_ as unlocked and without mutex.

This constructor is typically used by the issuer of the guard when the locking of the mutex failed:

          ReadGuard<T*> mkGuard(RwMutex& mutex)
          {
              // lock and check result
              if (0 != mutex.readLock()) {
                  return ReadGuard<T*>(lockFailed);
              }
              // other work to load the guard and return
              ...
          }

Definition at line 510 of file mutex.h.

template<typename T>
OSB_LIB::ReadGuard< T * >::ReadGuard ( ReadGuard< T * > &  rhs  )  [inline]

Non-const copy constructor.

It copies the guard from `rhs', thus transferring the ownership of the lock.

Definition at line 520 of file mutex.h.

template<typename T>
template<typename S>
OSB_LIB::ReadGuard< T * >::ReadGuard ( ReadGuard< S * >  rhs  )  [inline]

Definition at line 551 of file mutex.h.

template<typename T>
OSB_LIB::ReadGuard< T * >::ReadGuard ( ReadGuardRef  r  )  [inline]

Construct from ReadGuardRef, transfers lock ownership.

Definition at line 583 of file mutex.h.


Member Function Documentation

template<typename T>
const T* OSB_LIB::ReadGuard< T * >::get (  )  const [inline]

Access to the locked pointer.

Returns:
The locked pointer if the guard owns the lock, else 0 (NULL pointer). In the latter case, the caller may check status_ or locked() for the reason.

Definition at line 607 of file mutex.h.

template<typename T>
bool OSB_LIB::ReadGuard< T * >::locked (  )  const [inline]

Lock (still) owned by the guard?

Definition at line 619 of file mutex.h.

template<typename T>
OSB_LIB::ReadGuard< T * >::operator ReadGuardRef (  )  [inline]

Convert to a ReadGuardRef.

Definition at line 593 of file mutex.h.

template<typename T>
template<typename S>
ReadGuard& OSB_LIB::ReadGuard< T * >::operator= ( ReadGuard< S * >  rhs  )  [inline]

Definition at line 565 of file mutex.h.

template<typename T>
ReadGuard& OSB_LIB::ReadGuard< T * >::operator= ( ReadGuard< T * >  rhs  )  [inline]

Non-const assignment operator.

The operator uses memberwise assignment which also includes the guard: A held lock is unlocked and afterwards the ownership of lock is taken from `rhs'.

Definition at line 536 of file mutex.h.

template<typename T>
bool OSB_LIB::ReadGuard< T * >::release (  )  [inline]

Release the lock ownership without unlocking the guard.

Definition at line 625 of file mutex.h.

template<typename T>
void OSB_LIB::ReadGuard< T * >::unlock (  )  [inline]

Unlock the guard.

Definition at line 622 of file mutex.h.


Friends And Related Function Documentation

template<typename T>
friend class ReadGuard [friend]

Provide access to data members for compatible read guards.

Definition at line 451 of file mutex.h.


Member Data Documentation

template<typename T>
RwGuard OSB_LIB::ReadGuard< T * >::guard_ [private]

The actual guard.

Definition at line 644 of file mutex.h.

template<typename T>
const T* OSB_LIB::ReadGuard< T * >::ptr_ [private]

Locked pointer.

Definition at line 642 of file mutex.h.

template<typename T>
int OSB_LIB::ReadGuard< T * >::status_

A status flag.

The status flag can be used by the guard's issuer to provide some additional information on the locked resource, e.g., that the latter was deleted.

The interpretation of status_ must be agreed between the issuer and the receiver of the guard.

Definition at line 638 of file mutex.h.


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