diff options
-rw-r--r-- | ACE/ChangeLog | 24 | ||||
-rw-r--r-- | ACE/ace/Atomic_Op_T.cpp | 29 | ||||
-rw-r--r-- | ACE/ace/Atomic_Op_T.h | 179 | ||||
-rw-r--r-- | ACE/ace/Atomic_Op_T.inl | 231 |
4 files changed, 332 insertions, 131 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index b18285b6d7d..2eeed6ad686 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,27 @@ +Fri Oct 5 18:45:48 UTC 2007 Ossama Othman <ossama_othman at symantec dot com> + + * ace/Atomic_Op_T.inl (ACE_Atomic_Op_Ex, operator=): + + Implement the assignment operator in terms of the copy + constructor, not the other way around. This (1) allows one less + lock to be held during copy construction, (2) allows for finer + grained locking during copy assignment, and (3) allows the + copy assignment operator to be implemented in a strongly + exception safe manner. + + * ace/Atomic_Op_T.cpp: + + Only include "ace/Log_Msg.h" if ACE_HAS_DUMP is defined. It + isn't needed otherwise. + + From Russell Mora + * ace/Atomic_Op_T.h: + * ace/Atomic_Op_T.inl: + * ace/Atomic_Op_T.cpp: + + Parameterized argument types using type traits. Avoids warnings + about references being taken of temporaries for built-in types. + Fri Oct 5 12:20:00 UTC 2007 Simon Massey <sma@prismtech.com> * ace/config-lynxos.h: diff --git a/ACE/ace/Atomic_Op_T.cpp b/ACE/ace/Atomic_Op_T.cpp index 2fffdd0b060..ad8f6b01059 100644 --- a/ACE/ace/Atomic_Op_T.cpp +++ b/ACE/ace/Atomic_Op_T.cpp @@ -2,7 +2,10 @@ #define ACE_ATOMIC_OP_T_CPP #include "ace/Atomic_Op_T.h" -#include "ace/Log_Msg.h" + +#ifdef ACE_HAS_DUMP +# include "ace/Log_Msg.h" +#endif /* ACE_HAS_DUMP */ #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once @@ -27,7 +30,8 @@ ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::mutex (void) return this->mutex_; } -template <class ACE_LOCK, class TYPE> void +template <class ACE_LOCK, class TYPE> +void ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::dump (void) const { #if defined (ACE_HAS_DUMP) @@ -39,21 +43,21 @@ ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::dump (void) const } template <class ACE_LOCK, class TYPE> -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex - (ACE_LOCK &mtx) - : mutex_ (mtx), - value_ (0) +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex (ACE_LOCK & mtx) + : mutex_ (mtx) + , value_ (0) { // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex"); } template <class ACE_LOCK, class TYPE> -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex - (ACE_LOCK &mtx, const TYPE &c) - : mutex_ (mtx), - value_ (c) +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex ( + ACE_LOCK & mtx, + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type c) + : mutex_ (mtx) + , value_ (c) { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex"); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex"); } // **************************************************************** @@ -66,7 +70,8 @@ ACE_Atomic_Op<ACE_LOCK, TYPE>::ACE_Atomic_Op (void) } template <class ACE_LOCK, class TYPE> -ACE_Atomic_Op<ACE_LOCK, TYPE>::ACE_Atomic_Op (const TYPE &c) +ACE_Atomic_Op<ACE_LOCK, TYPE>::ACE_Atomic_Op ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type c) : impl_ (own_mutex_, c) { // ACE_TRACE ("ACE_Atomic_Op<ACE_LOCK, TYPE>::ACE_Atomic_Op"); diff --git a/ACE/ace/Atomic_Op_T.h b/ACE/ace/Atomic_Op_T.h index ea5c5d201c4..6cb422850e6 100644 --- a/ACE/ace/Atomic_Op_T.h +++ b/ACE/ace/Atomic_Op_T.h @@ -22,6 +22,113 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL +template<typename TYPE> +struct ACE_Type_Traits +{ + typedef TYPE const & parameter_type; +}; + +template<> +struct ACE_Type_Traits<bool> +{ + typedef bool parameter_type; +}; + +template<> +struct ACE_Type_Traits<char> +{ + typedef char parameter_type; +}; + +template<> +struct ACE_Type_Traits<signed char> +{ + typedef signed char parameter_type; +}; + +template<> +struct ACE_Type_Traits<unsigned char> +{ + typedef unsigned char parameter_type; +}; + +template<> +struct ACE_Type_Traits<short> +{ + typedef short parameter_type; +}; + +template<> +struct ACE_Type_Traits<unsigned short> +{ + typedef unsigned short parameter_type; +}; + +template<> +struct ACE_Type_Traits<int> +{ + typedef int parameter_type; +}; + +template<> +struct ACE_Type_Traits<unsigned int> +{ + typedef unsigned int parameter_type; +}; + +template<> +struct ACE_Type_Traits<long> +{ + typedef long parameter_type; +}; + +template<> +struct ACE_Type_Traits<unsigned long> +{ + typedef unsigned long parameter_type; +}; + +#ifndef ACE_LACKS_LONGLONG_T +template<> +struct ACE_Type_Traits<long long> +{ + typedef long long parameter_type; +}; +#endif /* !ACE_LACKS_LONGLONG_T */ + +#if !defined (ACE_LACKS_LONGLONG_T) \ + && !defined (ACE_LACKS_UNSIGNEDLONGLONG_T) +template<> +struct ACE_Type_Traits<unsigned long long> +{ + typedef unsigned long long parameter_type; +}; +#endif /* !ACE_LACKS_LONGLONG_T && !ACE_LACKS_UNSIGNEDLONGLONG_T */ + +template<> +struct ACE_Type_Traits<float> +{ + typedef float parameter_type; +}; + +template<> +struct ACE_Type_Traits<double> +{ + typedef double parameter_type; +}; + +template<> +struct ACE_Type_Traits<long double> +{ + typedef long double parameter_type; +}; + +template<typename TYPE> +struct ACE_Type_Traits<TYPE*> +{ + typedef TYPE* parameter_type; +}; + /** * @class ACE_Atomic_Op_Ex * @@ -40,17 +147,20 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL * optimisations to provide atomic operations without requiring a * lock. */ -template <class ACE_LOCK, class TYPE> +template <class ACE_LOCK, typename TYPE> class ACE_Atomic_Op_Ex { public: + + typedef typename ACE_Type_Traits<TYPE>::parameter_type arg_type; + // = Initialization methods. /// Initialize @c value_ to 0. - ACE_Atomic_Op_Ex (ACE_LOCK &mtx); + ACE_Atomic_Op_Ex (ACE_LOCK & mtx); /// Initialize @c value_ to c. - ACE_Atomic_Op_Ex (ACE_LOCK &mtx, const TYPE &c); + ACE_Atomic_Op_Ex (ACE_LOCK & mtx, arg_type c); // = Accessors. @@ -61,7 +171,7 @@ public: TYPE operator++ (int); /// Atomically increment @c value_ by rhs. - TYPE operator+= (const TYPE &rhs); + TYPE operator+= (arg_type rhs); /// Atomically pre-decrement @c value_. TYPE operator-- (void); @@ -70,31 +180,32 @@ public: TYPE operator-- (int); /// Atomically decrement @c value_ by rhs. - TYPE operator-= (const TYPE &rhs); + TYPE operator-= (arg_type rhs); /// Atomically compare @c value_ with rhs. - bool operator== (const TYPE &rhs) const; + bool operator== (arg_type rhs) const; /// Atomically compare @c value_ with rhs. - bool operator!= (const TYPE &rhs) const; + bool operator!= (arg_type rhs) const; /// Atomically check if @c value_ greater than or equal to rhs. - bool operator>= (const TYPE &rhs) const; + bool operator>= (arg_type rhs) const; /// Atomically check if @c value_ greater than rhs. - bool operator> (const TYPE &rhs) const; + bool operator> (arg_type rhs) const; /// Atomically check if @c value_ less than or equal to rhs. - bool operator<= (const TYPE &rhs) const; + bool operator<= (arg_type rhs) const; /// Atomically check if @c value_ less than rhs. - bool operator< (const TYPE &rhs) const; + bool operator< (arg_type rhs) const; /// Atomically assign rhs to @c value_. - ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> &operator= (const TYPE &rhs); + ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> &operator= (arg_type rhs); /// Atomically assign <rhs> to @c value_. - ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> &operator= (const ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> &rhs); + ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> &operator= ( + ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> const & rhs); /// Explicitly return @c value_. TYPE value (void) const; @@ -106,7 +217,7 @@ public: // Declare the dynamic allocation hooks. /// Manage copying... - ACE_Atomic_Op_Ex (const ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> &); + ACE_Atomic_Op_Ex (ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> const &); /** * Returns a reference to the underlying <ACE_LOCK>. This makes it @@ -115,7 +226,7 @@ public: * ACE_Recursive_Mutex or ACE_Process_Mutex. @note the right * name would be lock_, but HP/C++ will choke on that! */ - ACE_LOCK &mutex (void); + ACE_LOCK & mutex (void); /** * Explicitly return @c value_ (by reference). This gives the user @@ -123,11 +234,11 @@ public: * will usually be used in conjunction with explicit access to the * lock. Use with care ;-) */ - TYPE &value_i (void); + TYPE & value_i (void); private: /// Type of synchronization mechanism. - ACE_LOCK &mutex_; + ACE_LOCK & mutex_; /// Current object decorated by the atomic op. TYPE value_; @@ -147,24 +258,28 @@ private: * ACE_Atomic_Op <ACE_Thread_Mutex, long> that provides optimized * atomic integer operations without actually requiring a mutex. */ -template <class ACE_LOCK, class TYPE> +template <class ACE_LOCK, typename TYPE> class ACE_Atomic_Op { public: + + typedef typename ACE_Type_Traits<TYPE>::parameter_type arg_type; + /// Initialize @c value_ to 0. ACE_Atomic_Op (void); /// Initialize @c value_ to c. - ACE_Atomic_Op (const TYPE &c); + ACE_Atomic_Op (arg_type c); /// Manage copying... - ACE_Atomic_Op (const ACE_Atomic_Op<ACE_LOCK, TYPE> &c); + ACE_Atomic_Op (ACE_Atomic_Op<ACE_LOCK, TYPE> const & c); /// Atomically assign rhs to @c value_. - ACE_Atomic_Op<ACE_LOCK, TYPE> &operator= (const TYPE &rhs); + ACE_Atomic_Op<ACE_LOCK, TYPE> & operator= (arg_type rhs); /// Atomically assign <rhs> to @c value_. - ACE_Atomic_Op<ACE_LOCK, TYPE> &operator= (const ACE_Atomic_Op<ACE_LOCK, TYPE> &rhs); + ACE_Atomic_Op<ACE_LOCK, TYPE> & operator= ( + ACE_Atomic_Op<ACE_LOCK, TYPE> const & rhs); /// Atomically pre-increment @c value_. TYPE operator++ (void); @@ -173,7 +288,7 @@ public: TYPE operator++ (int); /// Atomically increment @c value_ by rhs. - TYPE operator+= (const TYPE &rhs); + TYPE operator+= (arg_type rhs); /// Atomically pre-decrement @c value_. TYPE operator-- (void); @@ -182,25 +297,25 @@ public: TYPE operator-- (int); /// Atomically decrement @c value_ by rhs. - TYPE operator-= (const TYPE &rhs); + TYPE operator-= (arg_type rhs); /// Atomically compare @c value_ with rhs. - bool operator== (const TYPE &rhs) const; + bool operator== (arg_type rhs) const; /// Atomically compare @c value_ with rhs. - bool operator!= (const TYPE &rhs) const; + bool operator!= (arg_type rhs) const; /// Atomically check if @c value_ greater than or equal to rhs. - bool operator>= (const TYPE &rhs) const; + bool operator>= (arg_type rhs) const; /// Atomically check if @c value_ greater than rhs. - bool operator> (const TYPE &rhs) const; + bool operator> (arg_type rhs) const; /// Atomically check if @c value_ less than or equal to rhs. - bool operator<= (const TYPE &rhs) const; + bool operator<= (arg_type rhs) const; /// Atomically check if @c value_ less than rhs. - bool operator< (const TYPE &rhs) const; + bool operator< (arg_type rhs) const; /// Explicitly return @c value_. TYPE value (void) const; @@ -218,7 +333,7 @@ public: * the future. If you need access to the underlying mutex, consider * using the ACE_Atomic_Op_Ex template instead. */ - ACE_LOCK &mutex (void); + ACE_LOCK & mutex (void); /** * Explicitly return @c value_ (by reference). This gives the user @@ -226,7 +341,7 @@ public: * will usually be used in conjunction with explicit access to the * lock. Use with care ;-) */ - TYPE &value_i (void); + TYPE & value_i (void); private: /// Type of synchronization mechanism. diff --git a/ACE/ace/Atomic_Op_T.inl b/ACE/ace/Atomic_Op_T.inl index d41be1cbd15..3d09ba304fe 100644 --- a/ACE/ace/Atomic_Op_T.inl +++ b/ACE/ace/Atomic_Op_T.inl @@ -4,138 +4,165 @@ #include "ace/Guard_T.h" +#include <algorithm> + ACE_BEGIN_VERSIONED_NAMESPACE_DECL // // ACE_Atomic_Op_Ex inline functions // -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator++ (void) { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator++"); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator++"); ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_); return ++this->value_; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator+= (const TYPE &rhs) +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator+= ( + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type rhs) { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator+="); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator+="); ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_); return this->value_ += rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator-- (void) { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator--"); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator--"); ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_); return --this->value_; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator-= (const TYPE &rhs) +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator-= ( + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type rhs) { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator-="); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator-="); ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_); return this->value_ -= rhs; } -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> &rhs) +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 & rhs) : mutex_ (rhs.mutex_) + , value_ (rhs.value ()) // rhs.value() returns atomically { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex"); - *this = rhs; // Invoke the assignment operator. + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::ACE_Atomic_Op_Ex"); } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator++ (int) { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator++"); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator++"); ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_); return this->value_++; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator-- (int) { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator--"); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator--"); ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_); return this->value_--; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator== (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator== ( + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type rhs) const { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator=="); - ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, false); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator=="); + ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, false); return this->value_ == rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator!= (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator!= ( + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type rhs) const { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator!="); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator!="); return !(*this == rhs); } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator>= (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator>= ( + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type rhs) const { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator>="); - ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, false); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator>="); + ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, false); return this->value_ >= rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator> (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator> ( + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type rhs) const { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator>"); - ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, false); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator>"); + ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, false); return this->value_ > rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator<= (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator<= ( + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type rhs) const { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator<="); - ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, false); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator<="); + ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, false); return this->value_ <= rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator< (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator< ( + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type rhs) const { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator<"); - ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, false); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator<"); + ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, false); return this->value_ < rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> & -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator= (const ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> &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) { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator="); - if (&rhs == this) - return *this; // Avoid deadlock... + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator="); + + ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> tmp (rhs); + ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, *this); - // This will call ACE_Atomic_Op_Ex::TYPE(), which will ensure the - // value of <rhs> is acquired atomically. + std::swap (this->value_, tmp.value_); - this->value_ = rhs.value (); return *this; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::value (void) const { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::value"); - ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_LOCK &) this->mutex_, this->value_); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::value"); + ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, this->value_); return this->value_; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE & +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 @@ -145,10 +172,12 @@ ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::value_i (void) return this->value_; } -template <class ACE_LOCK, class TYPE> ACE_INLINE ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> & -ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator= (const TYPE &rhs) +template <class ACE_LOCK, class TYPE> +ACE_INLINE ACE_Atomic_Op_Ex<ACE_LOCK, TYPE> & +ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator= ( + typename ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::arg_type rhs) { -// ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator="); + // ACE_TRACE ("ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator="); ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, *this); this->value_ = rhs; return *this; @@ -159,107 +188,133 @@ ACE_Atomic_Op_Ex<ACE_LOCK, TYPE>::operator= (const TYPE &rhs) // template <class ACE_LOCK, class TYPE> ACE_INLINE -ACE_Atomic_Op<ACE_LOCK, TYPE>::ACE_Atomic_Op - (const ACE_Atomic_Op<ACE_LOCK, TYPE> &rhs) +ACE_Atomic_Op<ACE_LOCK, TYPE>::ACE_Atomic_Op ( + ACE_Atomic_Op<ACE_LOCK, TYPE> const & rhs) : impl_ (own_mutex_, rhs.value ()) { -// ACE_TRACE ("ACE_Atomic_Op<ACE_LOCK, TYPE>::ACE_Atomic_Op"); + // ACE_TRACE ("ACE_Atomic_Op<ACE_LOCK, TYPE>::ACE_Atomic_Op"); } -template <class ACE_LOCK, class TYPE> ACE_INLINE ACE_Atomic_Op<ACE_LOCK, TYPE> & -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator= (const TYPE &i) +template <class ACE_LOCK, class TYPE> +ACE_INLINE ACE_Atomic_Op<ACE_LOCK, TYPE> & +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator= ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type i) { this->impl_ = i; return *this; } -template <class ACE_LOCK, class TYPE> ACE_INLINE ACE_Atomic_Op<ACE_LOCK, TYPE> & -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator= (const ACE_Atomic_Op<ACE_LOCK, TYPE> &rhs) +template <class ACE_LOCK, class TYPE> +ACE_INLINE ACE_Atomic_Op<ACE_LOCK, TYPE> & +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator= ( + ACE_Atomic_Op<ACE_LOCK, TYPE> const & rhs) { this->impl_ = rhs.impl_; return *this; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op<ACE_LOCK, TYPE>::operator++ (void) { return ++this->impl_; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op<ACE_LOCK, TYPE>::operator++ (int) { return this->impl_++; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator+= (const TYPE &rhs) +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator+= ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type rhs) { return this->impl_ += rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op<ACE_LOCK, TYPE>::operator-- (void) { return --this->impl_; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op<ACE_LOCK, TYPE>::operator-- (int) { return this->impl_--; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator-= (const TYPE &rhs) +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator-= ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type rhs) { return this->impl_ -= rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator== (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator== ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type rhs) const { return this->impl_ == rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator!= (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator!= ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type rhs) const { return this->impl_ != rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator>= (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator>= ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type rhs) const { return this->impl_ >= rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator> (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator> ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type rhs) const { return this->impl_ > rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator<= (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator<= ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type rhs) const { return this->impl_ <= rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE bool -ACE_Atomic_Op<ACE_LOCK, TYPE>::operator< (const TYPE &rhs) const +template <class ACE_LOCK, class TYPE> +ACE_INLINE bool +ACE_Atomic_Op<ACE_LOCK, TYPE>::operator< ( + typename ACE_Atomic_Op<ACE_LOCK, TYPE>::arg_type rhs) const { return this->impl_ < rhs; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE ACE_Atomic_Op<ACE_LOCK, TYPE>::value (void) const { return this->impl_.value (); } -template <class ACE_LOCK, class TYPE> ACE_INLINE void +template <class ACE_LOCK, class TYPE> +ACE_INLINE void ACE_Atomic_Op<ACE_LOCK, TYPE>::dump (void) const { #if defined (ACE_HAS_DUMP) @@ -268,13 +323,15 @@ ACE_Atomic_Op<ACE_LOCK, TYPE>::dump (void) const return; } -template <class ACE_LOCK, class TYPE> ACE_INLINE ACE_LOCK & +template <class ACE_LOCK, class TYPE> +ACE_INLINE ACE_LOCK & ACE_Atomic_Op<ACE_LOCK, TYPE>::mutex (void) { return this->own_mutex_; } -template <class ACE_LOCK, class TYPE> ACE_INLINE TYPE & +template <class ACE_LOCK, class TYPE> +ACE_INLINE TYPE & ACE_Atomic_Op<ACE_LOCK, TYPE>::value_i (void) { return this->impl_.value_i (); |