26 #ifndef TAGLIB_REFCOUNTER_H
27 #define TAGLIB_REFCOUNTER_H
33 # include <libkern/OSAtomic.h>
34 # define TAGLIB_ATOMIC_MAC
35 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
40 # define TAGLIB_ATOMIC_WIN
41 #elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 401) \
42 && (defined(__i386__) || defined(__i486__) || defined(__i586__) || \
43 defined(__i686__) || defined(__x86_64) || defined(__ia64)) \
44 && !defined(__INTEL_COMPILER)
45 # define TAGLIB_ATOMIC_GCC
46 #elif defined(__ia64) && defined(__INTEL_COMPILER)
47 # include <ia64intrin.h>
48 # define TAGLIB_ATOMIC_GCC
51 #ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class.
65 virtual ~RefCounter();
72 class RefCounterPrivate;
80 RefCounterOld() : refCount(1) {}
82 #ifdef TAGLIB_ATOMIC_MAC
83 void ref() { OSAtomicIncrement32Barrier(
const_cast<int32_t*
>(&refCount)); }
84 bool deref() {
return ! OSAtomicDecrement32Barrier(
const_cast<int32_t*
>(&refCount)); }
85 int32_t count() {
return refCount; }
87 volatile int32_t refCount;
88 #elif defined(TAGLIB_ATOMIC_WIN)
89 void ref() { InterlockedIncrement(&refCount); }
90 bool deref() {
return ! InterlockedDecrement(&refCount); }
91 long count() {
return refCount; }
93 volatile long refCount;
94 #elif defined(TAGLIB_ATOMIC_GCC)
95 void ref() { __sync_add_and_fetch(&refCount, 1); }
96 bool deref() {
return ! __sync_sub_and_fetch(&refCount, 1); }
97 int count() {
return refCount; }
99 volatile int refCount;
101 void ref() { refCount++; }
102 bool deref() {
return ! --refCount; }
103 int count() {
return refCount; }
105 unsigned int refCount;
111 #endif // DO_NOT_DOCUMENT