Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef TAGLIB_REFCOUNTER_H
00027 #define TAGLIB_REFCOUNTER_H
00028
00029 #include "taglib_export.h"
00030 #include "taglib.h"
00031
00032 #ifdef __APPLE__
00033 # include <libkern/OSAtomic.h>
00034 # define TAGLIB_ATOMIC_MAC
00035 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
00036 # ifndef NOMINMAX
00037 # define NOMINMAX
00038 # endif
00039 # include <windows.h>
00040 # define TAGLIB_ATOMIC_WIN
00041 #elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 401) \
00042 && (defined(__i386__) || defined(__i486__) || defined(__i586__) || \
00043 defined(__i686__) || defined(__x86_64) || defined(__ia64)) \
00044 && !defined(__INTEL_COMPILER)
00045 # define TAGLIB_ATOMIC_GCC
00046 #elif defined(__ia64) && defined(__INTEL_COMPILER)
00047 # include <ia64intrin.h>
00048 # define TAGLIB_ATOMIC_GCC
00049 #endif
00050
00051 #ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class.
00052
00058 namespace TagLib
00059 {
00060
00061 class TAGLIB_EXPORT RefCounter
00062 {
00063 public:
00064 RefCounter();
00065 virtual ~RefCounter();
00066
00067 void ref();
00068 bool deref();
00069 int count() const;
00070
00071 private:
00072 class RefCounterPrivate;
00073 RefCounterPrivate *d;
00074 };
00075
00076
00077 class RefCounterOld
00078 {
00079 public:
00080 RefCounterOld() : refCount(1) {}
00081
00082 #ifdef TAGLIB_ATOMIC_MAC
00083 void ref() { OSAtomicIncrement32Barrier(const_cast<int32_t*>(&refCount)); }
00084 bool deref() { return ! OSAtomicDecrement32Barrier(const_cast<int32_t*>(&refCount)); }
00085 int32_t count() { return refCount; }
00086 private:
00087 volatile int32_t refCount;
00088 #elif defined(TAGLIB_ATOMIC_WIN)
00089 void ref() { InterlockedIncrement(&refCount); }
00090 bool deref() { return ! InterlockedDecrement(&refCount); }
00091 long count() { return refCount; }
00092 private:
00093 volatile long refCount;
00094 #elif defined(TAGLIB_ATOMIC_GCC)
00095 void ref() { __sync_add_and_fetch(&refCount, 1); }
00096 bool deref() { return ! __sync_sub_and_fetch(&refCount, 1); }
00097 int count() { return refCount; }
00098 private:
00099 volatile int refCount;
00100 #else
00101 void ref() { refCount++; }
00102 bool deref() { return ! --refCount; }
00103 int count() { return refCount; }
00104 private:
00105 uint refCount;
00106 #endif
00107 };
00108
00109 }
00110
00111 #endif // DO_NOT_DOCUMENT
00112 #endif
00113