Oracle Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.2)

E26041-01

SynchronizedMemberWriteBlock Class Reference

#include <coherence/lang/SynchronizedMemberWriteBlock.hpp>

Inherits SynchronizedMemberReadBlock.

List of all members.


Detailed Description

The SynchronizedMemberBlock 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 { SynchronizedMemberWriteBlock syncWrite(self()); // write lock acquired // critical section goes here // ... } // write lock released // outside of sync block

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

// outside of sync block COH_SYNCHRONIZED_MEMBER_WRITE // write lock acquired { // critical section goes here // ... // ... } // write lock released // outside of sync block

The SynchronizedMemberWriteBlock 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 indirectly 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

 SynchronizedMemberWriteBlock (const Object &o, SynchronizedMemberWriteBlock *pDelegate=NULL)
 Construct a synchronized SynchronizedMemberWriteBlock, acquiring the Object's member write lock.
 ~SynchronizedMemberWriteBlock ()
 Destroy a SynchronizedMemberWriteBlock.
template<class M, class V>
void setMember (M &member, V value)
 Set the specified member to the specified value, without obtaining additional synchronization.
template<class M, class V>
M::GetType updateMember (M &member, V valueAssumed, V valueNew)
 Set the specified member to the specified value so long as the current value is equal to the assumed value.
template<class M, class V>
M::GetType exchangeMember (M &member, V valueNew)
 Set the specified member to the specified value and return the previous value.

Classes

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

Constructor & Destructor Documentation

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

Construct a synchronized SynchronizedMemberWriteBlock, acquiring the Object's member write lock.

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

~SynchronizedMemberWriteBlock (  )  [inline]

Destroy a SynchronizedMemberWriteBlock.

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


Member Function Documentation

void setMember ( M &  member,
value 
) [inline]

Set the specified member to the specified value, without obtaining additional synchronization.

This helper function is only supported on "members" which supply a custom two-parameter "set" method utilizing the SynchronizedMemberWriteBlock facility.

Parameters:
member the member to set
value the value to set the member to

M::GetType updateMember ( M &  member,
valueAssumed,
valueNew 
) [inline]

Set the specified member to the specified value so long as the current value is equal to the assumed value.

This helper function is only supported on "members" which supply a custom parameterized "set" and "get" methods utilizing the SynchronizedMemberWriteBlock facility.

Parameters:
member the member to set
valueAssumed the assumed current value of the member
valueNew the value to set the member to
Returns:
the actual value prior to the update attempt

M::GetType exchangeMember ( M &  member,
valueNew 
) [inline]

Set the specified member to the specified value and return the previous value.

This helper function is only supported on "members" which supply a custom parameterized "set" and "get" methods utilizing the SynchronizedMemberWriteBlock facility.

Parameters:
member the member to set
valueNew the value to set the member to
Returns:
the prior value


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