#ifndef ROOT_TAtomicCountGcc
#define ROOT_TAtomicCountGcc
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2) || \
(defined(__APPLE_CC__) && __APPLE_CC__ > 5000 && !defined(MAC_OS_X_VERSION_10_6))
#include <bits/atomicity.h>
#else
#include <ext/atomicity.h>
#endif
#if defined(__GLIBCXX__) // g++ 3.4+
using __gnu_cxx::__atomic_add;
using __gnu_cxx::__exchange_and_add;
#endif
class TAtomicCount {
private:
mutable _Atomic_word fCnt;
TAtomicCount(const TAtomicCount &);
TAtomicCount &operator=(const TAtomicCount &);
public:
explicit TAtomicCount(Long_t v) : fCnt(v) { }
void operator++() { __atomic_add(&fCnt, 1); }
Long_t operator--() { return __exchange_and_add(&fCnt, -1) - 1; }
operator long() const { return __exchange_and_add(&fCnt, 0); }
void Set(Long_t v) {
fCnt = v;
#ifdef _GLIBCXX_WRITE_MEM_BARRIER
#if !(defined(__INTEL_COMPILER) && defined(__ia64__)) //ICC doesn't support inline asm on IA-64
_GLIBCXX_WRITE_MEM_BARRIER;
#endif
#endif
}
Long_t Get() const { return __exchange_and_add(&fCnt, 0); }
};
#endif