Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Atomic_Op_Ex Class Template Reference

Transparently parameterizes synchronization into basic arithmetic operations. More...

#include <Atomic_Op_T.h>

Collaboration diagram for ACE_Atomic_Op_Ex:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Atomic_Op_Ex (ACE_LOCK &mtx)
 Initialize <value_> to 0. More...

 ACE_Atomic_Op_Ex (ACE_LOCK &mtx, const TYPE &c)
 Initialize <value_> to c. More...

TYPE operator++ (void)
 Atomically pre-increment <value_>. More...

TYPE operator++ (int)
 Atomically post-increment <value_>. More...

TYPE operator+= (const TYPE &rhs)
 Atomically increment <value_> by rhs. More...

TYPE operator-- (void)
 Atomically pre-decrement <value_>. More...

TYPE operator-- (int)
 Atomically post-decrement <value_>. More...

TYPE operator-= (const TYPE &rhs)
 Atomically decrement <value_> by rhs. More...

int operator== (const TYPE &rhs) const
 Atomically compare <value_> with rhs. More...

int operator!= (const TYPE &rhs) const
 Atomically compare <value_> with rhs. More...

int operator>= (const TYPE &rhs) const
 Atomically check if <value_> greater than or equal to rhs. More...

int operator> (const TYPE &rhs) const
 Atomically check if <value_> greater than rhs. More...

int operator<= (const TYPE &rhs) const
 Atomically check if <value_> less than or equal to rhs. More...

int operator< (const TYPE &rhs) const
 Atomically check if <value_> less than rhs. More...

void operator= (const TYPE &rhs)
 Atomically assign rhs to <value_>. More...

void operator= (const ACE_Atomic_Op_Ex< ACE_LOCK, TYPE > &rhs)
 Atomically assign <rhs> to <value_>. More...

TYPE value (void) const
 Explicitly return <value_>. More...

void dump (void) const
 Dump the state of an object. More...

 ACE_Atomic_Op_Ex (const ACE_Atomic_Op_Ex< ACE_LOCK, TYPE > &)
 Manage copying... More...

ACE_LOCK & mutex (void)
TYPE & value_i (void)

Private Attributes

ACE_LOCK & mutex_
 Type of synchronization mechanism. More...

TYPE value_
 Current object decorated by the atomic op. More...


Detailed Description

template<class ACE_LOCK, class TYPE>
class ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >

Transparently parameterizes synchronization into basic arithmetic operations.

This class is described in an article in the July/August 1994 issue of the C++ Report magazine. It implements a templatized version of the Decorator pattern from the GoF book.

ACE_Atomic_Op_Ex objects must be constructed with a reference to an existing lock. A single lock can be shared between multiple ACE_Atomic_Op_Ex objects. If you do not require this ability consider using the ACE_Atomic_Op class instead, which may be able to take advantage of platform-specific optimisations to provide atomic operations without requiring a lock.

Definition at line 45 of file Atomic_Op_T.h.


Constructor & Destructor Documentation

template<class ACE_LOCK, class TYPE>
ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::ACE_Atomic_Op_Ex ACE_LOCK &    mtx
 

Initialize <value_> to 0.

Definition at line 40 of file Atomic_Op_T.cpp.

00041   : mutex_ (mtx),
00042     value_ (0)
00043 {
00044   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex");
00045 }

template<class ACE_LOCK, class TYPE>
ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::ACE_Atomic_Op_Ex ACE_LOCK &    mtx,
const TYPE &    c
 

Initialize <value_> to c.

Definition at line 49 of file Atomic_Op_T.cpp.

