00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TAtomicCountGcc
00013 #define ROOT_TAtomicCountGcc
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2) || \
00032 (defined(__APPLE_CC__) && __APPLE_CC__ > 5000 && !defined(MAC_OS_X_VERSION_10_6))
00033 #include <bits/atomicity.h>
00034 #else
00035 #include <ext/atomicity.h>
00036 #endif
00037
00038 #if defined(__GLIBCXX__) // g++ 3.4+
00039
00040 using __gnu_cxx::__atomic_add;
00041 using __gnu_cxx::__exchange_and_add;
00042
00043 #endif
00044
00045
00046 class TAtomicCount {
00047 private:
00048 mutable _Atomic_word fCnt;
00049
00050 TAtomicCount(const TAtomicCount &);
00051 TAtomicCount &operator=(const TAtomicCount &);
00052
00053 public:
00054 explicit TAtomicCount(Long_t v) : fCnt(v) { }
00055 void operator++() { __atomic_add(&fCnt, 1); }
00056 Long_t operator--() { return __exchange_and_add(&fCnt, -1) - 1; }
00057 operator long() const { return __exchange_and_add(&fCnt, 0); }
00058 void Set(Long_t v) {
00059 fCnt = v;
00060 #ifdef _GLIBCXX_WRITE_MEM_BARRIER
00061 #if !(defined(__INTEL_COMPILER) && defined(__ia64__)) //ICC doesn't support inline asm on IA-64
00062 _GLIBCXX_WRITE_MEM_BARRIER;
00063 #endif
00064 #endif
00065 }
00066 Long_t Get() const { return __exchange_and_add(&fCnt, 0); }
00067 };
00068
00069 #endif