#include <coherence/lang/SynchronizedMemberWriteBlock.hpp>
Inherits SynchronizedMemberReadBlock.
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.
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... |
SynchronizedMemberWriteBlock | ( | const Object & | o, | |
SynchronizedMemberWriteBlock * | pDelegate = NULL | |||
) | [inline] |
Construct a synchronized SynchronizedMemberWriteBlock, acquiring the Object's member write lock.
o | the Object to lock | |
pDelegate | SynchronizedMemberWriteBlock to delegate to, or NULL for no delegate |
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.
void setMember | ( | M & | member, | |
V | 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.
member | the member to set | |
value | the value to set the member to |
M::GetType updateMember | ( | M & | member, | |
V | valueAssumed, | |||
V | 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.
member | the member to set | |
valueAssumed | the assumed current value of the member | |
valueNew | the value to set the member to |
M::GetType exchangeMember | ( | M & | member, | |
V | 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.
member | the member to set | |
valueNew | the value to set the member to |