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