From a175b8356b3a4182e24bd57268ad173f0583e3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Tue, 8 Oct 2013 16:06:03 +0200 Subject: [PATCH] Reintroduce the old RefCounter from 1.8, which is needed by TagLib::Map<> and TagLib::List<> (closes #296) --- taglib/toolkit/tlist.tcc | 3 +- taglib/toolkit/tmap.tcc | 9 +++--- taglib/toolkit/trefcounter.h | 53 ++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/taglib/toolkit/tlist.tcc b/taglib/toolkit/tlist.tcc index 81e29153..72d4767b 100644 --- a/taglib/toolkit/tlist.tcc +++ b/taglib/toolkit/tlist.tcc @@ -39,7 +39,8 @@ namespace TagLib { // A base for the generic and specialized private class types. New // non-templatized members should be added here. -class ListPrivateBase : public RefCounter +// BIC change to RefCounter +class ListPrivateBase : public RefCounterOld { public: ListPrivateBase() : autoDelete(false) {} diff --git a/taglib/toolkit/tmap.tcc b/taglib/toolkit/tmap.tcc index d6f51c07..5d3abcad 100644 --- a/taglib/toolkit/tmap.tcc +++ b/taglib/toolkit/tmap.tcc @@ -31,17 +31,18 @@ namespace TagLib { // public members //////////////////////////////////////////////////////////////////////////////// +// BIC change to RefCounter template template -class Map::MapPrivate : public RefCounter +class Map::MapPrivate : public RefCounterOld { public: - MapPrivate() : RefCounter() {} + MapPrivate() : RefCounterOld() {} #ifdef WANT_CLASS_INSTANTIATION_OF_MAP - MapPrivate(const std::map& m) : RefCounter(), map(m) {} + MapPrivate(const std::map& m) : RefCounterOld(), map(m) {} std::map map; #else - MapPrivate(const std::map& m) : RefCounter(), map(m) {} + MapPrivate(const std::map& m) : RefCounterOld(), map(m) {} std::map map; #endif }; diff --git a/taglib/toolkit/trefcounter.h b/taglib/toolkit/trefcounter.h index 53c6f1c0..75388b10 100644 --- a/taglib/toolkit/trefcounter.h +++ b/taglib/toolkit/trefcounter.h @@ -29,6 +29,23 @@ #include "taglib_export.h" #include "taglib.h" +#ifdef __APPLE__ +# include +# define TAGLIB_ATOMIC_MAC +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define NOMINMAX +# include +# define TAGLIB_ATOMIC_WIN +#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 401) \ + && (defined(__i386__) || defined(__i486__) || defined(__i586__) || \ + defined(__i686__) || defined(__x86_64) || defined(__ia64)) \ + && !defined(__INTEL_COMPILER) +# define TAGLIB_ATOMIC_GCC +#elif defined(__ia64) && defined(__INTEL_COMPILER) +# include +# define TAGLIB_ATOMIC_GCC +#endif + #ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class. /*! * \internal @@ -38,6 +55,7 @@ */ namespace TagLib { + class TAGLIB_EXPORT RefCounter { public: @@ -52,7 +70,42 @@ namespace TagLib class RefCounterPrivate; RefCounterPrivate *d; }; + + // BIC this old class is needed by tlist.tcc and tmap.tcc + class RefCounterOld + { + public: + RefCounterOld() : refCount(1) {} + +#ifdef TAGLIB_ATOMIC_MAC + void ref() { OSAtomicIncrement32Barrier(const_cast(&refCount)); } + bool deref() { return ! OSAtomicDecrement32Barrier(const_cast(&refCount)); } + int32_t count() { return refCount; } + private: + volatile int32_t refCount; +#elif defined(TAGLIB_ATOMIC_WIN) + void ref() { InterlockedIncrement(&refCount); } + bool deref() { return ! InterlockedDecrement(&refCount); } + long count() { return refCount; } + private: + volatile long refCount; +#elif defined(TAGLIB_ATOMIC_GCC) + void ref() { __sync_add_and_fetch(&refCount, 1); } + bool deref() { return ! __sync_sub_and_fetch(&refCount, 1); } + int count() { return refCount; } + private: + volatile int refCount; +#else + void ref() { refCount++; } + bool deref() { return ! --refCount; } + int count() { return refCount; } + private: + uint refCount; +#endif + }; + } #endif // DO_NOT_DOCUMENT #endif +