From 198530547d758404cca814b89583ad1b3e695f45 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 3 May 2013 13:53:32 +0900 Subject: [PATCH] Removed RefCounter implementation from a public header --- config.h.cmake | 8 +++ taglib/CMakeLists.txt | 2 + taglib/asf/asfattribute.cpp | 1 + taglib/asf/asfpicture.cpp | 1 + taglib/fileref.cpp | 1 + taglib/mp4/mp4coverart.cpp | 1 + taglib/mp4/mp4item.cpp | 1 + taglib/mpeg/mpegheader.cpp | 1 + taglib/taglib_config.h.cmake | 8 --- taglib/toolkit/taglib.h | 64 -------------------- taglib/toolkit/tbytevector.cpp | 1 + taglib/toolkit/tlist.tcc | 1 + taglib/toolkit/tmap.tcc | 2 + taglib/toolkit/trefcounter.cpp | 105 +++++++++++++++++++++++++++++++++ taglib/toolkit/trefcounter.h | 57 ++++++++++++++++++ taglib/toolkit/tstring.cpp | 1 + 16 files changed, 183 insertions(+), 72 deletions(-) create mode 100644 taglib/toolkit/trefcounter.cpp create mode 100644 taglib/toolkit/trefcounter.h diff --git a/config.h.cmake b/config.h.cmake index 155fea66..0a5c7015 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -16,6 +16,14 @@ /* Defined if your compiler supports codecvt */ #cmakedefine HAVE_STD_CODECVT 1 +/* Defined if your compiler supports some atomic operations */ +#cmakedefine HAVE_STD_ATOMIC 1 +#cmakedefine HAVE_BOOST_ATOMIC 1 +#cmakedefine HAVE_GCC_ATOMIC 1 +#cmakedefine HAVE_MAC_ATOMIC 1 +#cmakedefine HAVE_WIN_ATOMIC 1 +#cmakedefine HAVE_IA64_ATOMIC 1 + /* Defined if you have libz */ #cmakedefine HAVE_ZLIB 1 diff --git a/taglib/CMakeLists.txt b/taglib/CMakeLists.txt index 72712ca2..352f7e2e 100644 --- a/taglib/CMakeLists.txt +++ b/taglib/CMakeLists.txt @@ -50,6 +50,7 @@ set(tag_HDRS toolkit/tmap.h toolkit/tmap.tcc toolkit/tpropertymap.h + toolkit/trefcounter.h mpeg/mpegfile.h mpeg/mpegproperties.h mpeg/mpegheader.h @@ -289,6 +290,7 @@ set(toolkit_SRCS toolkit/tfilestream.cpp toolkit/tdebug.cpp toolkit/tpropertymap.cpp + toolkit/trefcounter.cpp toolkit/unicode.cpp ) diff --git a/taglib/asf/asfattribute.cpp b/taglib/asf/asfattribute.cpp index 937a8816..4ee2d0a1 100644 --- a/taglib/asf/asfattribute.cpp +++ b/taglib/asf/asfattribute.cpp @@ -25,6 +25,7 @@ #include #include +#include "trefcounter.h" #include "asfattribute.h" #include "asffile.h" diff --git a/taglib/asf/asfpicture.cpp b/taglib/asf/asfpicture.cpp index 3db695a4..999f9204 100644 --- a/taglib/asf/asfpicture.cpp +++ b/taglib/asf/asfpicture.cpp @@ -25,6 +25,7 @@ #include #include +#include "trefcounter.h" #include "asfattribute.h" #include "asffile.h" #include "asfpicture.h" diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 508fc0c5..157ba2ee 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -36,6 +36,7 @@ #include #include #include +#include "trefcounter.h" #include "fileref.h" #include "asffile.h" diff --git a/taglib/mp4/mp4coverart.cpp b/taglib/mp4/mp4coverart.cpp index 5ccc76d6..2746469d 100644 --- a/taglib/mp4/mp4coverart.cpp +++ b/taglib/mp4/mp4coverart.cpp @@ -25,6 +25,7 @@ #include #include +#include "trefcounter.h" #include "mp4coverart.h" using namespace TagLib; diff --git a/taglib/mp4/mp4item.cpp b/taglib/mp4/mp4item.cpp index fdb96451..671f26b4 100644 --- a/taglib/mp4/mp4item.cpp +++ b/taglib/mp4/mp4item.cpp @@ -25,6 +25,7 @@ #include #include +#include "trefcounter.h" #include "mp4item.h" using namespace TagLib; diff --git a/taglib/mpeg/mpegheader.cpp b/taglib/mpeg/mpegheader.cpp index c715dbc1..a582f758 100644 --- a/taglib/mpeg/mpegheader.cpp +++ b/taglib/mpeg/mpegheader.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "trefcounter.h" #include "mpegheader.h" diff --git a/taglib/taglib_config.h.cmake b/taglib/taglib_config.h.cmake index 633fad28..2eb67b06 100644 --- a/taglib/taglib_config.h.cmake +++ b/taglib/taglib_config.h.cmake @@ -3,14 +3,6 @@ /* Defined if your compiler supports std::wstring */ #cmakedefine TAGLIB_HAVE_STD_WSTRING 1 -/* Defined if your compiler supports some atomic operations */ -#cmakedefine TAGLIB_HAVE_STD_ATOMIC 1 -#cmakedefine TAGLIB_HAVE_BOOST_ATOMIC 1 -#cmakedefine TAGLIB_HAVE_GCC_ATOMIC 1 -#cmakedefine TAGLIB_HAVE_MAC_ATOMIC 1 -#cmakedefine TAGLIB_HAVE_WIN_ATOMIC 1 -#cmakedefine TAGLIB_HAVE_IA64_ATOMIC 1 - #define TAGLIB_WITH_ASF 1 #define TAGLIB_WITH_MP4 1 diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h index a80c02e4..80233db3 100755 --- a/taglib/toolkit/taglib.h +++ b/taglib/toolkit/taglib.h @@ -46,46 +46,6 @@ #include -// Atomic increment/decrement operations - -#if defined(TAGLIB_HAVE_STD_ATOMIC) -# include -# define TAGLIB_ATOMIC_INT std::atomic -# define TAGLIB_ATOMIC_INC(x) x.fetch_add(1) -# define TAGLIB_ATOMIC_DEC(x) (x.fetch_sub(1) - 1) -#elif defined(TAGLIB_HAVE_BOOST_ATOMIC) -# include -# define TAGLIB_ATOMIC_INT boost::atomic -# define TAGLIB_ATOMIC_INC(x) x.fetch_add(1) -# define TAGLIB_ATOMIC_DEC(x) (x.fetch_sub(1) - 1) -#elif defined(TAGLIB_HAVE_GCC_ATOMIC) -# define TAGLIB_ATOMIC_INT int -# define TAGLIB_ATOMIC_INC(x) __sync_add_and_fetch(&x, 1) -# define TAGLIB_ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1) -#elif defined(TAGLIB_HAVE_WIN_ATOMIC) -# if !defined(NOMINMAX) -# define NOMINMAX -# endif -# include -# define TAGLIB_ATOMIC_INT long -# define TAGLIB_ATOMIC_INC(x) InterlockedIncrement(&x) -# define TAGLIB_ATOMIC_DEC(x) InterlockedDecrement(&x) -#elif defined(TAGLIB_HAVE_MAC_ATOMIC) -# include -# define TAGLIB_ATOMIC_INT int32_t -# define TAGLIB_ATOMIC_INC(x) OSAtomicIncrement32Barrier(&x) -# define TAGLIB_ATOMIC_DEC(x) OSAtomicDecrement32Barrier(&x) -#elif defined(TAGLIB_HAVE_IA64_ATOMIC) -# include -# define TAGLIB_ATOMIC_INT int -# define TAGLIB_ATOMIC_INC(x) __sync_add_and_fetch(&x, 1) -# define TAGLIB_ATOMIC_DEC(x) __sync_sub_and_fetch(&x, 1) -#else -# define TAGLIB_ATOMIC_INT int -# define TAGLIB_ATOMIC_INC(x) (++x) -# define TAGLIB_ATOMIC_DEC(x) (--x) -#endif - //! A namespace for all TagLib related classes and functions /*! @@ -118,30 +78,6 @@ namespace TagLib { #else typedef std::basic_string wstring; #endif - -#ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class. - /*! - * \internal - * This is just used as a base class for shared classes in TagLib. - * - * \warning This is not part of the TagLib public API! - */ - - class RefCounter - { - public: - RefCounter() : refCount(1) {} - - void ref() { TAGLIB_ATOMIC_INC(refCount); } - bool deref() { return (TAGLIB_ATOMIC_DEC(refCount) == 0); } - int count() { return refCount; } - - private: - volatile TAGLIB_ATOMIC_INT refCount; - }; - -#endif // DO_NOT_DOCUMENT - } /*! diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index adada716..471af477 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -41,6 +41,7 @@ #include #include +#include "trefcounter.h" #include "tbytevector.h" diff --git a/taglib/toolkit/tlist.tcc b/taglib/toolkit/tlist.tcc index 37817f05..81e29153 100644 --- a/taglib/toolkit/tlist.tcc +++ b/taglib/toolkit/tlist.tcc @@ -24,6 +24,7 @@ ***************************************************************************/ #include +#include "trefcounter.h" namespace TagLib { diff --git a/taglib/toolkit/tmap.tcc b/taglib/toolkit/tmap.tcc index 0f2b9933..d6f51c07 100644 --- a/taglib/toolkit/tmap.tcc +++ b/taglib/toolkit/tmap.tcc @@ -23,6 +23,8 @@ * http://www.mozilla.org/MPL/ * ***************************************************************************/ +#include "trefcounter.h" + namespace TagLib { //////////////////////////////////////////////////////////////////////////////// diff --git a/taglib/toolkit/trefcounter.cpp b/taglib/toolkit/trefcounter.cpp new file mode 100644 index 00000000..b971c93c --- /dev/null +++ b/taglib/toolkit/trefcounter.cpp @@ -0,0 +1,105 @@ +/*************************************************************************** + copyright : (C) 2013 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#include "config.h" +#include "trefcounter.h" + +#if defined(HAVE_STD_ATOMIC) +# include +# define ATOMIC_INT std::atomic +# define ATOMIC_INC(x) x.fetch_add(1) +# define ATOMIC_DEC(x) (x.fetch_sub(1) - 1) +#elif defined(HAVE_BOOST_ATOMIC) +# include +# define ATOMIC_INT boost::atomic +# 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) +#elif defined(HAVE_WIN_ATOMIC) +# if !defined(NOMINMAX) +# define NOMINMAX +# endif +# include +# define ATOMIC_INT long +# define ATOMIC_INC(x) InterlockedIncrement(&x) +# define ATOMIC_DEC(x) InterlockedDecrement(&x) +#elif defined(HAVE_MAC_ATOMIC) +# include +# define ATOMIC_INT int32_t +# define ATOMIC_INC(x) OSAtomicIncrement32Barrier(&x) +# define ATOMIC_DEC(x) OSAtomicDecrement32Barrier(&x) +#elif defined(HAVE_IA64_ATOMIC) +# include +# 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 + +namespace TagLib +{ + class RefCounter::RefCounterPrivate + { + public: + RefCounterPrivate() : refCount(1) {} + + void ref() { ATOMIC_INC(refCount); } + bool deref() { return (ATOMIC_DEC(refCount) == 0); } + int count() const { return refCount; } + + volatile ATOMIC_INT refCount; + }; + + RefCounter::RefCounter() + : d(new RefCounterPrivate()) + { + } + + RefCounter::~RefCounter() + { + delete d; + } + + void RefCounter::ref() + { + d->ref(); + } + + bool RefCounter::deref() + { + return d->deref(); + } + + int RefCounter::count() const + { + return d->count(); + } +} \ No newline at end of file diff --git a/taglib/toolkit/trefcounter.h b/taglib/toolkit/trefcounter.h new file mode 100644 index 00000000..7559e695 --- /dev/null +++ b/taglib/toolkit/trefcounter.h @@ -0,0 +1,57 @@ +/*************************************************************************** + copyright : (C) 2013 by Tsuda Kageyu + email : tsuda.kageyu@gmail.com + ***************************************************************************/ + +/*************************************************************************** + * This library is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License version * + * 2.1 as published by the Free Software Foundation. * + * * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * + * 02110-1301 USA * + * * + * Alternatively, this file is available under the Mozilla Public * + * License Version 1.1. You may obtain a copy of the License at * + * http://www.mozilla.org/MPL/ * + ***************************************************************************/ + +#ifndef TAGLIB_REFCOUNTER_H +#define TAGLIB_REFCOUNTER_H + +#include "taglib.h" + +#ifndef DO_NOT_DOCUMENT // Tell Doxygen to skip this class. +/*! + * \internal + * This is just used as a base class for shared classes in TagLib. + * + * \warning This is not part of the TagLib public API! + */ +namespace TagLib +{ + class RefCounter + { + public: + RefCounter(); + virtual ~RefCounter(); + + void ref(); + bool deref(); + int count() const; + + private: + class RefCounterPrivate; + RefCounterPrivate *d; + }; +} + +#endif // DO_NOT_DOCUMENT +#endif \ No newline at end of file diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index acf4847f..cf745f81 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -30,6 +30,7 @@ #include "tstring.h" #include "tdebug.h" #include "tstringlist.h" +#include "trefcounter.h" #include #include