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
This commit is contained in:
Nick Shaforostoff 2011-03-10 17:29:30 +00:00
parent eee860f9c6
commit 0cdfa793e9
2 changed files with 26 additions and 0 deletions

View File

@ -44,6 +44,12 @@
#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

View 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;
}
}
////////////////////////////////////////////////////////////////////////////////