]> granicus.if.org Git - taglib/commitdiff
use atomic refcounting on mac and win32, todo for linux
authorNick Shaforostoff <shafff@ukr.net>
Thu, 10 Mar 2011 17:29:30 +0000 (17:29 +0000)
committerNick Shaforostoff <shafff@ukr.net>
Thu, 10 Mar 2011 17:29:30 +0000 (17:29 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1224407 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/toolkit/taglib.h
taglib/toolkit/tfile.cpp

index 65a0c0b2dcef58f225abc648b0558cdbd5a1815f..a43cdb6d8e7ee10fe699b1f3356a61fe436670e5 100644 (file)
 
 #include <string>
 
+#ifdef __APPLE__
+#include <libkern/OSAtomic.h>
+#elif defined(_MSC_VER)
+#include <Windows.h>
+#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
index f0b3c80d5da4844bc201f6055e02d871716e5648..7ba4c00c1dea93508a7af3037d9e8b44a5cb15a7 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <iostream>
 
 #ifdef _WIN32
 # include <wchar.h>
@@ -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"<<name<<std::endl;
+  }
 }
 
 ////////////////////////////////////////////////////////////////////////////////