#include <coherence/lang/SynchronizedMemberReadBlock.hpp>
Inherits FinalizableBlock.
Inherited by SynchronizedMemberWriteBlock.
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.
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... |
SynchronizedMemberReadBlock | ( | const Object & | o, | |
SynchronizedMemberReadBlock * | pDelegate = NULL | |||
) | [inline] |
Construct a synchronized SynchronizedMemberReadBlock, acquiring the Object's member read lock.
o | the Object to lock | |
pDelegate | SynchronizedMemberReadBlock to delegate to, or NULL for no delegate |
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.
operator bool | ( | ) | const [inline] |
Validate that the lock is held.
The boolean conversion is utilized by the COH_SYNCHRONIZED_MEMBER_READ macro.
IllegalStateException | if the lock is not held. |
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.
member | the member whose value to get |
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.
member | the member whose value to get |
void initialize | ( | const Object & | o, | |
SynchronizedMemberReadBlock * | pDelegate = NULL | |||
) | [inline, protected] |
Initialize a synchronized SynchronizedMemberReadBlock.
o | the Object associated with the block | |
pDelegate | SynchronizedMemberReadBlock to delegate to, or NULL for no delegate |
IllegalArgumentException | if pSyncDelegate is non-NULL and references a different Object. |