00050   : mutex_ (mtx),
00051     value_ (c)
00052 {
00053 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex");
00054 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::ACE_Atomic_Op_Ex const ACE_Atomic_Op_Ex< ACE_LOCK, TYPE > &   
 

Manage copying...

Definition at line 41 of file Atomic_Op_T.i.

00042   : mutex_ (rhs.mutex_)
00043 {
00044 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex");
00045   *this = rhs; // Invoke the assignment operator.
00046 }


Member Function Documentation

template<class ACE_LOCK, class TYPE>
void ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::dump void    const
 

Dump the state of an object.

Definition at line 30 of file Atomic_Op_T.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, LM_DEBUG, and mutex_.

00031 {
00032   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::dump");
00033   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00034   this->mutex_.dump ();
00035   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00036 }

template<class ACE_LOCK, class TYPE>
ACE_LOCK & ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::mutex void   
 

Returns a reference to the underlying <ACE_LOCK>. This makes it possible to acquire the lock explicitly, which can be useful in some cases if you instantiate the <ACE_Atomic_Op_Ex> with an <ACE_Recursive_Mutex> or <ACE_Process_Mutex>. NOTE: the right name would be lock_, but HP/C++ will choke on that!

Definition at line 23 of file Atomic_Op_T.cpp.

References mutex_.

00024 {
00025   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::mutex");
00026   return this->mutex_;
00027 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE int ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator!= const TYPE &    rhs const
 

Atomically compare <value_> with rhs.

Definition at line 73 of file Atomic_Op_T.i.

00074 {
00075 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator!=");
00076   return !(*this == rhs);
00077 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE TYPE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator++ int   
 

Atomically post-increment <value_>.

Definition at line 49 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00050 {
00051 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator++");
00052   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_);
00053   return this->value_++;
00054 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE TYPE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator++ void   
 

Atomically pre-increment <value_>.

Definition at line 9 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00010 {
00011 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator++");
00012   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_);
00013   return ++this->value_;
00014 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE TYPE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator+= const TYPE &    rhs
 

Atomically increment <value_> by rhs.

Definition at line 17 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00018 {
00019 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator+=");
00020   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_);
00021   return this->value_ += rhs;
00022 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE TYPE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator-- int   
 

Atomically post-decrement <value_>.

Definition at line 57 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00058 {
00059 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator--");
00060   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_);
00061   return this->value_--;
00062 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE TYPE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator-- void   
 

Atomically pre-decrement <value_>.

Definition at line 25 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00026 {
00027 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator--");
00028   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_);
00029   return --this->value_;
00030 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE TYPE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator-= const TYPE &    rhs
 

Atomically decrement <value_> by rhs.

Definition at line 33 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00034 {
00035 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator-=");
00036   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_);
00037   return this->value_ -= rhs;
00038 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE int ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator< const TYPE &    rhs const
 

Atomically check if <value_> less than rhs.

Definition at line 104 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00105 {
00106 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator<");
00107   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, 0);
00108   return this->value_ < rhs;
00109 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE int ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator<= const TYPE &    rhs const
 

Atomically check if <value_> less than or equal to rhs.

Definition at line 96 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00097 {
00098 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator<=");
00099   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, 0);
00100   return this->value_ <= rhs;
00101 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE void ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator= const ACE_Atomic_Op_Ex< ACE_LOCK, TYPE > &    rhs
 

Atomically assign <rhs> to <value_>.

Definition at line 112 of file Atomic_Op_T.i.

References ACE_GUARD, value, and value_.

00113 {
00114 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator=");
00115   if (&rhs == this)
00116     return; // Avoid deadlock...
00117   ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_);
00118   // This will call ACE_Atomic_Op_Ex::TYPE(), which will ensure the value
00119   // of <rhs> is acquired atomically.
00120 
00121   this->value_ = rhs.value ();
00122 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE void ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator= const TYPE &    rhs
 

Atomically assign rhs to <value_>.

Definition at line 143 of file Atomic_Op_T.i.

References ACE_GUARD, and value_.

00144 {
00145 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator=");
00146   ACE_GUARD (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_);
00147   this->value_ = rhs;
00148 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE int ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator== const TYPE &    rhs const
 

Atomically compare <value_> with rhs.

Definition at line 65 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00066 {
00067 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator==");
00068   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, 0);
00069   return this->value_ == rhs;
00070 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE int ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator> const TYPE &    rhs const
 

Atomically check if <value_> greater than rhs.

Definition at line 88 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00089 {
00090 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator>");
00091   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, 0);
00092   return this->value_ > rhs;
00093 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE int ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator>= const TYPE &    rhs const
 

Atomically check if <value_> greater than or equal to rhs.

Definition at line 80 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

00081 {
00082 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator>=");
00083   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, 0);
00084   return this->value_ >= rhs;
00085 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE TYPE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value void    const
 

Explicitly return <value_>.

Definition at line 125 of file Atomic_Op_T.i.

References ACE_GUARD_RETURN, and value_.

Referenced by operator=.

00126 {
00127 // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::value");
00128   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, this->value_);
00129   return this->value_;
00130 }

template<class ACE_LOCK, class TYPE>
ACE_INLINE TYPE & ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value_i void   
 

Explicitly return <value_> (by reference). This gives the user full, unrestricted access to the underlying value. This method will usually be used in conjunction with explicit access to the lock. Use with care ;-)

Definition at line 133 of file Atomic_Op_T.i.

References value_.

00134 {
00135   // Explicitly return <value_> (by reference).  This gives the user
00136   // full, unrestricted access to the underlying value.  This method
00137   // will usually be used in conjunction with explicit access to the
00138   // lock.  Use with care ;-)
00139   return this->value_;
00140 }


Member Data Documentation

template<class ACE_LOCK, class TYPE>
ACE_LOCK& ACE_Atomic_Op_Ex::mutex_ [private]
 

Type of synchronization mechanism.

Definition at line 131 of file Atomic_Op_T.h.

Referenced by dump, and mutex.

template<class ACE_LOCK, class TYPE>
TYPE ACE_Atomic_Op_Ex::value_ [private]
 

Current object decorated by the atomic op.

Definition at line 134 of file Atomic_Op_T.h.

Referenced by operator++, operator+=, operator--, operator-=, operator<, operator<=, operator=, operator==, operator>, operator>=, value, and value_i.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:45:57 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002