Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Phx::ReadLockedAccessor< T > Class Template Reference

A ReadLockedAccessor offers access to a piece of data while a read-lock protecting the data is held. More...

#include <PhxAccessors.h>

Inheritance diagram for Phx::ReadLockedAccessor< T >:

Phx::LockedPtrInterface< ReadLockedAccessor< T > > List of all members.

Public Member Functions

 ReadLockedAccessor (const T &data, ReadWriteLock *lock)
 Constructs a ReadLockedAccessor that offers access to its data while a given lock is held.
 ReadLockedAccessor (const T &data, ReadLockHolder *lockHolder)
 Constructs a locked accessor that offers read only access to its data while holding the lock already acquired via a ReadLockHolder.
T & data ()
 Returns the protected data to the client.

Detailed Description

template<class T>
class Phx::ReadLockedAccessor< T >

A ReadLockedAccessor offers access to a piece of data while a read-lock protecting the data is held.

A ReadLockedAccessor is an object that contains a ReadLockHolder and a copy of some data protected by that lock. For as long as this object is in existance, the data may be safely accessed under the protection provided by the lock. When this object is destructed, the lock holder is destroyed and the lock released.

The client can access the data via the data() method.

The template parameter T is the data type that is held by this object. The lock is interpreted as protecting the contents of the T object that is held. It does NOT protect the reference to the T itself. That is, the lock belongs to the T, and not to the object that contains T.

Remarks:
Copy construction and assignment are disallowed. You should refer to a LockedAccessor as a smart pointer (Ptr).

The template parameter T must be a copy-constructable type.

See also:
LockedAccessor

WriteLockedAccessor


Constructor & Destructor Documentation

template<class T>
Phx::ReadLockedAccessor< T >::ReadLockedAccessor const T &  data,
ReadWriteLock lock
[inline]
 

Constructs a ReadLockedAccessor that offers access to its data while a given lock is held.

Parameters:
data The value to set for the data field when this object is initialized. If the lock must be taken before the data is stored (e.g., if the lock must protect access to the data object itself, not just its contents) then you should acquire the lock first yourself (with a ReadLockHolder object) and then hand-off that lock to this object using ReadLockedAccessor(T, ReadLockHolder*).
lock A raw pointer to the ReadWriteLock that protects the data. This lock will be held for as long as this object is in use and will be released upon its destruction.
Warning:
Creating multiple ReadLockedAccessor objects will acquire the read lock multiple times.

template<class T>
Phx::ReadLockedAccessor< T >::ReadLockedAccessor const T &  data,
ReadLockHolder lockHolder
[inline]
 

Constructs a locked accessor that offers read only access to its data while holding the lock already acquired via a ReadLockHolder.

Parameters:
data The value to set for the data field when this object is initialized.
lockHolder The ReadLockHolder object that already controls the lock protecting this data. That ReadLockHolder will pass the lock to this ReadLockedAccessor which will hold it until releasing it on destruction. On return, 'lockHolder' no longer is in control of the lock and will do nothing on its destruction.


Member Function Documentation

template<class T>
T& Phx::ReadLockedAccessor< T >::data  )  [inline]
 

Returns the protected data to the client.

Note that this returns a non-const reference and thus does not enforce the read-only nature of read access. The primary function of this object is to hold the read lock and it will not impose read only access on the data on its own. To get this behavior, simply change the template parameter to "const T" instead of "T". For instance, to only give const access to the client, declare your accessor as ReadLockedAccessor<const myobject=""> rather than ReadLockedAccessor<MyObject>.

Returns:
A reference to the data contained by this locked accessor.
See also:
LockedAccessor::data()


The documentation for this class was generated from the following file:
Generated on Wed Dec 21 22:05:39 2005 for Phoenix OSFS by  doxygen 1.4.2