ACE_Atomic_Op_Ex< ACE_LOCK, TYPE > Class Template Reference

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

#include <Atomic_Op_T.h>

Collaboration diagram for ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Type_Traits< TYPE
>::parameter_type 
arg_type

Public Member Functions

 ACE_Atomic_Op_Ex (ACE_LOCK &mtx)
 Initialize value_ to 0.
 ACE_Atomic_Op_Ex (ACE_LOCK &mtx, arg_type c)
 Initialize value_ to c.
TYPE operator++ (void)
 Atomically pre-increment value_.
TYPE operator++ (int)
 Atomically post-increment value_.
TYPE operator+= (arg_type rhs)
 Atomically increment value_ by rhs.
TYPE operator-- (void)
 Atomically pre-decrement value_.
TYPE operator-- (int)
 Atomically post-decrement value_.
TYPE operator-= (arg_type rhs)
 Atomically decrement value_ by rhs.
bool operator== (arg_type rhs) const
 Atomically compare value_ with rhs.
bool operator!= (arg_type rhs) const
 Atomically compare value_ with rhs.
bool operator>= (arg_type rhs) const
 Atomically check if value_ greater than or equal to rhs.
bool operator> (arg_type rhs) const
 Atomically check if value_ greater than rhs.
bool operator<= (arg_type rhs) const
 Atomically check if value_ less than or equal to rhs.
bool operator< (arg_type rhs) const
 Atomically check if value_ less than rhs.
ACE_Atomic_Op_Ex< ACE_LOCK,
TYPE > & 
operator= (arg_type rhs)
 Atomically assign rhs to value_.
ACE_Atomic_Op_Ex< ACE_LOCK,
TYPE > & 
operator= (ACE_Atomic_Op_Ex< ACE_LOCK, TYPE > const &rhs)
 Atomically assign <rhs> to value_.
TYPE value (void) const
 Explicitly return value_.
void dump (void) const
 Dump the state of an object.
 ACE_Atomic_Op_Ex (ACE_Atomic_Op_Ex< ACE_LOCK, TYPE > const &)
 Manage copying...
ACE_LOCK & mutex (void)
TYPE & value_i (void)

Private Attributes

ACE_LOCK & mutex_
 Type of synchronization mechanism.
TYPE value_
 Current object decorated by the atomic op.

Detailed Description

template<class ACE_LOCK, typename 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 151 of file Atomic_Op_T.h.


Member Typedef Documentation

template<class ACE_LOCK, typename TYPE>
typedef ACE_Type_Traits<TYPE>::parameter_type ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::arg_type

Definition at line 155 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 46 of file Atomic_Op_T.cpp.

00047   : mutex_ (mtx)
00048   , value_ (0)
00049 {
00050   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex");
00051 }

template<class ACE_LOCK, typename TYPE>
ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::ACE_Atomic_Op_Ex ( ACE_LOCK &  mtx,
arg_type  c 
)

Initialize value_ to c.

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

Manage copying...

Definition at line 55 of file Atomic_Op_T.inl.

00057   : mutex_ (rhs.mutex_)
00058   , value_ (rhs.value ())  // rhs.value() returns atomically
00059 {
00060   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex");
00061 }


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 35 of file Atomic_Op_T.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, LM_DEBUG, and ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::mutex_.

00036 {
00037 #if defined (ACE_HAS_DUMP)
00038   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::dump");
00039   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00040   this->mutex_.dump ();
00041   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00042 #endif /* ACE_HAS_DUMP */
00043 }

template<class ACE_LOCK, class TYPE>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL 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 27 of file Atomic_Op_T.cpp.

00028 {
00029   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::mutex");
00030   return this->mutex_;
00031 }

template<class ACE_LOCK, typename TYPE>
bool ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator!= ( arg_type  rhs  )  const

Atomically compare value_ with rhs.

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 65 of file Atomic_Op_T.inl.

References ACE_GUARD_RETURN, and ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value_.

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

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

Atomically pre-increment value_.

Definition at line 17 of file Atomic_Op_T.inl.

References ACE_GUARD_RETURN, and ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::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_;
00022 }

template<class ACE_LOCK, typename TYPE>
TYPE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator+= ( arg_type  rhs  ) 

Atomically increment value_ by rhs.

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 74 of file Atomic_Op_T.inl.

References ACE_GUARD_RETURN, and ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value_.

00075 {
00076   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator--");
00077   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_);
00078   return this->value_--;
00079 }

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 36 of file Atomic_Op_T.inl.

References ACE_GUARD_RETURN, and ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value_.

00037 {
00038   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator--");
00039   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_);
00040   return --this->value_;
00041 }

template<class ACE_LOCK, typename TYPE>
TYPE ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator-= ( arg_type  rhs  ) 

Atomically decrement value_ by rhs.

template<class ACE_LOCK, typename TYPE>
bool ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator< ( arg_type  rhs  )  const

Atomically check if value_ less than rhs.

template<class ACE_LOCK, typename TYPE>
bool ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator<= ( arg_type  rhs  )  const

Atomically check if value_ less than or equal to rhs.

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

Atomically assign <rhs> to value_.

Definition at line 142 of file Atomic_Op_T.inl.

References ACE_GUARD_RETURN, and ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value_.

00144 {
00145   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator=");
00146 
00147   ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> tmp (rhs);
00148 
00149   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, *this);
00150   std::swap (this->value_, tmp.value_);
00151 
00152   return *this;
00153 }

template<class ACE_LOCK, typename TYPE>
ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>& ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator= ( arg_type  rhs  ) 

Atomically assign rhs to value_.

template<class ACE_LOCK, typename TYPE>
bool ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator== ( arg_type  rhs  )  const

Atomically compare value_ with rhs.

template<class ACE_LOCK, typename TYPE>
bool ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator> ( arg_type  rhs  )  const

Atomically check if value_ greater than rhs.

template<class ACE_LOCK, typename TYPE>
bool ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator>= ( arg_type  rhs  )  const

Atomically check if value_ greater than or equal to rhs.

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 157 of file Atomic_Op_T.inl.

References ACE_GUARD_RETURN, and ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value_.

00158 {
00159   // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::value");
00160   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_);
00161   return this->value_;
00162 }

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 166 of file Atomic_Op_T.inl.

References ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value_.

00167 {
00168   // Explicitly return <value_> (by reference).  This gives the user
00169   // full, unrestricted access to the underlying value.  This method
00170   // will usually be used in conjunction with explicit access to the
00171   // lock.  Use with care ;-)
00172   return this->value_;
00173 }


Member Data Documentation

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

Type of synchronization mechanism.

Definition at line 241 of file Atomic_Op_T.h.

Referenced by ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::dump().

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

Current object decorated by the atomic op.

Definition at line 244 of file Atomic_Op_T.h.

Referenced by ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator++(), ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator--(), ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::operator=(), ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value(), and ACE_Atomic_Op_Ex< ACE_LOCK, TYPE >::value_i().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:34:55 2010 for ACE by  doxygen 1.4.7