From 0cdfa793e98cab96ab36004c4d59c9b251b4ef9a Mon Sep 17 00:00:00 2001 From: Nick Shaforostoff Date: Thu, 10 Mar 2011 17:29:30 +0000 Subject: [PATCH] use atomic refcounting on mac and win32, todo for linux git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1224407 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- taglib/toolkit/taglib.h | 22 ++++++++++++++++++++++ taglib/toolkit/tfile.cpp | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h index 65a0c0b2..a43cdb6d 100644 --- a/taglib/toolkit/taglib.h +++ b/taglib/toolkit/taglib.h @@ -44,6 +44,12 @@ #include +#ifdef __APPLE__ +#include +#elif defined(_MSC_VER) +#include +#endif + //! A namespace for all TagLib related classes and functions /*! @@ -81,11 +87,27 @@ namespace TagLib { { public: RefCounter() : refCount(1) {} + +#ifdef __APPLE__ + void ref() { OSAtomicIncrement32(&refCount); } + bool deref() { return ! OSAtomicDecrement32(&refCount); } + int32_t count() { return refCount; } + private: + volatile int32_t refCount; +#elif defined(_MSC_VER) + void ref() { InterlockedIncrement(&refCount); } + bool deref() { return ! InterlockedDecrement(&refCount); } + long count() { return refCount; } + private: + volatile long refCount; +#else void ref() { refCount++; } bool deref() { return ! --refCount ; } int count() { return refCount; } private: uint refCount; +#endif + }; #endif // DO_NOT_DOCUMENT diff --git a/taglib/toolkit/tfile.cpp b/taglib/toolkit/tfile.cpp index f0b3c80d..7ba4c00c 100644 --- a/taglib/toolkit/tfile.cpp +++ b/taglib/toolkit/tfile.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef _WIN32 # include @@ -115,7 +116,10 @@ File::FilePrivate::FilePrivate(FileName fileName) : file = fopen(name, "rb"); if(!file) + { debug("Could not open file " + String((const char *) name)); + std::cout<<"Could not open file"<