mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Removed some redundant code from tsmartptr.h.
This commit is contained in:
parent
5687c70d80
commit
1dc2471d01
@ -31,36 +31,36 @@
|
||||
|
||||
#if defined(HAVE_STD_ATOMIC)
|
||||
# include <atomic>
|
||||
# define ATOMIC_INT std::atomic<unsigned int>
|
||||
# define ATOMIC_INT std::atomic<int>
|
||||
# define ATOMIC_INC(x) x.fetch_add(1)
|
||||
# define ATOMIC_DEC(x) (x.fetch_sub(1) - 1)
|
||||
#elif defined(HAVE_BOOST_ATOMIC)
|
||||
# include <boost/atomic.hpp>
|
||||
# define ATOMIC_INT boost::atomic<unsigned int>
|
||||
# define ATOMIC_INT boost::atomic<int>
|
||||
# define ATOMIC_INC(x) x.fetch_add(1)
|
||||
# define ATOMIC_DEC(x) (x.fetch_sub(1) - 1)
|
||||
#elif defined(HAVE_GCC_ATOMIC)
|
||||
# define ATOMIC_INT int
|
||||
# define ATOMIC_INC(x) __sync_add_and_fetch(&x, 1)
|
||||
# define ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1)
|
||||
# define ATOMIC_INC(x) ::__sync_add_and_fetch(&x, 1)
|
||||
# define ATOMIC_DEC(x) ::__sync_sub_and_fetch(&x, 1)
|
||||
#elif defined(HAVE_WIN_ATOMIC)
|
||||
# if !defined(NOMINMAX)
|
||||
# define NOMINMAX
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# define ATOMIC_INT long
|
||||
# define ATOMIC_INC(x) InterlockedIncrement(&x)
|
||||
# define ATOMIC_DEC(x) InterlockedDecrement(&x)
|
||||
# define ATOMIC_INT volatile LONG
|
||||
# define ATOMIC_INC(x) ::InterlockedIncrement(&x)
|
||||
# define ATOMIC_DEC(x) ::InterlockedDecrement(&x)
|
||||
#elif defined(HAVE_MAC_ATOMIC)
|
||||
# include <libkern/OSAtomic.h>
|
||||
# define ATOMIC_INT int32_t
|
||||
# define ATOMIC_INC(x) OSAtomicIncrement32Barrier(&x)
|
||||
# define ATOMIC_DEC(x) OSAtomicDecrement32Barrier(&x)
|
||||
# define ATOMIC_INC(x) ::OSAtomicIncrement32Barrier(&x)
|
||||
# define ATOMIC_DEC(x) ::OSAtomicDecrement32Barrier(&x)
|
||||
#elif defined(HAVE_IA64_ATOMIC)
|
||||
# include <ia64intrin.h>
|
||||
# define ATOMIC_INT int
|
||||
# define ATOMIC_INC(x) __sync_add_and_fetch(&x, 1)
|
||||
# define ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1)
|
||||
# define ATOMIC_INC(x) ::__sync_add_and_fetch(&x, 1)
|
||||
# define ATOMIC_DEC(x) ::__sync_sub_and_fetch(&x, 1)
|
||||
#else
|
||||
# define ATOMIC_INT int
|
||||
# define ATOMIC_INC(x) (++x)
|
||||
@ -72,16 +72,14 @@ namespace TagLib
|
||||
class RefCounter::RefCounterPrivate
|
||||
{
|
||||
public:
|
||||
RefCounterPrivate()
|
||||
: refCount(1)
|
||||
{
|
||||
}
|
||||
RefCounterPrivate() :
|
||||
refCount(1) {}
|
||||
|
||||
volatile ATOMIC_INT refCount;
|
||||
ATOMIC_INT refCount;
|
||||
};
|
||||
|
||||
RefCounter::RefCounter()
|
||||
: d(new RefCounterPrivate())
|
||||
RefCounter::RefCounter() :
|
||||
d(new RefCounterPrivate())
|
||||
{
|
||||
}
|
||||
|
||||
@ -100,6 +98,11 @@ namespace TagLib
|
||||
return (ATOMIC_DEC(d->refCount) == 0);
|
||||
}
|
||||
|
||||
int RefCounter::count() const
|
||||
{
|
||||
return static_cast<int>(d->refCount);
|
||||
}
|
||||
|
||||
bool RefCounter::unique() const
|
||||
{
|
||||
return (d->refCount == 1);
|
||||
|
@ -44,6 +44,7 @@ namespace TagLib
|
||||
|
||||
void ref();
|
||||
bool deref();
|
||||
int count() const;
|
||||
bool unique() const;
|
||||
|
||||
private:
|
||||
|
@ -55,34 +55,7 @@
|
||||
#else // !HAVE_STD_SHARED_PTR && !HAVE_TR1_SHARED_PTR && !HAVE_BOOST_SHARED_PTR
|
||||
|
||||
# include <algorithm>
|
||||
|
||||
# if defined(HAVE_GCC_ATOMIC)
|
||||
# define ATOMIC_INT int
|
||||
# define ATOMIC_INC(x) ::__sync_add_and_fetch(&x, 1)
|
||||
# define ATOMIC_DEC(x) ::__sync_sub_and_fetch(&x, 1)
|
||||
# elif defined(HAVE_WIN_ATOMIC)
|
||||
# if !defined(NOMINMAX)
|
||||
# define NOMINMAX
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# define ATOMIC_INT volatile LONG
|
||||
# define ATOMIC_INC(x) ::InterlockedIncrement(&x)
|
||||
# define ATOMIC_DEC(x) ::InterlockedDecrement(&x)
|
||||
# elif defined(HAVE_MAC_ATOMIC)
|
||||
# include <libkern/OSAtomic.h>
|
||||
# define ATOMIC_INT int32_t
|
||||
# define ATOMIC_INC(x) ::OSAtomicIncrement32Barrier(&x)
|
||||
# define ATOMIC_DEC(x) ::OSAtomicDecrement32Barrier(&x)
|
||||
# elif defined(HAVE_IA64_ATOMIC)
|
||||
# include <ia64intrin.h>
|
||||
# define ATOMIC_INT int
|
||||
# define ATOMIC_INC(x) ::__sync_add_and_fetch(&x, 1)
|
||||
# define ATOMIC_DEC(x) ::__sync_sub_and_fetch(&x, 1)
|
||||
# else
|
||||
# define ATOMIC_INT int
|
||||
# define ATOMIC_INC(x) (++x)
|
||||
# define ATOMIC_DEC(x) (--x)
|
||||
# endif
|
||||
# include <trefcounter.h>
|
||||
|
||||
namespace TagLib
|
||||
{
|
||||
@ -91,11 +64,11 @@ namespace TagLib
|
||||
|
||||
// Counter base class. Provides a reference counter.
|
||||
|
||||
class CounterBase
|
||||
class CounterBase : public RefCounter
|
||||
{
|
||||
public:
|
||||
CounterBase() :
|
||||
refCount(1)
|
||||
RefCounter()
|
||||
{
|
||||
}
|
||||
|
||||
@ -105,12 +78,12 @@ namespace TagLib
|
||||
|
||||
void addref()
|
||||
{
|
||||
ATOMIC_INC(refCount);
|
||||
RefCounter::ref();
|
||||
}
|
||||
|
||||
void release()
|
||||
{
|
||||
if(ATOMIC_DEC(refCount) == 0) {
|
||||
if(RefCounter::deref()) {
|
||||
dispose();
|
||||
delete this;
|
||||
}
|
||||
@ -118,13 +91,10 @@ namespace TagLib
|
||||
|
||||
long use_count() const
|
||||
{
|
||||
return static_cast<long>(refCount);
|
||||
return RefCounter::count();
|
||||
}
|
||||
|
||||
virtual void dispose() = 0;
|
||||
|
||||
private:
|
||||
ATOMIC_INT refCount;
|
||||
};
|
||||
|
||||
// Counter impl class. Provides a dynamic deleter.
|
||||
|
Loading…
x
Reference in New Issue
Block a user