Oracle Coherence for C++ API
Release 3.6.1.0

E18813-01

SynchronizedMemberReadBlock Class Reference

#include <coherence/lang/SynchronizedMemberReadBlock.hpp>

Inherits FinalizableBlock.

Inherited by SynchronizedMemberWriteBlock.

List of all members.


Detailed Description

The SynchronizedMemberReadBlock class allows for easy creation of synchronized code blocks based on an Object's member level read/write lock.

The SynchronizedMemberBlock object will ensure that the locks are acquired and released as part of starting and ending the code block.

Member read/write locks are not a general purpose feature, and should not be used to protect blocking calls. They are intended to protect reads and writes to data member primitives, and other short non-blocking code blocks.

Example usage:

// outside of sync block { SynchronizedMemberReadBlock syncRead(self()); // read lock acquired // critical section goes here // ... } // read lock released // outside of sync block

A more friendly form is to use the COH_SYNCHRONIZED_MEMBER_READ macros. Example usage:

// outside of sync block COH_SYNCHRONIZED_MEMBER_READ // read lock acquired { // critical section goes here // ... // ... } // read lock released // outside of sync block

The SynchronizedMemberReadBlock class relies on its creator to ensure that the associated Object outlives the scope of the block. The helper macro ensures this by only allowing you to create a block for the encompassing Object, i.e. "this". If the blocks are manually created then the caller must ensure that the associated Object outlives the block. ' Note: This class derives from FinalizableBlock, allowing custom finalizers to be registered. The finalizers will execute after the lock has been released.

Author:
mf 2008.01.29

Public Member Functions

  SynchronizedMemberReadBlock (const Object &o, SynchronizedMemberReadBlock *pDelegate=NULL)
  Construct a synchronized SynchronizedMemberReadBlock, acquiring the Object's member read lock.
  ~SynchronizedMemberReadBlock ()
  Destroy a SynchronizedMemberReadBlock.
  operator bool () const
  Validate that the lock is held.
template<class M>
M::ConstGetType  getMember (const M &member)
  Get the value of the specified member, without obtaining additional synchronization.
template<class M>
M::GetType  getMember (M &member)
  Get the value of the specified member, without obtaining additional synchronization.

Protected Member Functions

  SynchronizedMemberReadBlock ()
  Construct an uninitialized SynchronizedMemberReadBlock.
void  initialize (const Object &o, SynchronizedMemberReadBlock *pDelegate=NULL)
  Initialize a synchronized SynchronizedMemberReadBlock.

Protected Attributes

const Object m_cpObject
  The Object on which the lock is applied.

Classes

class   Guard
  Simple read lock structure for use in inlining. More...

Constructor & Destructor Documentation

SynchronizedMemberReadBlock ( const Object o,
SynchronizedMemberReadBlock pDelegate = NULL  
) [inline]

Construct a synchronized SynchronizedMemberReadBlock, acquiring the Object's member read lock.

Parameters:
o  the Object to lock
pDelegate  SynchronizedMemberReadBlock to delegate to, or NULL for no delegate
Exceptions:
IllegalArgumentException  if pSyncDelegate is non-NULL and references a different Object.

~SynchronizedMemberReadBlock (  )  [inline]

Destroy a SynchronizedMemberReadBlock.

This is a no-op for a delegating block, otherwise the read lock is released.


Member Function Documentation

operator bool (  )  const [inline]

Validate that the lock is held.

The boolean conversion is utilized by the COH_SYNCHRONIZED_MEMBER_READ macro.

Exceptions:
IllegalStateException  if the lock is not held.
Returns:
false always

Reimplemented from FinalizableBlock.

M::ConstGetType getMember ( const M &  member  )  [inline]

Get the value of the specified member, without obtaining additional synchronization.

This helper function is only supported on "members" which supply a custom two-parameter "get" method utilizing the SynchronizedMemberBlock::SynchronizedMemberReadBlock facility.

Parameters:
member  the member whose value to get
Returns:
the member's value

M::GetType getMember ( M &  member  )  [inline]

Get the value of the specified member, without obtaining additional synchronization.

This helper function is only supported on "members" which supply a custom parameterized "get" method utilizing the SynchronizedMemberBlock::SynchronizedMemberReadBlock facility.

Parameters:
member  the member whose value to get
Returns:
the member's value

void initialize ( const Object o,
SynchronizedMemberReadBlock pDelegate = NULL  
) [inline, protected]

Initialize a synchronized SynchronizedMemberReadBlock.

Parameters:
o  the Object associated with the block
pDelegate  SynchronizedMemberReadBlock to delegate to, or NULL for no delegate
Exceptions:
IllegalArgumentException  if pSyncDelegate is non-NULL and references a different Object.

The documentation for this class was generated from the following file:
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.