Atomic_Op.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Atomic_Op.inl,v 4.8 2005/11/15 16:32:26 shuston Exp
00004 
00005 
00006 #if defined (ACE_HAS_BUILTIN_ATOMIC_OP)
00007 
00008 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00009 
00010 ACE_INLINE
00011 ACE_Atomic_Op<ACE_Thread_Mutex, long>::ACE_Atomic_Op (void)
00012   : value_ (0)
00013 {
00014 }
00015 
00016 ACE_INLINE
00017 ACE_Atomic_Op<ACE_Thread_Mutex, long>::ACE_Atomic_Op (const long &c)
00018   : value_ (c)
00019 {
00020 }
00021 
00022 ACE_INLINE
00023 ACE_Atomic_Op<ACE_Thread_Mutex, long>::ACE_Atomic_Op (
00024   const ACE_Atomic_Op<ACE_Thread_Mutex, long> &rhs)
00025   : value_ (rhs.value_)
00026 {
00027 }
00028 
00029 ACE_INLINE long
00030 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator++ (void)
00031 {
00032 #if defined (WIN32)
00033   return ::InterlockedIncrement (const_cast<long *> (&this->value_));
00034 #else /* WIN32 */
00035   return (*increment_fn_) (&this->value_);
00036 #endif /* WIN32 */
00037 }
00038 
00039 ACE_INLINE long
00040 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator++ (int)
00041 {
00042   return ++*this - 1;
00043 }
00044 
00045 ACE_INLINE long
00046 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator-- (void)
00047 {
00048 #if defined (WIN32)
00049   return ::InterlockedDecrement (const_cast<long *> (&this->value_));
00050 #else /* WIN32 */
00051   return (*decrement_fn_) (&this->value_);
00052 #endif /* WIN32 */
00053 }
00054 
00055 ACE_INLINE long
00056 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator-- (int)
00057 {
00058   return --*this + 1;
00059 }
00060 
00061 ACE_INLINE long
00062 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator+= (long rhs)
00063 {
00064 #if defined (WIN32) && defined (ACE_HAS_INTERLOCKED_EXCHANGEADD)
00065   return ::InterlockedExchangeAdd (const_cast<long *> (&this->value_),
00066                                    rhs) + rhs;
00067 #else /* WIN32 && ACE_HAS_INTERLOCKED_EXCHANGEADD */
00068   return (*exchange_add_fn_) (&this->value_, rhs) + rhs;
00069 #endif /* WIN32 && ACE_HAS_INTERLOCKED_EXCHANGEADD */
00070 }
00071 
00072 ACE_INLINE long
00073 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator-= (long rhs)
00074 {
00075 #if defined (WIN32) && defined (ACE_HAS_INTERLOCKED_EXCHANGEADD)
00076   return ::InterlockedExchangeAdd (const_cast<long *> (&this->value_),
00077                                    -rhs) - rhs;
00078 #else /* WIN32 && ACE_HAS_INTERLOCKED_EXCHANGEADD */
00079   return (*exchange_add_fn_) (&this->value_, -rhs) - rhs;
00080 #endif /* WIN32 && ACE_HAS_INTERLOCKED_EXCHANGEADD */
00081 }
00082 
00083 ACE_INLINE bool
00084 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator== (long rhs) const
00085 {
00086   return (this->value_ == rhs);
00087 }
00088 
00089 ACE_INLINE bool
00090 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator!= (long rhs) const
00091 {
00092   return (this->value_ != rhs);
00093 }
00094 
00095 ACE_INLINE bool
00096 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator>= (long rhs) const
00097 {
00098   return (this->value_ >= rhs);
00099 }
00100 
00101 ACE_INLINE bool
00102 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator> (long rhs) const
00103 {
00104   return (this->value_ > rhs);
00105 }
00106 
00107 ACE_INLINE bool
00108 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator<= (long rhs) const
00109 {
00110   return (this->value_ <= rhs);
00111 }
00112 
00113 ACE_INLINE bool
00114 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator< (long rhs) const
00115 {
00116   return (this->value_ < rhs);
00117 }
00118 
00119 ACE_INLINE ACE_Atomic_Op<ACE_Thread_Mutex, long> &
00120 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator= (long rhs)
00121 {
00122 #if defined (WIN32)
00123   ::InterlockedExchange (const_cast<long *> (&this->value_), rhs);
00124 #else /* WIN32 */
00125   (*exchange_fn_) (&this->value_, rhs);
00126 #endif /* WIN32 */
00127   return *this;
00128 }
00129 
00130 ACE_INLINE ACE_Atomic_Op<ACE_Thread_Mutex, long> &
00131 ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator= (
00132    const ACE_Atomic_Op<ACE_Thread_Mutex, long> &rhs)
00133 {
00134 #if defined (WIN32)
00135   ::InterlockedExchange (const_cast<long *> (&this->value_), rhs.value_);
00136 #else /* WIN32 */
00137   (*exchange_fn_) (&this->value_, rhs.value_);
00138 #endif /* WIN32 */
00139   return *this;
00140 }
00141 
00142 ACE_INLINE long
00143 ACE_Atomic_Op<ACE_Thread_Mutex, long>::value (void) const
00144 {
00145   return this->value_;
00146 }
00147 
00148 ACE_INLINE volatile long &
00149 ACE_Atomic_Op<ACE_Thread_Mutex, long>::value_i (void)
00150 {
00151   return this->value_;
00152 }
00153 
00154 
00155 ACE_INLINE
00156 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::ACE_Atomic_Op (void)
00157   : value_ (0)
00158 {
00159 }
00160 
00161 ACE_INLINE
00162 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::ACE_Atomic_Op (const unsigned long &c)
00163   : value_ (c)
00164 {
00165 }
00166 
00167 ACE_INLINE
00168 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::ACE_Atomic_Op (
00169   const ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long> &rhs)
00170   : value_ (rhs.value_)
00171 {
00172 }
00173 
00174 ACE_INLINE unsigned long
00175 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator++ (void)
00176 {
00177 #if defined (WIN32)
00178   return static_cast<unsigned long> (::InterlockedIncrement (const_cast<long *> (reinterpret_cast<volatile long *>(&this->value_))));
00179 #else /* WIN32 */
00180   return static_cast<unsigned long> ((*increment_fn_) (reinterpret_cast<volatile long *> (&this->value_)));
00181 #endif /* WIN32 */
00182 }
00183 
00184 ACE_INLINE unsigned long
00185 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator++ (int)
00186 {
00187   return ++*this - 1;
00188 }
00189 
00190 ACE_INLINE unsigned long
00191 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator-- (void)
00192 {
00193 #if defined (WIN32)
00194   return static_cast<unsigned long> (::InterlockedDecrement (const_cast<long *> (reinterpret_cast<volatile long *>(&this->value_))));
00195 #else /* WIN32 */
00196   return static_cast<unsigned long> ((*decrement_fn_) (reinterpret_cast<volatile long *> (&this->value_)));
00197 #endif /* WIN32 */
00198 }
00199 
00200 ACE_INLINE unsigned long
00201 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator-- (int)
00202 {
00203   return --*this + 1;
00204 }
00205 
00206 ACE_INLINE unsigned long
00207 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator+= (unsigned long rhs)
00208 {
00209 #if defined (WIN32) && defined (ACE_HAS_INTERLOCKED_EXCHANGEADD)
00210   return static_cast<unsigned long> (::InterlockedExchangeAdd (const_cast<long *> (reinterpret_cast <volatile long *>(&this->value_)),
00211                                    rhs)) + rhs;
00212 #else /* WIN32 && ACE_HAS_INTERLOCKED_EXCHANGEADD */
00213   return static_cast<unsigned long> ((*exchange_add_fn_) (reinterpret_cast<volatile long *> (&this->value_), rhs)) + rhs;
00214 #endif /* WIN32 && ACE_HAS_INTERLOCKED_EXCHANGEADD */
00215 }
00216 
00217 ACE_INLINE unsigned long
00218 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator-= (unsigned long rhs)
00219 {
00220 #if defined (WIN32) && defined (ACE_HAS_INTERLOCKED_EXCHANGEADD)
00221   return static_cast<unsigned long> (::InterlockedExchangeAdd (const_cast<long *> (reinterpret_cast<volatile long *>(&this->value_)),
00222                                    -static_cast<long>(rhs))) - rhs;
00223 #else /* WIN32 && ACE_HAS_INTERLOCKED_EXCHANGEADD */
00224   return static_cast<unsigned long> ((*exchange_add_fn_) (reinterpret_cast<volatile long *> (&this->value_), -rhs)) - rhs;
00225 #endif /* WIN32 && ACE_HAS_INTERLOCKED_EXCHANGEADD */
00226 }
00227 
00228 ACE_INLINE bool
00229 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator== (unsigned long rhs) const
00230 {
00231   return (this->value_ == rhs);
00232 }
00233 
00234 ACE_INLINE bool
00235 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator!= (unsigned long rhs) const
00236 {
00237   return (this->value_ != rhs);
00238 }
00239 
00240 ACE_INLINE bool
00241 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator>= (unsigned long rhs) const
00242 {
00243   return (this->value_ >= rhs);
00244 }
00245 
00246 ACE_INLINE bool
00247 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator> (unsigned long rhs) const
00248 {
00249   return (this->value_ > rhs);
00250 }
00251 
00252 ACE_INLINE bool
00253 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator<= (unsigned long rhs) const
00254 {
00255   return (this->value_ <= rhs);
00256 }
00257 
00258 ACE_INLINE bool
00259 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator< (unsigned long rhs) const
00260 {
00261   return (this->value_ < rhs);
00262 }
00263 
00264 ACE_INLINE ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long> &
00265 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator= (unsigned long rhs)
00266 {
00267 #if defined (WIN32)
00268   ::InterlockedExchange (const_cast<long *> (reinterpret_cast<volatile long*> (&this->value_)), rhs);
00269 #else /* WIN32 */
00270   (*exchange_fn_) (reinterpret_cast<volatile long *> (&this->value_), rhs);
00271 #endif /* WIN32 */
00272   return *this;
00273 }
00274 
00275 ACE_INLINE ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long> &
00276 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::operator= (
00277    const ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long> &rhs)
00278 {
00279 #if defined (WIN32)
00280   ::InterlockedExchange (const_cast<long *> (reinterpret_cast<volatile long*> (&this->value_)), rhs.value_);
00281 #else /* WIN32 */
00282   (*exchange_fn_) (reinterpret_cast<volatile long *> (&this->value_), rhs.value_);
00283 #endif /* WIN32 */
00284   return *this;
00285 }
00286 
00287 ACE_INLINE unsigned long
00288 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::value (void) const
00289 {
00290   return this->value_;
00291 }
00292 
00293 ACE_INLINE volatile unsigned long &
00294 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::value_i (void)
00295 {
00296   return this->value_;
00297 }
00298 
00299 ACE_END_VERSIONED_NAMESPACE_DECL
00300 
00301 #endif /* ACE_HAS_BUILTIN_ATOMIC_OP */

Generated on Thu Nov 9 09:41:46 2006 for ACE by doxygen 1.3.6